簡體   English   中英

將文本轉語音文件編寫為 MP3 - IBM Watson

[英]Writing a Text to Speech file as an MP3 - IBM Watson

我正在關注 IBM Watson 文本轉語音Node.JS的 Node.JS 實現的文檔

我想把output生成的文件轉成MP3格式。 該文檔建議擴充基本代碼,但我不確定該怎么做。 我的代碼正在渲染無法播放的MP3

這是文檔中的內容:

textToSpeech.synthesize(synthesizeParams)
  .then(response => {

    // The following line is necessary only for
    // wav formats; otherwise, `response.result`
    // can be directly piped to a file.

    return textToSpeech.repairWavHeaderStream(response.result);
  })
  .then(buffer => {
    fs.writeFileSync('hello_world.wav', buffer);
  })
  .catch(err => {
    console.log('error:', err);
  });

正如它所說, response.result應該直接通過管道傳輸到文件。 這是我的許多嘗試之一(導致錯誤)。

textToSpeech
  .synthesize(synthesizeParams)  
  .then(response => {
    fs.writeFileSync('Hello.mp3', response.result)
  })
  .catch(err => {
    console.log('error:', err)
  })

如何將 output 文本轉語音輸入為MP3

如果您的參數正在請求一個 mp3 文件,這將是accept參數,那么您的代碼看起來沒問題。 因此,如果 output 文件未被識別為音頻,則它很可能是包含錯誤消息的文本文件。 此錯誤消息將指示出什么問題,這很可能是未經授權的消息。

我認為您的 catch 錯誤塊沒有記錄任何內容。

暫無
暫無

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

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