将录制的音频从浏览器流式传输到服务器 [英] Stream recorded audio from browser to server

查看:48
本文介绍了将录制的音频从浏览器流式传输到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将录制的音频从浏览器实时流式传输到服务器并播放.服务器最终将成为播放这些音频流的嵌入式设备.

I would like to live stream recorded audio from the browser to the server and play it. The server will end up being a embedded device that plays these audio streams.

到目前为止,我已经成功地录制了音频并将其编码为 WAVE 文件,并使用网络音频 API 在浏览器上播放,并遵循此 教程.

So far I've successfully recorded audio and encoded it into a WAVE file and play it on the browser using the web audio API and following this tutorial.

现在我有一个 .WAV 编码的 blob 流.我尝试找到通过网络套接字连接将它们流式传输到 nodejs 后端并使用 npm 模块播放它们的方法.但我没有运气.

Now I have a stream of .WAV encoded blobs. I tried finding ways to stream these to a nodejs backend with a web socket connection and play them using a npm module. But I haven't had any luck.

有人知道我应该遵循的任何资源或模块吗?也许我应该尝试不同的方法?由于在浏览器上录制,因此需要在服务器上相对较快地播放音频.

Does anyone know of any resources or modules I should follow? Maybe I should try a different approach? The audio needs to be played relatively quickly on the server since recording on the browser.

推荐答案

我目前正在使用一些允许通过网络浏览器流式传输到 Internet 广播服务器的软件进行此操作.

I'm doing this currently with some software that allows for streaming to internet radio servers via your web browser.

我使用 WebAudio APIgetUserMedia 从声音设备获取实时 PCM 音频数据.从那里,我根据可用带宽量将此数据从 32 位浮点数转换为 16、12 或 8 位数据.这个转换后的 int 样本被写入一个带有 BinaryJS 的流设置,它在 Node.js 和客户端上都包装了流.作为 BinaryJS 的一个额外好处,您可以根据需要打开任意数量的流,因此我在同一 WebSocket 连接上使用第二个流来控制数据.

I use the WebAudio API along with getUserMedia to get live PCM audio data from the sound device. From there, I convert this data from 32-bit float to 16, 12, or 8 bit data depending on the amount of bandwidth available. This converted int samples are written to a stream setup with BinaryJS which wraps streams on both the Node.js and the client. As a bonus with BinaryJS, you can have as many streams open as you want, so I use a second stream over the same WebSocket connection for control data.

http://demo.audiopump.co:3000/

这篇关于将录制的音频从浏览器流式传输到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆