I am trying to create an MP3 file using Azure Text to Speech. The node file runs, but nothing gets created or outputted. The Node.js docs files and example aren't too good
https://github.com/Azure-Samples/Cognitive-Speech-TTS
https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=require%2Cwindowsinstall&pivots=programming-language-javascript
const sdk = require("microsoft-cognitiveservices-speech-sdk");
var subscriptionKey = "809-myazureapikey";
var serviceRegion = "westeurope"; // e.g., "westus"
function synthesizeSpeech() {
const speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);
const audioConfig = AudioConfig.fromAudioFileOutput("speech.mp3");
const synthesizer = new SpeechSynthesizer(speechConfig, audioConfig);F
synthesizer.speakTextAsync(
"A simple test to write to a file.",
result => {
if (result) {
console.log(JSON.stringify(result));
}
synthesizer.close();
},
error => {
console.log(error);
synthesizer.close();
});
};
Do I need to declare and use the fs service to write the file?
This is a Bing Speech example, which is different from the Azure service and example
https://github.com/palmerabollo/bingspeech-api-client/blob/master/examples/index.js
Here is a minimal working project: azure-text-to-speech
It's almost identical to the sample provided in Microsoft documentation.
I've just modified some imports to make it run and also added output format settings (since you've mentioned that you want MP3 and the default is WAV).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With