USB audio on a Raspberry PI

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

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

Yea it does

If shows up with alsa you can install sox and my node-red-sox-utils nodes from github which are in beta right now to interface with it directly from nodered:


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.

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

my flow is attached

[{"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}]

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?

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.

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


I have this layout

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):

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.


@dceejay did any updates get pushed to fix this?

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

1 Like

Damn! so its a non starter then?

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.

1 Like

Don’t think I’ve ever seen a PR

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!

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

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

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.