# 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:** 3

<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 September 2018 20:32 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/41 "2018-09-30T20:32:06Z")

</div>

Thanks guys,

I'll do some tests and come back to you as soon as I can.

Glenn

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [30 September 2018 21:33 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/42 "2018-09-30T21:33:57Z")

</div>

> [@dceejay](#):
>
> Don’t have a mic either

Would a USB webcam work instead? I have one or two of those lying around & I've meant to try them out, just not got round to it.

---

<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 September 2018 21:47 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/43 "2018-09-30T21:47:53Z")

</div>

Yes a USB webcam will work.

---

<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: [1 October 2018 08:07 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/44 "2018-10-01T08:07:06Z")

</div>

> [@BartButenaers](#):
>
> npm install bartbutenaers/node-red-contrib-wav-headers

Hi Bart,

Struggling to load wav headers as shown. Please advise?

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: [1 October 2018 10:22 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/45 "2018-10-01T10:22:23Z")

</div>

Hi Bart,

All good now and loaded.

Great work! The sound plays through a USB Camera. I have yet to test with the separate microphone and I am yet to test latency.

My comment so far is that it sounds a little jagged at times as if bits of data are being missed. I have also had to reboot once as it stopped completely, but that maybe a separate issue I'm not sure. I will keep running trials and I will report back.

Thanks again

Glenn

---

<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: [1 October 2018 10:44 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/46 "2018-10-01T10:44:59Z")

</div>

Glenn,  
You are welcome!

Would be nice if you could do some tests, because of I lots of other Node-red developments on my todo list.

> [@GChapo](#):
>
> it sounds a little jagged at times as if bits of data are being missed

That was something I was worried about. Will need to investigate it...

---

<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: [1 October 2018 10:49 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/47 "2018-10-01T10:49:54Z")

</div>

Do you think the wav-headers node is good enough to publish on NPM?

---

<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: [1 October 2018 11:08 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/48 "2018-10-01T11:08:59Z")

</div>

And another question. How have you implemented my change of the dashboard audio-out node?

---

<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: [1 October 2018 11:30 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/49 "2018-10-01T11:30:44Z")

</div>

I have made no implementation change. All I have done is load the wav node in, import your flow, stick two dashboard buttons on for playback and stop and deployed

---

<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: [1 October 2018 11:42 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/50 "2018-10-01T11:42:52Z")

</div>

Ah that might explain the missing samples. In the discussion you will see that I changed the dashboard code. Currently it will play one sample at a time. In my code the chunks with samples are continiously appending samples. I will do a pull request this evening, so Dave can load my changes. Hopefully it works smoother then for you.

---

<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: [1 October 2018 11:55 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/51 "2018-10-01T11:55:40Z")

</div>

Look forward to it. Thanks

---

<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: [1 October 2018 12:32 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/52 "2018-10-01T12:32:22Z")

</div>

> [@dceejay](#):
>
> Well as long as it doesn’t break existing users then happy to look at and try a PR.

Hi Dave (@dceejay),  
I would like to pass my pimped dashboard version to Glenn, so he can test whether the audio is streamed smoothly with my fix. Once all tests are completed, I will create a pull request.  
What is the easiest way to do this? Can I pass him the content of my /dist folder?

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: [1 October 2018 12:42 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/53 "2018-10-01T12:42:23Z")

</div>

that should do it - though I'm happy to look at PR as soon as you are ready.

---

<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: [4 October 2018 17:52 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/54 "2018-10-04T17:52:59Z")

</div>

Evening Dave (@dceejay),

Have been experimenting a bit further, with the aid of Glenn. The new _ **node-red-contrib-wav-headers** _ seems to be working fine, but there is still some work on the **audio-out** node. Glenn sended me same wave files (with his dashboard sound recordings) and the good new is that we have streaming audio. The bad news is that you can hear from time to time that the stream is chunked. Have been looking for solutions, but they are more complex as my original proposal (which was rather short).

So the question is: are you still interested in integrating it into the dashboard, if the code changes are becoming larger? Or should I create my own template node...

---

<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: [4 October 2018 17:55 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/55 "2018-10-04T17:55:46Z")

</div>

Still happy for a PR. As long as existing users won’t break when they upgrade.

---

<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: [4 October 2018 17:58 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/56 "2018-10-04T17:58:56Z")

</div>

> [@dceejay](#):
>
> As long as existing users won’t break when they upgrade.

Deal !

However it will take a bit longer as expected. But that is becoming a habit ...

---

<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: [1 November 2018 13:17 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/57 "2018-11-01T13:17:29Z")

</div>

Hey Dave,

I'm completely stuck on the audio streaming. I managed to get acceptable quality in a dashboard running on my **PC**. However the sound has a lot of distortions on an **Android** phone. Have been remote debugging yesterday evening (via USB cable), but the code seems to be acting as I expected on my phone:

- Enough audio chunks from the Node-RED flow are queued in the dashboard, so no gaps.
- All parameters (number of channels, playback rate, ...) are identical to the test on my PC.
- All audio chunks are nicely splitted and joined again.
- ...

Since I have no indication anymore why the audio is bad on Android, I thought adding some troubleshooting functionality to the audio-out node. For example in this [link](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Visualizations_with_Web_Audio_API) it is explained how to visualise the audio samples in a graph, both a **waveform (like oscilloscope)** or **frequency bars (like spectrum analyzer)**. Perhaps it doesn't help me finding the solution, but that is the only option I have at the moment 😩

Do you think it would be a good idea to display - optionally - such a **canvas** in your audio-out node (invisible by default) or should I create a new custom node (based on the new widget API)? And if you prefer the first option, could you give me a hint how I should accomplish this (via ui.add...)?

I would prefer the first option, since I could add the **AnalyzerNode** in the existing audio **chain** that I have already build:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2e13653508d5fb19e4daaccd65a157f355fc5b30.jpeg)  
If you don't want this in the standard audio-out node, it might perhaps be better to put the entire streaming functionality in a custom node (and keep the audio-out node for playing a single audio file, as it does today already).

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: [1 November 2018 14:59 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/58 "2018-11-01T14:59:39Z")

</div>

Hi Bart, apologies I got slightly confused with which method you are proposing as your preferred.... to extend the existing node ? or to create a new one ?  
To my mind the audio out node is an end of a flow - If that suits this then yes... - but if what you are thinking is more like a debug node (as in you may want more than one...) then maybe a new node may be better - or at least turn off the actual audio out when in visual mode ?

---

<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: [1 November 2018 15:46 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/59 "2018-11-01T15:46:53Z")

</div>

Hi Dave, I prefer to add it to your node (but not visible by default). Reason: once we 'ever' publish it on npm, there will be users saying I doesn't work correctly on device X with browser Y. Then it could be useful that they could visualize the audio, e.g. dropdown on config screen ("not visible", "waveform", "spectrum"). It is just an idea, because I found the audio distortions very difficult to analyze. But as said before, I'm not an audio expert...

---

<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: [1 November 2018 16:08 UTC](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/60 "2018-11-01T16:08:26Z")

</div>

so the hide/show would be an option a config option in the node ?  
I don't think I have a problem with that. (at this conceptual level 🙂

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

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