Skip to content

Instantly share code, notes, and snippets.

@Feawel
Last active March 1, 2018 22:02
Show Gist options
  • Save Feawel/00aeb7d375037afb89e0a16e08e7df75 to your computer and use it in GitHub Desktop.
Save Feawel/00aeb7d375037afb89e0a16e08e7df75 to your computer and use it in GitHub Desktop.
const someReallyUsefullFunction = async (text) => {
// Break in parts small enough to be handle by Polly API
const parts = divideTextEnoughToBeHandleByPolly(text)
// Concat AudioStreams in one Buffer
const audioStreams = audios.map(a => a.AudioStream)
const buffer = Buffer.concat(audioStreams, audioStreams.reduce((len, a) => len + a.length, 0))
...
}
// Here i am using SSML, but you can use plainText
const generatePollyAudio = (text, voiceId) => {
const params = {
Text: `<speak><prosody rate="100%">${text}</prosody></speak>`,
VoiceId: voiceId,
TextType: 'ssml'
}
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