Created
December 13, 2016 13:54
-
-
Save anaptfox/6ea8fcf6ae9f3a9617ebc9b3eccbd894 to your computer and use it in GitHub Desktop.
Node.js Amazon Polly to file example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the SDK | |
const AWS = require('aws-sdk') | |
const Fs = require('fs') | |
// Create an Polly client | |
const Polly = new AWS.Polly({ | |
signatureVersion: 'v4', | |
region: 'us-east-1' | |
}) | |
let params = { | |
'Text': 'Hi, my name is @anaptfox.', | |
'OutputFormat': 'mp3', | |
'VoiceId': 'Kimberly' | |
} | |
Polly.synthesizeSpeech(params, (err, data) => { | |
if (err) { | |
console.log(err.code) | |
} else if (data) { | |
if (data.AudioStream instanceof Buffer) { | |
Fs.writeFile("./speech.mp3", data.AudioStream, function(err) { | |
if (err) { | |
return console.log(err) | |
} | |
console.log("The file was saved!") | |
}) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this:
var output = child_process.execSync('lame --decode ' + argv.mp3 + ' ' + '-b 8000' + ' ' + argv.wav + '.wav');
To convert in wav 8000hz