簡體   English   中英

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

[英]Azure Text to Speech - Not writing to MP3 file using Node.js

我正在嘗試使用 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();
    });
  };

是否需要聲明並使用 fs 服務來寫入文件?

這是一個 Bing Speech 示例,與 Azure 服務和示例不同

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

這是一個最小的工作項目: azure-text-to-speech

它與Microsoft 文檔中提供的示例幾乎相同。
我剛剛修改了一些導入以使其運行並添加了輸出格式設置(因為您已經提到您想要 MP3 並且默認為 WAV)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM