gpt4 book ai didi

node.js - 将 LINEAR16 音频编码为 Twilio 媒体音频/x-mulaw | Node JS

转载 作者:行者123 更新时间:2023-12-04 03:55:21 24 4
gpt4 key购买 nike

我一直在尝试将 mulaw 媒体流传输回 Twilio。要求是有效载荷必须是音频/x-mulaw 编码,采样率为 8000 和 base64 编码

我的输入来自@google-cloud/text-to-speech in LINEAR16 Google Docs

我试过了 Wavefile

这就是我对来自@google-cloud/text-to-speech 的响应进行编码的方式

 const wav = new wavefile.WaveFile(speechResponse.audioContent)
wav.toBitDepth('8')
wav.toSampleRate(8000)
wav.toMuLaw()

然后我通过 WebSocket 将结果发送回 Twilio

twilioWebsocket.send(JSON.stringify({
event: 'media',
media: {
payload: wav.toBase64(),
},
streamSid: meta.streamSid,
}))

Problem is we only hear random noise on other ends of Twilio call, seems like encoding is not proper

Secondly I have checked the @google-cloud/text-to-speech output audio by saving it in a file and it was proper and clear

Can anyone please help me with the encoding

最佳答案

我也遇到了同样的问题。错误在 wav.toBase64() 中,因为它包含 wav header 。 Twilio 媒体流需要原始音频数据,您可以使用 wav.data.samples 获取这些数据,因此您的代码将是:

 const wav = new wavefile.WaveFile(speechResponse.audioContent)
wav.toBitDepth('8')
wav.toSampleRate(8000)
wav.toMuLaw()

const payload = Buffer.from(wav.data.samples).toString('base64');

关于node.js - 将 LINEAR16 音频编码为 Twilio 媒体音频/x-mulaw | Node JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64003753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com