[英]Azure Text to Speech - Not writing to MP3 file using Node.js
[英]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.