# Streaming live audio data via MQTT

**URL:** <https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602>\
**Category:** General\
**Tags:** mqtt\
**Created:** [18 August 2022 11:29 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602 "2022-08-18T11:29:08Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [20 August 2022 11:18 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/21 "2022-08-20T11:18:25Z")

</div>

> [@BartButenaers](#):
>
> But if nobody diggs into this problem, we keep on getting the same issue until ethernity

We need a player that can handle infinite streams of audio chunks, and can seemless play them sequentially. But it should support smoothing of steep edges when the next arrives not in time.

Because it takes too much time to develop something yourself. Some things I tried in the past:

1. Mostly they refer to solutions where you _ **schedule** _ the chunks via the web audio api. But I got still way too much distortions
2. Tried a _ **datasource** _ that created continiously zero values, and then overwrite those zeros by real audio values when available. This was much better compared to solution 1, but still bad on Android.
3. I haven't tried smoothing the edges due to a lack of free time.

But not sure if a library like e.g. [pcm-player](https://github.com/pkjy/pcm-player) can solve our issue, because - when looking at the [code](https://github.com/pkjy/pcm-player/blob/master/src/pcm-player.js#L145) - it only applies _ **fading** _ when being flushed (by default every second) but not in between (and steep edges can happen everywhere). But I haven't analyzed it in detail...

---

<div class="post-metadata">

**Author:** ![nhiennguyenhuy](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nhiennguyenhuy](https://discourse.nodered.org/u/nhiennguyenhuy)\
**Post date:** [20 August 2022 11:22 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/22 "2022-08-20T11:22:58Z")

</div>

> [@BartButenaers](#):
>
> You could do also _ **experiment 5** _:

I tested for this case.  
I found an importance thing which you said before: If I change the buffer size (frames\_per\_buffer) to the "proper value", the sound is _ **smoothler** _ than other value. And I got the same quality as Experiment 1.

Maybe the issue here is the "proper" buffer size?  
But I've changed that value (1024 bytes, 2048 bytes, 4096 bytes, ...) for Experiment 2, but I couldn't get clear sound...

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [20 August 2022 12:11 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/23 "2022-08-20T12:11:08Z")

</div>

I assume frames\_per\_buffer is a setting of the python player? And what do you mean by "proper value"?  
A larger player buffer means that mostly all segments will be available at the time the player will start playing them. So less steep edges...

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [20 August 2022 12:19 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/24 "2022-08-20T12:19:30Z")

</div>

Link to the python audio player/capture missing?? I don't see that

---

<div class="post-metadata">

**Author:** ![nhiennguyenhuy](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nhiennguyenhuy](https://discourse.nodered.org/u/nhiennguyenhuy)\
**Post date:** [20 August 2022 12:54 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/25 "2022-08-20T12:54:44Z")

</div>

Do you mean google drive link? I just checked it, and it is still OK.

---

<div class="post-metadata">

**Author:** ![nhiennguyenhuy](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nhiennguyenhuy](https://discourse.nodered.org/u/nhiennguyenhuy)\
**Post date:** [20 August 2022 12:57 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/26 "2022-08-20T12:57:24Z")

</div>

> [@BartButenaers](#):
>
> I assume frames\_per\_buffer is a setting of the python player? And what do you mean by "proper value"?

I tested for some value of frames\_per\_buffer ( of the python player) and there is a value which reproduces best quality of audio.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [20 August 2022 13:03 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/27 "2022-08-20T13:03:00Z")

</div>

Yes, the python player you refering to, I guess is a script

---

<div class="post-metadata">

**Author:** ![nhiennguyenhuy](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nhiennguyenhuy](https://discourse.nodered.org/u/nhiennguyenhuy)\
**Post date:** [20 August 2022 13:08 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/28 "2022-08-20T13:08:50Z")

</div>

I just shared the sample audio only.

Python program is based on this document  
[https://people.csail.mit.edu/hubert/pyaudio/docs/](https://people.csail.mit.edu/hubert/pyaudio/docs/)

And this is my python [code](https://docs.google.com/document/d/12Cdyvr_ebZEnRPs6qRZg2YqF0xFDKOcPKe3u16WxlEA/edit?usp=sharing)  
.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [20 August 2022 15:26 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/29 "2022-08-20T15:26:45Z")

</div>

> [@BartButenaers](#):
>
> But not sure if a library like e.g. [pcm-player](https://github.com/pkjy/pcm-player) can solve our issue,

The online [demo](https://pkjy.github.io/pcm-player/) of the pcm-player works very good on my Android phone. So I will try to integrate it in Node-RED...

---

<div class="post-metadata">

**Author:** ![nhiennguyenhuy](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nhiennguyenhuy](https://discourse.nodered.org/u/nhiennguyenhuy)\
**Post date:** [21 August 2022 03:21 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/30 "2022-08-21T03:21:16Z")

</div>

Thank you so much!

I'm trying to rewrite python code, especially about the number\_of\_frame\_per\_buffer and processing time on Raspi Zero.  
Maybe it takes too much time for capturing or/and playing audio. And it can't not meet the speed of receiving data. Finally we lose the audio data....

I will update the information if I have better result.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 August 2022 07:35 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/31 "2022-08-21T07:35:38Z")

</div>

@nhiennguyenhuy,  
Don't know if you have seen [this](https://discourse.nodered.org/t/developing-a-custom-ui-node-for-flexdash/66704/14) discussion. @tve has been so kind to create a very basic pcm player node in Flexdash for us yesterday evening.

Flexdash is a new dashboard for Node-RED with lot of potential. It is currently in alfa status, but it is already quite stable. You can run it in parallel to your old dashboard. So you can always give it a try if you have time. Constructive feedback is very welcome!!!

Did not have time yet to digg into the code of that player node, so perhaps it doesn't completely fits your use case....

---

<div class="post-metadata">

**Author:** ![nhiennguyenhuy](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nhiennguyenhuy](https://discourse.nodered.org/u/nhiennguyenhuy)\
**Post date:** [21 August 2022 09:56 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/32 "2022-08-21T09:56:21Z")

</div>

I sincerely appreciate your kindness and support, and also for @tve's support too.  
I will be sure to try it soon. I'm very new in Node-red, also in audio processing, so it takes me much time to understand what you said ...

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 August 2022 10:15 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/33 "2022-08-21T10:15:25Z")

</div>

Will try to explain it a bit in more detail:

You have been testing the audio-out node, which allows you to play an audio file in your dashboard (which you access via http(s)://your\_hostname:1880/ui). But we know that this node is designed to play 1 file, and can cause a lot of noise if you start pushing a live stream of audio chunks to it.

So would be nice if we could allow the dashboard to play such live streams.

However the current official dashboard that you use, is developed in AngularJs which is not supported anymore (although of course the Node-RED dashboard is still nicely supported). Therefore Thorsten has developed a new dashboard (named Flexdash) based on VueJs. Moreover Flexdash offers more features compared to the current dashboard.

Since I have no time to support 2 dashboards, I will now start focussing on Flexdash. So Thorsten has added (experimental) support for audio chunks in Flexdash.

So if you have time to install Flexdash, you could test that new feature...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 October 2022 10:16 UTC](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602/34 "2022-10-20T10:16:13Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/streaming-live-audio-data-via-mqtt/66602.md?page=1)
