Created
March 8, 2018 23:11
-
-
Save jonathanmv/c3b1bfbcca3e8be4ce8e1144502739a8 to your computer and use it in GitHub Desktop.
Save the speech from a text into a mp3 file locally
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 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