├── sample 1 ├── .gitignore ├── auth.js ├── credentials.json ├── voices.js ├── package.json ├── TEXT.txt └── speakTest.js └── sample 2 ├── .gitignore ├── package.json ├── speaker.js └── aws-polly.js /sample 1/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json -------------------------------------------------------------------------------- /sample 2/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json -------------------------------------------------------------------------------- /sample 1/auth.js: -------------------------------------------------------------------------------- 1 | const AWS = require("aws-sdk"); 2 | AWS.config.loadFromPath('./credentials.json') 3 | -------------------------------------------------------------------------------- /sample 1/credentials.json: -------------------------------------------------------------------------------- 1 | { 2 | "accessKeyId": "AKIAJHQEVG7IH5IS4EFQ", 3 | "secretAccessKey": "D9bwYm+ovX89C8IQSAtEuCKd46oPlGnYg47WwsWs", 4 | "region": "us-east-2" 5 | } -------------------------------------------------------------------------------- /sample 1/voices.js: -------------------------------------------------------------------------------- 1 | const AWS = require("aws-sdk"); 2 | require('./auth.js') 3 | 4 | 5 | let polly = new AWS.Polly(); 6 | // let param = { "LanguageCode": 'en-GB' } 7 | let param = { "LanguageCode": 'en-US' } 8 | polly.describeVoices(param, (err, data) => { 9 | if (err) console.log("EROrr", err); 10 | else console.log("DAta", data) 11 | }) -------------------------------------------------------------------------------- /sample 1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learn", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Majid Ashraf", 10 | "license": "ISC", 11 | "dependencies": { 12 | "aws-sdk": "^2.188.0", 13 | "fs": "0.0.1-security" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample 2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learnpolly", 3 | "version": "1.0.0", 4 | "description": "learn aws polly ", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Majid Ashraf", 10 | "license": "ISC", 11 | "dependencies": { 12 | "aws-sdk": "^2.188.0", 13 | "fs": "0.0.1-security", 14 | "speaker": "^0.4.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample 1/TEXT.txt: -------------------------------------------------------------------------------- 1 | 2 | Hello, this is Majid Ashraf. and, 3 | I am Hasan Idress . 4 | 5 | I am sorry, to inform you. that the items you requested 6 | 7 | I am sorry, to inform you. that the items you requested, are back-ordered We apologize for the inconvenience. 8 | 9 | 10 | 11 | 12 | This is extra loud volume. 13 | This is slow speech. 14 | 15 | 16 | This is an important announcement, you are using STRONG 17 | This is an important announcement , you are using none 18 | Hello this is Michael Sealy and I am Jason Stevenson 19 | -------------------------------------------------------------------------------- /sample 2/speaker.js: -------------------------------------------------------------------------------- 1 | // Load the SDK 2 | const AWS = require('aws-sdk') 3 | const Stream = require('stream') 4 | const Speaker = require('speaker') 5 | 6 | // Create an Polly client 7 | const Polly = new AWS.Polly({ 8 | signatureVersion: 'v4', 9 | region: 'us-east-1' 10 | }) 11 | 12 | // Create the Speaker instance 13 | const Player = new Speaker({ 14 | channels: 1, 15 | bitDepth: 16, 16 | sampleRate: 16000 17 | }) 18 | 19 | let params = { 20 | 'Text': 'Hi, my name is @anaptfox.', 21 | 'OutputFormat': 'pcm', 22 | 'VoiceId': 'Kimberly' 23 | } 24 | 25 | Polly.synthesizeSpeech(params, (err, data) => { 26 | if (err) { 27 | console.log(err.code) 28 | } else if (data) { 29 | if (data.AudioStream instanceof Buffer) { 30 | // Initiate the source 31 | var bufferStream = new Stream.PassThrough() 32 | // convert AudioStream into a readable stream 33 | bufferStream.end(data.AudioStream) 34 | // Pipe into Player 35 | bufferStream.pipe(Player) 36 | } 37 | } 38 | }) -------------------------------------------------------------------------------- /sample 2/aws-polly.js: -------------------------------------------------------------------------------- 1 | const AWS = require("aws-sdk"); 2 | const File_System = require("fs"); 3 | 4 | // Create an Polly client 5 | const Polly = new AWS.Polly({ 6 | region: 'us-east-1' 7 | }) 8 | 9 | let params = { 10 | "OutputFormat": "mp3", 11 | "Text": ` 12 | Hello, this is Majid Ashraf. and, 13 | 14 | I am sorry, to inform you. that the items you requested, are back-ordered We apologize for the inconvenience. 15 | 16 | `, 17 | "TextType": "ssml", 18 | "VoiceId": "Joanna" 19 | } 20 | 21 | 22 | Polly.synthesizeSpeech(params, (err, data) => { 23 | if (err) { 24 | console.log(err.code) 25 | } else if (data) { 26 | if (data.AudioStream instanceof Buffer) { 27 | File_System.writeFile("./speech.mp3", data.AudioStream, function (err) { 28 | if (err) { 29 | return console.log(err) 30 | } 31 | console.log("The file was saved!") 32 | }) 33 | } 34 | } 35 | }) -------------------------------------------------------------------------------- /sample 1/speakTest.js: -------------------------------------------------------------------------------- 1 | const AWS = require("aws-sdk"); 2 | require('./auth.js') 3 | const fs = require('fs'); 4 | 5 | let polly = new AWS.Polly(); 6 | 7 | var params = { 8 | // "LexiconNames": ["string"], 9 | "OutputFormat": "mp3", 10 | // "SpeechMarkTypes": ["string"], 11 | "Text": ` 12 | Hello, this is Majid Ashraf. and, 13 | I am Hasan Idress . 14 | 15 | I am sorry, to inform you. that the items you requested 16 | 17 | I am sorry, to inform you. that the items you requested, are back-ordered We apologize for the inconvenience. 18 | 19 | `, 20 | "TextType": "ssml", 21 | "VoiceId": "Joanna" 22 | } 23 | 24 | let synthCB = function (err, data) { 25 | if (err) { 26 | console.log(err) 27 | } else { 28 | console.log("DATA------- ", data.AudioStream) 29 | fs.writeFile("speech.mp3", data.AudioStream, (err, data) => { 30 | if (err) { 31 | console.log("Error saving File", err) 32 | } 33 | console.log("FILE SAVE!") 34 | }) 35 | } 36 | } 37 | 38 | polly.synthesizeSpeech(params, synthCB) --------------------------------------------------------------------------------