Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Text to Speech - Not writing to MP3 file using Node.js

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

like image 930
sigur7 Avatar asked Sep 09 '20 14:09

sigur7


Video Answer


1 Answers

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).

like image 65
mcernak Avatar answered Oct 12 '22 09:10

mcernak