Streaming live audio data via MQTT

Hi @nhiennguyenhuy,

I don't think your problem has anything to do with mqtt. The dashboard's audio-out node simply can only play a single audio buffer, for example an mp3 file. You push an infinite stream of audio fragments to it, which it is not what this node is designed for...

I have tried in the past to implement this feature, but it was just to hard in my limited spare time.

  • You can easily fool your eyes by sending separate images to it: your eyes will believe they see fluent video.
  • It is very hard to fool your ears: they will hear every abnormal transition from one segment to the next.

At one moment the audio chunks will arrive too soon, so some of them will be skipped by the audio node. At another moment the audio chunks will arrive not fast enough, which means there will be a gap of silence. In both cases you get steep edges, as transition between succesive audio fragments. And that is what your ears hear.

The audio-node immediately plays a fragment, as soon as you pass it one. I tried to add a buffer to it in the past (i.e. an array where N input fragments are being stored), and then it was already much better. Because if the buffer is large enough, the node will play all the segments nicely after each other. So no steep edges between the fragments.
However the buffer size needs to be small, otherwise the delay will become too noticable. And then you get again more distortions.

Perhaps meanwhile new javascript libraries have been implemented that can solve this problem. Don't know...

When you search on this forum, you will quickly find that others have tried this before you already (e.g. here) ...

Bart

2 Likes