[英]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.