javascript - Azure 文本转语音 - 不使用 Node.js 写入 MP3 文件

标签 javascript node.js azure azure-functions

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

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();
    });
  };

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

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

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

最佳答案

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

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

关于javascript - Azure 文本转语音 - 不使用 Node.js 写入 MP3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63813568/

相关文章:

node.js - (双代理)node js 使用 node-http-proxy 在企业代理后面创建代理服务器

azure - Azure 时序见解 Gen2 的存储成本较高

c++ - 从 SQL Server 的 Azure 帐户获取 IP

javascript - jQuery 插件 - 高亮文本

javascript - 使用代理超出最大堆栈调用大小

javascript - 再次单击 JavaScript 中的按钮时数据会重复

javascript - 如何用fs读取并保存base64图像

node.js - Bcrypt 非法参数 : number

javascript - 多选下拉控件 - Primeng - Angular 6 - 在页面加载时默认选择所有选项并将它们显示为选定标签

Azure Web 应用程序 kudu 部署 C# 6