# Play Sound from USB Microphone

**URL:** <https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551>\
**Category:** Dashboard\
**Created:** [25 August 2018 09:25 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551 "2018-08-25T09:25:09Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 August 2018 16:28 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/21 "2018-08-25T16:28:49Z")

</div>

sorry - I don't have a USB mic so can't help at that end of the pipe ☹

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 August 2018 16:41 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/22 "2018-08-25T16:41:20Z")

</div>

> [@GChapo](#):
>
> Still confused by how the node picks up which USB the microphone is attached to?

I expect that is the same way that the system knows to use a wifi adaptor for wifi whichever port you plug it in. It says, oh here is a wifi adaptor, I will use it for wifi. I assume that in the case of a mic it does a similar thing.  
If you run, in a terminal  
`tail -f /var/log/syslog`  
and plug the mic in you should see it recognising it as a mic.

I am still not sure what is working and what isn't, are you able to record from the mic to a file? I suggest get that working, then get playing the file working, then you should be able to take the file out and pass it straight through I believe.

Which version of node-red and node.js are you using? Restart node-red and then, in a terminal, run node-red-log and copy/paste here what you see from where node red starts.

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [25 August 2018 16:55 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/23 "2018-08-25T16:55:44Z")

</div>

Thanks Colin,

I'll park it for a couple of days and run all the mic tests as you suggest. It seems to be that if it's secure on setup then the node red bit should be fairly straight forward. If I have problems I'll come back to you.

In the meantime thank you all very much for your assistance.

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [28 August 2018 17:54 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/24 "2018-08-28T17:54:46Z")

</div>

I'm still really struggling with this. I have played the demo.wav file successfully several times but for the life of me I cannot serve it up to the dashboard ui on my phone. I have the following configuration;

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/036eb7cbb397dcbcd86176152c77481a2564febd.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [28 August 2018 18:09 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/25 "2018-08-28T18:09:52Z")

</div>

I've not used the microPi node so just guessing by the words you have on the debug... I would guess you need to take the buffer file part of the second output and feed that into the audio out... so you would need to pass through a change node to move the buffer part only to the payload (ie removing the metadata parts)

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [28 August 2018 21:45 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/26 "2018-08-28T21:45:36Z")

</div>

Hi dceejay,

Thank-you for your assistance.

On your recommendation I am now able to receive sound through the dashboard UI, however as I have a record and stop, it doesn't play the recorded piece until I press stop. I am unsure how to buffer once I hit record and stop sound when I hit stop?

Thanks again

Glenn

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [30 August 2018 07:43 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/27 "2018-08-30T07:43:12Z")

</div>

Is it possible to play live audio stream in node red? I now can record and playback but don't seem to be able to play live?

---

<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:** [31 August 2018 10:06 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/28 "2018-08-31T10:06:05Z")

</div>

Hi Glenn,

I have also been asking a rather similar [question](https://groups.google.com/forum/#!topic/node-red/U511c4MZogs) in the past, on the old forum. My never got an answer... In my case the audio was a stream arriving from an IP camera, but I assume my audio fragements should travel through the Node-RED flow the same way as your audio?

So if somebody can point us in the right direction, that would be very appreciated !!  
Bart

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [31 August 2018 12:11 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/29 "2018-08-31T12:11:14Z")

</div>

Node-RED by default works on chunk / packets of data. There are a few nodes that handle streams but most don't. No reason that more couldn't be made to work with streams - including the audio out one - but that's just the way they are right now. I look forwards to your pull request 🙂

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [31 August 2018 13:27 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/30 "2018-08-31T13:27:32Z")

</div>

Thanks Bart & Dceejay. Yes I did follow your previous dead end search Bart, so thank you for confirming my suspicions.

I have put a feature request in and look forward to its deployment.

Glenn

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 August 2018 14:19 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/31 "2018-08-31T14:19:33Z")

</div>

For the moment a way to achieve it would be to work out how to do it from the command line then run that from an exec node.

---

<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:** [31 August 2018 17:47 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/32 "2018-08-31T17:47:25Z")

</div>

Hi Colin,

that would be indeed enough if somebody could let us know how do it with third party stuff. Then at least I would know in which direction I have to search to integrate it better in Node-RED afterwards.

But I'm a complete noob regarding to Audio 😩 I assume we should start with some kind of segmentation/fragmentation ... (e.g. with **ffmpeg**???). So all feedback from anybody is welcome. Don't even know at the moment for which keywords I have to google.

Bart

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 August 2018 20:10 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/33 "2018-08-31T20:10:52Z")

</div>

I don't know either but I would start by googling for  
raspberry pi stream audio from microphone  
That seems to give a good number of hits.

---

<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:** [2 September 2018 11:27 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/34 "2018-09-02T11:27:05Z")

</div>

Hi Glenn,

I have 'very' few time at the moment, but would like to experiment with the audio in Node-RED in a couple of weeks. Would be nice if you could give some extra information about what you have currently achieved (and please export you flow and share it here).

- I also don't have a microphone at my Raspberry. Which one are you using?

- Had a quick view at the node-red-contrib-micropi and I see that the support multiple nodes (?):  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/199d48fe2e396909ff666140105046b854701e5d.png)

- Seems both nodes return a raw audio stream. I assume that is a stream of infinite length?

- You say "_it doesn't play the recorded piece until I press stop_". Do I interpret this correctly: the microphone node doesn't send any data on the wire (to the audio out node), until you stop the stream. Then it sends a wave file containing the whole recorded audio. Is that correct? Or does it sends continiously data to the audio out node, which buffers the data and starts playing only after you stop the stream? Summarized: which of both nodes buffers the data?

- Can you give some more info about the data on the wire ?

- ...

Thank!  
Bart

---

<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:** [2 September 2018 19:40 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/35 "2018-09-02T19:40:14Z")

</div>

> [@dceejay](#):
>
> There are a few nodes that handle streams but most don't. No reason that more couldn't be made to work with streams - including the audio out one -

Evening Dave,

Had just a very quick look at both nodes used by Glenn. By looking at the code, I would expect that streaming is already implemented everywhere? Would be nice if you could indicate in what area you would expect there is a problem. I have no microphone available, so cannot see what happens ...

1. The _ **node-red-contrib-micropi** _ node [sends](https://github.com/MarkusWals/node-red-contrib-micropi/blob/master/micropi/nodes/microphone/microphone.js#L79) data chunks on it's output:

2. The **_server-side Audio-Out_** node [receives](https://github.com/node-red/node-red-dashboard/blob/master/nodes/ui_audio.js) those buffers, and sends them to the client-side:

3. The **_client-side Audio-Out_** node [receives](https://github.com/node-red/node-red-dashboard/blob/10e52e4c73b960de7535eccfd926ac2a23c2b78e/src/main.js#L518) this buffer, decodes it an plays it:

Thanks !  
Bart

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 September 2018 20:03 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/36 "2018-09-02T20:03:38Z")

</div>

Must admit I don’t know. Don’t have a mic either so not tried that node. May just be a config problem he has.

---

<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:** [2 September 2018 20:12 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/37 "2018-09-02T20:12:26Z")

</div>

No problem. I have ordered a microphone for raspberry from [Aliexpress](https://nl.aliexpress.com/item/SunFounder-USB-Mini-Microphone-for-Raspberry-Pi-3-2-Module-B-and-Rpi-B/32809066524.html?spm=a2g0z.10010108.1000016.1.12072f85QyPrhF&isOrigTitle=true). That allows me to do an end-to-end test, and debug the whole scenario...

Two reasons why I bought it on Aliexpress:

1. Good price.
2. But more important: They deliver only in 3 weeks, so then at least I have some extra time to finish the blockly node first 😉

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [17 September 2018 11:10 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/38 "2018-09-17T11:10:26Z")

</div>

Hi Bart,

Apologies I have parked this for a while.

Flow is below.

Basically if you hit record it sends to a file and then serves up when you hit playback. It's the best I have achieved to date. The top node output (live raw data) does nothing.

I use the webcam microphone and I have also tried [https://www.amazon.co.uk/gp/product/B0757JT9S7/ref=oh\_aui\_search\_detailpage?ie=UTF8&psc=1](https://www.amazon.co.uk/gp/product/B0757JT9S7/ref=oh_aui_search_detailpage?ie=UTF8&psc=1)

`[{"id":"38f4fce9.a7a8c4","type":"microPi","z":"3604bb55.40a244","name":"microPi","filename":"/home/pi/audio/sound.wav","domain":"http://localhost:8989/getAudio","rate":"16000","bitwidth":"16","endian":"little","encoding":"signed-integer","channels":"1","silence":"5","debug":"true","mode":"666","x":380,"y":140,"wires":[[],["b83ead5b.13deb"],[]]},{"id":"14b5ec.4925ca15","type":"inject","z":"3604bb55.40a244","name":"record","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":"","x":110,"y":120,"wires":[["38f4fce9.a7a8c4"]]},{"id":"7fb8dc82.8def04","type":"inject","z":"3604bb55.40a244","name":"stop","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"x":110,"y":160,"wires":[["38f4fce9.a7a8c4"]]},{"id":"eb48aa20.6a6b28","type":"ui_template","z":"3604bb55.40a244","group":"f19ce9d9.8e1b38","name":"record","order":28,"width":"1","height":"1","format":"\n<md-button class=\"vibrate filled touched smallfont rounded\" style=\"background-color:#34495e\" ng-click=\"send({payload: 'Hello World'})\"> \n Start\n</md-button> \n\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":90,"y":80,"wires":[["7323cdff.622174"]]},{"id":"7323cdff.622174","type":"change","z":"3604bb55.40a244","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":80,"wires":[["38f4fce9.a7a8c4"]]},{"id":"aaf3e9b6.1d3cd8","type":"ui_template","z":"3604bb55.40a244","group":"f19ce9d9.8e1b38","name":"stop","order":28,"width":"1","height":"1","format":"\n<md-button class=\"vibrate filled touched smallfont rounded\" style=\"background-color:#34495e\" ng-click=\"send({payload: 'Hello World'})\"> \n Stop\n</md-button> \n\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":90,"y":200,"wires":[["2dda1822.24cb58"]]},{"id":"2dda1822.24cb58","type":"change","z":"3604bb55.40a244","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":200,"wires":[["38f4fce9.a7a8c4"]]},{"id":"b83ead5b.13deb","type":"change","z":"3604bb55.40a244","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"metadata","fromt":"re","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":140,"wires":[["3311e37f.8bbb2c"]]},{"id":"3311e37f.8bbb2c","type":"ui_audio","z":"3604bb55.40a244","name":"","group":"f19ce9d9.8e1b38","voice":"","always":true,"x":740,"y":140,"wires":[]},{"id":"f19ce9d9.8e1b38","type":"ui_group","z":"","name":"Devices","tab":"54f69592.154adc","order":2,"disp":false,"width":"6","collapse":false},{"id":"54f69592.154adc","type":"ui_tab","z":"","name":"Ratby Road","icon":"dashboard"}]`

---

<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:** [30 September 2018 19:10 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/39 "2018-09-30T19:10:29Z")

</div>

Hi @GChapo, @dceejay,

I have been doing a lot of experiments, and finally I have now a solution that seems to be working. Since these were my first steps into the world of audio signals, don't hesitate to let me know if something is not correct !

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/fe2e3ef82ab201fd97237ec060469f8318bf02be.png)

```auto
[{"id":"2852077b.af8aa8","type":"microphone","z":"279b8956.27dfe6","name":"microphone","endian":"little","bitwidth":"16","encoding":"signed-integer","channels":"1","rate":"22050","silence":"60","debug":false,"active":true,"x":950,"y":1220,"wires":[["c61c107a.970a2"]]},{"id":"c61c107a.970a2","type":"wav-headers","z":"279b8956.27dfe6","name":"","channels":1,"samplerate":22050,"bitwidth":16,"x":1136,"y":1220,"wires":[["7597ba6e.5adbb4"]]},{"id":"7597ba6e.5adbb4","type":"ui_audio","z":"279b8956.27dfe6","name":"","group":"180d570c.93b059","voice":"0","always":false,"x":1320,"y":1220,"wires":[]},{"id":"5482134.a222dec","type":"inject","z":"279b8956.27dfe6","name":"record","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":"","x":770,"y":1200,"wires":[["2852077b.af8aa8"]]},{"id":"363b5caf.bf44c4","type":"inject","z":"279b8956.27dfe6","name":"stop","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"x":770,"y":1240,"wires":[["2852077b.af8aa8"]]},{"id":"180d570c.93b059","type":"ui_group","z":"","name":"Devices","tab":"493cf398.76af9c","order":2,"disp":false,"width":"6"},{"id":"493cf398.76af9c","type":"ui_tab","z":"","name":"Ratby Road","icon":"dashboard"}]

```

Have lost two evenings figuring out why I got no sound at all. At the end I read some review of my USB microphone: I had to scream loud at 2 inch distance from my USB microphone, to be able to hear something. So I wouldn't suggest anybody to buy such a microphone 😡

1. I use the ' **microphone**' node (from node-red-contrib-micropi) to get audio samples from the USB microphone on my Raspberry. That node gives a stream of data chunks containing raw audio samples ( **PCM** ). I don't use the **Micropi** node (from the same node set), since that node - like Glenn already discovered - only starts playing data when you send a stop message!

2. However when you send such raw audio chunks to audio-out node in the dashboard, the browser cannot decode the raw audio samples. I just doesn't know what all the bytes mean, so I had to develop the [node-red-contrib-wav-headers](https://github.com/bartbutenaers/node-red-contrib-wav-headers), which adds **WAV headers** to the raw audio data.

3. We now have WAV audio chunks which can be decoded by the browser. But the **audio-out** node [currently](https://github.com/node-red/node-red-dashboard/blob/master/src/main.js#L542) can only play a **single audio file** :

This was only a proof of concept, but - due to a lack of time - there are still some TODO's:

- Some extra tests would need to be done. Would be nice if somebody else could do this ... E.g. I did a basic test whether the audio-out node can still play an audio file like in the original version, but perhaps other tests are required.
- I haven't done any performance tests yet.
- Some extra nodes should be developed, e.g. to convert the PCM chunks to MP3 chunks. Because currently a lot of data is transferred to the browser !! I have already developed some stuff, but I have not enough time to finish it all in a short period of time ...
- And the most difficult challenge: convince Dave to update the audio-out node. Still have to figure out how to accomplish that 🤔

Shoot !!!  
Bart

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 September 2018 19:23 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/40 "2018-09-30T19:23:37Z")

</div>

Well as long as it doesn’t break existing users then happy to look at and try a PR.

[Previous page](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551.md?page=1)

[Next page](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551.md?page=3)
