# 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:** 1
**Showing post:** 39

<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

---

_[View the full topic](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551)._
