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

admin2025-04-20  0

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

;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

.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./Azure-Samples/Cognitive-Speech-TTS

https://learn.microsoft./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./palmerabollo/bingspeech-api-client/blob/master/examples/index.js

Share Improve this question asked Sep 9, 2020 at 14:16 sigur7sigur7 9362 gold badges14 silver badges40 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8 +100

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745081155a283866.html

最新回复(0)