Skip to content

Instantly share code, notes, and snippets.

@jonathanmv
Created March 8, 2018 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanmv/c3b1bfbcca3e8be4ce8e1144502739a8 to your computer and use it in GitHub Desktop.
Save jonathanmv/c3b1bfbcca3e8be4ce8e1144502739a8 to your computer and use it in GitHub Desktop.
Save the speech from a text into a mp3 file locally
const saveSpeechLocally = text => getSpeech(text).then(saveSpeech)
const getSpeech = text => {
const Text = cleanText(text)
const OutputFormat = 'mp3'
const VoiceId = 'Kimberly'
const params = { Text, OutputFormat, VoiceId }
return polly.synthesizeSpeechAsync(params)
}
const saveSpeech = ({ AudioStream }) => {
const fileName = './audios/' + new Date().getTime() + '.mp3'
return fs.writeFileAsync(fileName, AudioStream)
.then(() => fileName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment