Azure Text to Speech - 不使用 Node.js 写入 MP3 文件

sig*_*ur7 5 javascript azure node.js azure-functions

我正在尝试使用 Azure Text to Speech 创建 MP3 文件。节点文件运行,但没有创建或输出任何内容。Node.js 文档文件和示例不太好

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();
    });
  };
Run Code Online (Sandbox Code Playgroud)

是否需要声明并使用 fs 服务来写入文件?

这是一个 Bing Speech 示例,与 Azure 服务和示例不同

https://github.com/palmerabollo/bingspeech-api-client/blob/master/examples/index.js

mce*_*nak 5

这是一个最小的工作项目:azure-text-to-speech

它与Microsoft 文档中提供的示例几乎相同。
我刚刚修改了一些导入以使其运行并添加了输出格式设置(因为您已经提到您想要 MP3 并且默认为 WAV)。