简体   繁体   English

MQTT 可以将音频直接流式传输到 Web 客户端吗?

[英]Can MQTT stream audio directly to a web client?

I was able to set up an Arduino to stream audio from a microphone into a linux server that's hosting an MQTT server.我能够设置一个 Arduino 将音频从麦克风流式传输到托管 MQTT 服务器的 linux 服务器。 I then have a golang script that subscribes to the MQTT server, saves payload to disk as a binary file, and converts the binary file to a .WAV file with FFMPEG.然后我有一个订阅 MQTT 服务器的 golang 脚本,将有效负载作为二进制文件保存到磁盘,并使用 FFMPEG 将二进制文件转换为 .WAV 文件。

Is it possible to have a web browser use only client side code to subscribe to the same MQTT server, receive the audio payload from the Arduino, and stream the audio in near-real-time to the human listener's computer speakers?是否可以让 Web 浏览器仅使用客户端代码订阅同一个 MQTT 服务器,从 Arduino 接收音频有效负载,并将音频近实时地流式传输到人类听众的计算机扬声器? I see a Paho Javascript Client library that can help me connect to MQTT, but it seems to receive payloads as string, which isn't evident to me on how I'd stream audio content with.我看到了一个Paho Javascript 客户端库,它可以帮助我连接到 MQTT,但它似乎以字符串的形式接收有效负载,这对我如何流式传输音频内容并不明显。 Hence, why I'm asking if it's even practical/feasible?因此,为什么我要问它是否实用/可行?

Or will I need to build another server-side script to stream MQTT data as audio data for a web client?或者我是否需要构建另一个服务器端脚本来将 MQTT 数据作为 Web 客户端的音频数据流式传输?

Look closer at the pahodoc , there is a fiction to get the message payload as binary data using the message.payloadBytes field.仔细查看 pahodoc ,有一种使用message.payloadBytes字段将消息有效负载作为二进制数据获取的小说。

payloadBytes |有效载荷字节 | ArrayBuffer |数组缓冲区 | read only The payload as an ArrayBuffer只读 有效负载作为 ArrayBuffer

An example is described here:此处描述了一个示例:

https://www.hardill.me.uk/wordpress/2014/08/29/unpacking-binary-data-from-mqtt-in-javascript/ https://www.hardill.me.uk/wordpress/2014/08/29/unpacking-binary-data-from-mqtt-in-javascript/

But basically you end up withan ArrayBuffer holding the binary data that you can then coonvert to a Typed Array and read back values at what ever offset you need.但基本上,您最终会得到一个 ArrayBuffer 保存二进制数据,然后您可以将其转换为类型化数组并以您需要的任何偏移量读回值。

To ensure it works in all environments, ensure that you use MQTT over WebSocket to connect to the server.为确保它适用于所有环境,请确保您使用 MQTT over WebSocket 连接到服务器。

Here is a discussion of this: Can a web browser use MQTT?以下是对此的讨论: Web 浏览器可以使用 MQTT 吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Paho客户端Web套接字找不到mqtt - Paho Client Web Socket Can't Find mqtt 我可以使用nodejs将麦克风音频从客户端传输到客户端吗? - Can I stream microphone audio from client to client using nodejs? 将流直接返回到Web浏览器 - Returning a stream directly to the web browser Stream 音频直接从浏览器到服务器 - Stream audio directly from browser to server 如何捕获在我的应用程序中播放的音频流,然后将其用作 Web Audio API 的有效输入以进行可视化? - How can I capture an audio stream playing in my application, and then it use it as a valid input for Web Audio API for visualization? 如何从手动创建的音频流中流式传输音频? (客户端) - How to stream audio from a manually created audio stream? (client side) 您可以重用AWS MQTT Javascript客户端吗 - Can you reuse AWS MQTT Javascript Client 如何在Web应用程序客户端录制音频并将其保存在Web服务器中? - How can I record audio in a web app client side and save it in a web server? Web Audio API : 高效播放 PCM 流 - Web Audio API : efficiently play a PCM stream Javascript Web音频rms无法读取流 - Javascript web audio rms not reading stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM