简体   繁体   English

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

[英]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.我正在尝试使用 Azure Text to Speech 创建 MP3 文件。 The node file runs, but nothing gets created or outputted.节点文件运行,但没有创建或输出任何内容。 The Node.js docs files and example aren't too good Node.js 文档文件和示例不太好

https://github.com/Azure-Samples/Cognitive-Speech-TTS 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 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?是否需要声明并使用 fs 服务来写入文件?

This is a Bing Speech example, which is different from the Azure service and example这是一个 Bing Speech 示例,与 Azure 服务和示例不同

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

Here is a minimal working project: azure-text-to-speech这是一个最小的工作项目: azure-text-to-speech

It's almost identical to the sample provided in Microsoft documentation .它与Microsoft 文档中提供的示例几乎相同。
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).我刚刚修改了一些导入以使其运行并添加了输出格式设置(因为您已经提到您想要 MP3 并且默认为 WAV)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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