简体   繁体   中英

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://docs.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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM