5

I have a "simple" question. I would like to turn my Pi into an audio streaming device for a game, where I need to hear what is going on in a room.

So I connected a USB microphone to the Pi and would like to set up a stream now, that streams the microphone input to a client (perfectly any streaming format that is supported by browsers, so an HTML5 audio element would be awesome.

I already tried the way it is described here: Raspberry Pi into an audio spying device by using ssh to transmit the data, but this is not really flexible and it does not suit my application as the latency is too much.

arecord -D plughw:1,0 -f dat | ssh -C user@remoteip aplay -f dat

The problem is that in this situation it has to stream as close as possible to real-time, because I'm observing a game-play from outside of the room and I really need to know what is going on in the room in real time.

I know, there are options like Icecast and Darkice (both seem to be hard to configure and not exactly what I'm looking for) and VLC streams. But my limitations are the web browser support on the client side and the low CPU performance of my Raspberry Pi.

I hope someone can help me out with this problem!

2 Answers 2

5

If you want realtime html5 audio on the receiver side, I would definitely recommend a streaming audio solution. CPU, network and memory load is probably much less compared with the solution you described.

Icecast in combination with Jack for streaming audio seems a good solution at first sight. Icecast is well documented and works fine for audio output. But it might get hard to get Jack working on a PI.

You could also try an equally good combination of Darkice and Alsa, which is described in detail here: https://stmllr.net/blog/live-mp3-streaming-from-audio-in-with-darkice-and-icecast2-on-raspberry-pi/

If you want to continue with your approach, you might want to convert the raw audio data to MP3 before you bring it to the ssh pipe, just to relax the bandwidth and file I/O.

4
  • Hi, thanks for your reply. I'm really new to iceboats and Jack. Can you provide me some more information how to set it up? I managed to setup icecast now, but I don't know how to use Jack as a input stream
    – SebasZil
    Jun 24, 2015 at 13:39
  • I Googled a bit to find an answer for you. The 'using jack' section goes straight to the topic: wiki.linuxaudio.org/wiki/raspberrypi
    – iep
    Jun 24, 2015 at 18:58
  • I have digged deeper into the subject and found that it is harder as I thought to get Jack running on a PI compared with other hardware or VPS. So my previous answer might take you on a more difficult challenge as I have suggested. I'll keep you posted, good luck in the meanwhile.
    – iep
    Jun 26, 2015 at 17:51
  • I didn't try this on a PI but the next link contains a series of actions that got me running on other debian platforms. It's a darkice/alsa solution, which is as good as icecast/jack: stmllr.net/blog/…
    – iep
    Jun 26, 2015 at 18:08
3

I think you should try one of two things. Firstly if you want low latency, you should ditch the USB approach which has more latency then one of these GPIO header based sound cards. This can take you from 3 ms down to 0.5 ms in ALSA latency. Now you have to worry about network latency.

For network latency, you can also ditch the server and go directly for a rtp (real time protocol). For example us avconv (ffmpeg) to stream the RTP audio directly using their 'rtp' protocol and in your html5 you can simply play that rtp stream back.

Another way to do it with close to zero delay is to just simply use analog ! Let the game do audio and set your sound card into 'bypass' mode which adds the analog input to the analog output of the sound card, whilst letting the sound card do its digital thing at the same time. This has zero delay. You can then take those analog wires directly into the room you are in and listen to it at the same time ... assuming the rooms are close enough to do this.

Matt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.