Created
February 11, 2017 16:53
-
-
Save Feawel/0d44b84aa90551b170a9a43cad814bd7 to your computer and use it in GitHub Desktop.
Nodejs script using polly API to return an audio stream (through a promise)
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
// Generate audio from Polly and check if output is a Buffer | |
const generatePollyAudio = (text, voiceId) => { | |
const params = { | |
Text: text, | |
OutputFormat: 'mp3', | |
VoiceId: voiceId // see Polly API for the list http://docs.aws.amazon.com/fr_fr/polly/latest/dg/API_Voice.html#API_Voice_Contents | |
} | |
return polly.synthesizeSpeech(params).promise().then( audio => { | |
if (audio.AudioStream instanceof Buffer) return audio | |
else throw 'AudioStream is not a Buffer.' | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment