Saturday, 8 July 2017

Record internal speaker audio in Linux

Record internal speakers in linux
Recording internal audio in Linux
The other day I came up with this brilliant idea to use my mobile phone as a bluetooth speaker for my laptop. I decided this could be easily accomplished once we had access to the whatever the audio card has, save it and stream it on tcp or udp port across a network connection to my mobile phone by piping it netcat after conversion to wav.

Sounds perfect, except the fact that it has been already implemented. Meanwhile, through numerous visits to stackoverflow and askUbuntu I finally discovered a cool new way to record audio.





  • pacat --record -d alsa_output.pci-0000_00_1f.3.analog-stereo.monitor | sox -t raw -r 44100 -s -L -b 16 -c 2 - dump.wav
This uses pacat to record the audio and then sox to convert it to wav and then save it. We could even go one step further and pipe this to netcat giving us the following command.

  • pacat --record -d alsa_output.pci-0000_00_1f.3.analog-steremonitor | sox -t raw -b 16 -e signed -c 2 -v 7 -r 44100 - -t wav - | nc -l 7777
This will stream the wav file using netcat on port 7777. This file can be saved by another netcat client and later played with vlc.

If you get any error while firing these commands check your output for the following command

  • pacmd list | grep "\.monitor"

Here is my output

name: <alsa_output.pci-0000_00_1f.3.analog-stereo.monitor>
alsa_output.pci-0000_00_1f.3.analog-stereo.monitor/#0: Monitor of Built-in Audio Analog Stereo

No comments:

Post a Comment