Last active
March 1, 2018 22:02
-
-
Save Feawel/00aeb7d375037afb89e0a16e08e7df75 to your computer and use it in GitHub Desktop.
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
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