# USB audio on a Raspberry PI

**URL:** <https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133>\
**Category:** Dashboard\
**Created:** [18 November 2020 12:40 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133 "2020-11-18T12:40:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 12:40 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/1 "2020-11-18T12:40:46Z")

</div>

Hi all,  
I am trying to stream audio from a radio scanner connected to my pi via usb. In simple terms it is acting as a usb microphone. So far i have had no luck at all getting it to work! can anyone provide me with a working example flow/guide? The other issue I am having is my iPad Pro does not play any audio from node red dashboard. any ideas on that?

cheers

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 November 2020 14:09 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/2 "2020-11-18T14:09:46Z")

</div>

Hello,  
Does your scanner show up under Linux like a standard microphone/audio interface under alsa? If you do a `arecord -l` on the command line does show up as an input device or does it stream the data in some kind of raw format over serial?

Johannes

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 14:24 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/3 "2020-11-18T14:24:26Z")

</div>

Yea it does

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 November 2020 14:37 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/4 "2020-11-18T14:37:41Z")

</div>

If shows up with alsa you can install [sox](http://sox.sourceforge.net/) and my node-red-sox-utils nodes from github which are in beta right now to interface with it directly from nodered:

> **[johanneskropf/node-red-contrib-sox-utils](https://github.com/johanneskropf/node-red-contrib-sox-utils)**
>
> a simple node-red wrapper around the record functionality of the sox commandline utility - johanneskropf/node-red-contrib-sox-utils

  
In the record node the scanner should appear in the source dropdown if it’s a valid audio interface giving you the option to record the audio and handle it in nodered.

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 15:56 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/5 "2020-11-18T15:56:54Z")

</div>

Thankyou, this works! however the audio is really choppy! have you got any ideas to fix this?

my flow is attached

```auto
[{"id":"1a1e0044.8a069","type":"ui_audio","z":"a96ef2d9.1d179","name":"","group":"a29ae445.1c44c8","voice":"","always":true,"x":820,"y":60,"wires":[]},{"id":"93930129.3b614","type":"sox-record","z":"a96ef2d9.1d179","name":"","buttonStart":"msg","inputs":1,"inputSource":"2,0","byteOrder":"-L","encoding":"signed-integer","channels":"2","rate":16000,"bits":16,"gain":"0","lowpass":8000,"showDuration":false,"durationType":"forever","durationLength":0,"silenceDetection":"nothing","silenceDuration":"2.0","silenceThreshold":"2.0","outputFormat":"stream","manualPath":"","debugOutput":false,"x":470,"y":60,"wires":[["55c39df.09d1964"],[]]},{"id":"ec08b42f.b38208","type":"ui_switch","z":"a96ef2d9.1d179","name":"","label":"Web Audio","tooltip":"","group":"a29ae445.1c44c8","order":4,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"start","onvalueType":"str","onicon":"","oncolor":"","offvalue":"stop","offvalueType":"str","officon":"","offcolor":"","x":310,"y":60,"wires":[["93930129.3b614"]]},{"id":"3a439393.82dfcc","type":"inject","z":"a96ef2d9.1d179","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"start","payloadType":"str","x":170,"y":40,"wires":[["ec08b42f.b38208"]]},{"id":"9b883a6d.b0f358","type":"inject","z":"a96ef2d9.1d179","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"stop","payloadType":"str","x":170,"y":80,"wires":[["ec08b42f.b38208"]]},{"id":"55c39df.09d1964","type":"wav-headers","z":"a96ef2d9.1d179","name":"","action":"add","channels":"2","samplerate":"16000","bitwidth":16,"x":650,"y":60,"wires":[["1a1e0044.8a069"],[]]},{"id":"a29ae445.1c44c8","type":"ui_group","name":"Radio Controls","tab":"701681b5.a061b8","order":2,"disp":true,"width":6,"collapse":true},{"id":"701681b5.a061b8","type":"ui_tab","name":"Ship Spy","icon":"fa-ship","disabled":false,"hidden":true}]

```

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 November 2020 16:17 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/6 "2020-11-18T16:17:29Z")

</div>

Please put your flow inbetween ``` or use the \</\> button from the toolbar so that your Flow will be formatted properly and can be imported.  
Are you trying to livestream the audio? How are you consuming the stream?

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 17:52 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/7 "2020-11-18T17:52:49Z")

</div>

Yes the audio is streaming to my dashboard

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 November 2020 19:12 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/8 "2020-11-18T19:12:09Z")

</div>

> [@blackwellj](#):
>
> Yes the audio is streaming to my dashboard

I have no experience with this. The raw stream output is not really ment for listening, it’s normally fed to other software/nodes for recording or processing. Is the dashboard node you are using ment for playing streams?  
Because if it’s not explicitly ment for receiving a stream of audio chunks it would play every chunk like it was an individual file which could explain the choppiness you are experiencing.

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 19:13 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/9 "2020-11-18T19:13:38Z")

</div>

I'm using a node to add the wav headers. Is there a way of buffering the audio so its not choppy?

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 19:14 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/10 "2020-11-18T19:14:49Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/7834c2e68f99ce190498e8de6408f4eb6642eb9b.png)  
I have this layout

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 November 2020 19:23 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/11 "2020-11-18T19:23:06Z")

</div>

> [@blackwellj](#):
>
> I'm using a node to add the wav headers. Is there a way of buffering the audio so its not choppy?

As I said I think the problem is that you are streaming audio chunks and the dashboard node is playing each and every chunk individually and not treating it as a stream. So the problem is on the dashboard side.

Edit:  
Here is a link to thread where exactly this issue is discussed but I think never got resolved. Read from the post I linked onwards and you will see it’s exactly the issue I expected (fun fact the node you use to add wav headers was developed because of this):

> [@Play Sound from USB Microphone](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/39):
>
> 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] [{"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,"w…

So unless somebody picks up the proposed changes by Bart and does a working pull request on the dashboard audio out node it looks like it just doesn’t support streams.

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 19:29 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/12 "2020-11-18T19:29:05Z")

</div>

> [@Play Sound from USB Microphone](https://discourse.nodered.org/t/play-sound-from-usb-microphone/2551/40):
>
> Well as long as it doesn’t break existing users then happy to look at and try a PR.

@dceejay did any updates get pushed to fix this?

---

<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:** [18 November 2020 19:45 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/13 "2020-11-18T19:45:33Z")

</div>

Hi Johannes,  
I never got it working without distortions on my Android phone. So that was for me end of story unfortunately...  
Bart

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [18 November 2020 20:22 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/14 "2020-11-18T20:22:05Z")

</div>

Damn! so its a non starter then?

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 November 2020 20:28 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/15 "2020-11-18T20:28:22Z")

</div>

You could try implementing those changes @BartButenaers was working on locally in your installation and see if it works for you as he was only having problems with his android phone and not his desktop if i remember correctly. So it might work good enough for you although it would be a hack of sorts.

---

<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:** [18 November 2020 21:37 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/16 "2020-11-18T21:37:22Z")

</div>

Don’t think I’ve ever seen a PR

---

<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:** [18 November 2020 22:08 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/17 "2020-11-18T22:08:04Z")

</div>

> [@blackwellj](#):
>
> Damn! so its a non starter then?

As Johannes said, you can use it as a starting point if you want. I have spent - at the time being - LOTS of spare time on it, but I only got it working on browsers running at Windows but not at Android (where the sound was very bad). So useless for a pull-request.

You can easily fool your eyes by showing images fast enough, but it seems to be very difficult to fool your ears: the slightest _ **overlap** _ or _ **gap** _ will be hearable.  
I was very disappointed that I didn't managed to get it working cross platform, but perhaps you have more luck. And perhaps meanwhile somebody else has developed some kind of library that you can integrate into Node-RED.  
Good luck with it!

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [20 November 2020 11:15 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/18 "2020-11-20T11:15:51Z")

</div>

I think your mods are beyone my skills ☹ im not interested in android, only IOS or windows

---

<div class="post-metadata">

**Author:** ![blackwellj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/blackwellj/32/243_2.png) [@blackwellj](https://discourse.nodered.org/u/blackwellj)\
**Post date:** [20 November 2020 11:22 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/19 "2020-11-20T11:22:58Z")

</div>

the stream doesnt need to be exact real time,could i record for 1 second then play that recording? then i have a buffer for network latency

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [20 November 2020 11:31 UTC](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133/20 "2020-11-20T11:31:41Z")

</div>

Than you would have a gap in the audio every second and a latency that would build up with every audio chunk that arrives as your problem is that the way it is right now a new play process is started for every chunk that arrives and instead of a continues process that consumes the chunks there is a new one each time. So the reason for the choppiness is this time that it takes to end the old process and start a new each and every time. So sending bigger buffers wouldn’t solve the problem.

[Next page](https://discourse.nodered.org/t/usb-audio-on-a-raspberry-pi/36133.md?page=2)
