且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过 websocket 将音频发送到 Nexmo Voice

更新时间:2022-01-22 07:34:02

看起来你正在将整个音频剪辑写入 websocket,Nexmo 接口要求音频在 20ms 帧内每条消息,这意味着您需要将剪辑分成 320 或 640 字节(取决于您使用的是 8Khz 还是 16Khz)块并将每个块写入套接字.如果您尝试将太大的文件写入套接字,它会像您看到的那样关闭.

It looks like you're writing the whole audio clip to the websocket, the Nexmo interface requires the audio to be in 20ms frames one per message, this means that you need to break your clip up into 320 or 640 byte (depending on if you're using 8Khz or 16Khz) chunks and write each one to the socket. If you try and write too larger file to the socket it will close as you are seeing.

参见 https://developer.nexmo.com/voice/voice-api/guides/websockets#writing-audio-to-the-websocket 了解详情.