Skip to content

Instantly share code, notes, and snippets.

@Feawel
Created February 11, 2017 16:53
Show Gist options
  • Save Feawel/0d44b84aa90551b170a9a43cad814bd7 to your computer and use it in GitHub Desktop.
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)
// 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