Raspberry Pi into an audio spying device

If you are a spy or work for the CIA or the FBI, this will come in handy in your knowledge. Given the size and price of the Raspberry Pi, it occurred to me that using it as a spying device (which are actually really expensive) would be really appropriate.

In this case, I’ll explain how to convert your Raspberry Pi into an audio streaming device, or audio spying device, however suits best to you. Use it under your own responsibility.

Plugging the microphone and loading the module

The Raspberry Pi has an audio output jack, but unfortunately there is no input port. We will then need a USB microphone. If you have one, keep reading, if not, go buy one 😉 (or plug a webcam with microphone).

Once the microphone is plugged in, you might have to load the audio module by typing the following command if it isn’t.

sudo modprobe snd_bcm2835

Recording and playing a test file

Now we can try to record some audio into a file by running:

arecord -D plughw:1,0 test.wav

Just press CTRL+C once you think you’ve got enough recording. Now let’s play it to see if it works! But first, plug your earphones to the audio output of your Raspberry Pi!

aplay test.wav

Did you hear anything? Great! Your Raspberry is ready to “rock”ord some audio!

If you want to record louder or adjust some parameter, you can use the alsamixer tool to play with the input/output levels of your microphone.


Once you have set your settings, remember to store your changes:

sudo alsactl store

Streaming the audio to another PC

What we want to do next, is to give the Pi the capability to send this audio through the network, maybe to a server we have somewhere. In order to tho that, we will pipe the audio from the microphone into an ssh communication to the destination computer. As simple as:

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

Now you have everything set! Switch on your speakers in the destination PC, and hear what the Raspberry Pi is spying from hundreds of miles!

Raspberry under the bed
Raspberry under the bed

In this (two overlapped and faded) pictures you can see my Raspberry Pi set under a bed, using a Wifi dongle, set to work as a baby-cry transmitter.

This might be useful in some situations ^^

See you!

47 thoughts on “Raspberry Pi into an audio spying device”

  1. Ei, bona pensada! A més, és prou senzill!
    Per internet veus de tot, gent que li posen LCD’s petits per muntar-se les seves pròpies consoles portàtils d’emulació i tot (vale, jo també vull XD).

  2. Hi, what would you recommend if I would like to store the recorded audio as mp3 (for memory efficiency, and “timeshift” playback). This way, you can download the files and analyze it whenever it is convenient.

  3. Then you would have to install “Lame” and then record as MP3

    sudo apt-get install lame

    arecord -f cd -t raw | lame -x -r – out.mp3

    Then you would have your memory efficient mp3 in out.mp3

  4. Thanks alot for the fast reply, I have ordered a ps3 eye cam to use the mics and try this out. I will give you a review if you are interested. Have a good day!

  5. Thank you for the article,
    I connected the Usb mic to Rpi,
    And now

    “How can I read the LIVE raw digital data?”

    Actually I want to stop recording ‘without Ctrl+C interrupt’, but with ‘when user becomes silent’
    ie.. When the raw bytes is below certain value (ie. below certain amplitude say,) i would stop recording and then write it to some wav file.

    Am I clear? Can you help?

  6. Hey mutsuda! I am interested in gathering audio from a usb microphone connected to my Raspberry Pi and streaming it to another computer real time (PCM format). Would it be possible to accomplish this using the methods you explain here? How would it be done? Thank you!

  7. I would also like to be able to stop the recording when the sound input stops, ideally after 5 minutes of no sound

  8. Hello, here is my “review” as promised:

    I’ve tried it out and it works pretty well. But I didn’t use a Raspberry Pi to run this setup but used a Pogoplug model B04 with archlinuxarm running on it. It has only 700MHz but got dualcore power ^_^. Running arecord with 22050Hz pipelining to lame:

    arecord -f S16_LE -r22050 | lame – longtermtest1.mp3

    creates about 95% CPU usage on ONE core. Bitrate is at 32kBit/s, the sound quality is OK for this purpose. 24h recording “costs” somewhere around 350MByte, I did the math, but don’t remember the exact figure. I’ve reduce the frequency to half of the typical 44KHz to reduce abit CPU load. With this setup arecord takes about 3-5% and lame about 85-90% CPU in a single core. Sometimes thw whole thing gets to 100% and the result is a overrun:

    overrun!!! (at least -1747563690.477 ms long)

    … seems like it’s not that big of a deal. I don’t know much about the whole thing, but this should be like frame skipping in video games. Nothing too bad. I got it like 25 times in a 10h test record. The file could be opened in audacity without problems, but takes some time.

    I also tried to run the whole thing in 2 thread at a time. The 2 cores where busy as expected but it recorded fine. So there is still enough CPU time to do other things.

    There a some other things I will try to make this thing more efficient and usefull:

    1 – I’m thinking of loading the recordings on a ftp server or send it out via email as the uplink from my internet connection is just around 1MBit. So whenever it is confortable for me I can download the big mp3 file from a much faster server.
    There is also a possibility (option) to have arecord (or was it lame?) make recordings in predefined pieces like 2h. It can come handy when opening the files in adacity because you don’t have to load a big file junk.

    2 – file names with timestamps (this should be easy)

    3 – creating waveforms as images for the files so you can see where the interesting pasts are. So you only download the recordings where it seem to be something going on.

    4 – possibility of recording only when the signal reaches a certain threshold.

    any sugestions or comments are welcome and appreciated.

  9. Oh, I forgot to mention the usage of ‘screen’, the terminal multiplexer to keep it running and monitoring the error messages without beeing connected. This part is very important as the Pogoplug B04 can only be accessed via SSH, there is no video out.

  10. Hi, i’m reallt interested in setting up this project. Do you think it’s possible to give me more details on setting up the target machine instead? i have some problems with it

  11. hi .. another geek transforming into a father here :-)
    unfortunately i am not catching the audiostream..
    1) what would “user@remoteip” be, if i want to get the sound on a win7 or an iphone?
    2) how do i stop the audiostream
    great project!

  12. Hi, i’ve tried to set up the same thing with two raspberry pi running on Raspbian with the following code.
    arecord -D plughw:1,0 -f dat | ssh -C pi@ aplay -f dat
    It does not work. Instead, another problem arises.
    pi@raspberrypi ~ $ arecord -D plughw:1,0 -f dat | ssh -C pi@ aplay -f dat
    ALSA lib pcm_hw.c:1401:(_snd_pcm_hw_open) Invalid value for card
    arecord: main:682: audio open error: No such file or directory
    pi@‘s password:
    aplay: playback:2483: read error
    What does this mean? Have i set up the system wrongly?

  13. Hi,

    Just what i was looking for. I’m actually looking to create a baby monitor with audio and video feed with the raspberry pi. Would you care to mention which mic you used? Or any good recommendations for a USB mic to use with the raspberry pi?

    Many thanks!

  14. great work, I have a question, does it actually have to record? I mean I’m interested in this project but i would actually want to it to start recording when the input volume level passes a certain level then stop recording when it decreases again. Once stopped it can send the file.

    Any thoughts or advice?

  15. I have webiopi and cambot running on my Ras Pi, and I’m currently using this server to stream video from my robot to a web page, but I also need audio. Instead of using ssh to stream the audio, can I stream microphone audio from the Pi to a laptop running a web page that has the video and play the audio through the browser?

  16. How adorable. Those government agency has better shit than the shitty pi. Oh, and fuck agents.

  17. what the fuck THAT IS ILLEGAL. I hope all of you get busted and hung up by your testicles for spying on people when they don’t know their being watched! DIE snakes DIE!!!

  18. You can detect the presence or absence of sound by monitoring the amplitude of the audio.

    I found on the SoX manpage that one of the output formats it supports is .dat, which gives you normalized amplitude cuts ranging between +/-1.0 per sample for your audio in a readable format.

    To do it in realtime, you should be able to do something like this:

    arecord -D plughw:1,0 -f dat -t wav | sox -t wav – out.dat

    at that point, you could write a script which will scan the file and look for amplitude changes indicating the presence of sound.

  19. Had a slight hangup because I didn’t have an ssh server running on the computer I was trying to listen from. After I “sudo apt-get install openssh-server”, it works like a charm just by following your instructions. Almost 0 latency too! Thank you so much, Mutsuda.

    Quick question, any way you know of to listen from an Android tablet?

  20. Had a slight hangup because I didn’t have an ssh server running on the computer I was trying to listen from. After I “sudo apt-get install openssh-server”, it works like a charm just by following your instructions. Almost 0 latency too! Thank you so much, Mutsuda.

    Quick question, any way you know to listen from an Android tablet?

  21. Hello Dear,

    You have provided a tremendous easy method to that, but the problem i am facing is that i could not heard the recorded audio except some scrambling noise..I did connected my A4Tech USB headphones.

    Do you have any further idea about this problem..??


  22. Dear Mustada,
    I have configured all the settings as you provided, i could hear the local recorded sound but can not establish the ssh session. it gives an error “unable to install hw params”.

    Any further recommendations..??


  23. Do you think it’s possible for RPi to receive a stream as if it was a microphone? That’s something that would be truly awesome to have. One RPi, and the whole house is wired with transmitters sending audio to RPi and then parsing it to text. If all well connected you can be on the other side of the planet and receive text messages of what people are saying in your house.

  24. Speech to text doesn’t work very well unless you have strong clear audio to work with. Hidden microphones usually pick up weak audio with a lot of background noise, so I suspect that the text you’ll get will be mostly gibberish.

  25. I like this idea but I want to take it one step further. I’d like to use it for Skype so I can cut the wire to my laptop. Perhaps even stream the video, I’d like the ability to do that even if I’d most likely not use it.
    Any thoughts?

  26. I can record/playback a text file on my Rpi but nothing comes out the remote XP PC when I try the streaming. Do I need anything special running on the PC (like Putty)? And for ‘user@remoteip’ I have Fred@ – is this the correct format? And my user does not have a startup password, could this be the problem?

    Many thanks

  27. Hi Geo!
    You need an SSH server running on your destination computer, and use your server credentials for user and password.

  28. Hi Matsuda, I got it working. The confusion was that your article assumes a Linux PC, I have a Windows PC.

    I used the following on the Rpi:
    arecord -D plughw:1,0 -f dat | cvlc -vvv stream:///dev/stdin –sout ‘#rtp{sdp=rtsp://:8554/}’ dat
    and at the Windows PC I ran VLC media player and set the network stream to:

    A similar setup works for video too. Hope this helps someone!

  29. Hi, Can you provide the details about your baby cry monitor? I’m working on a similar RPI project – baby monitor.

    I’ve the video stream running using Motion (http://www.lavrsen.dk/foswiki/bin/view/Motion/WebHome) on local network. However, I’m not able to merge video & audio from my USB camera mic.

    I tested the mic and I can record and play like this from the raspberry:

    $ arecord -D plughw:CAMERA -r 16000 test.wav -d 5
    $ aplay -D plughw:ALSA test.wav

    But video on the local network has no audio (which is expected because motion doesn’t do audio mixing). Any way to get that audio & video mixed?


Leave a Reply