Search code examples
linuxubuntuaudiomp3alsa

How can I record that sound going out of my speakers (not what's coming into the mic)?


I'm trying to record the sound my computer produces (without using a microphone)

I've found these two commands that work to record my microphone output into files:

# creates mp3
arecord -f cd > my_file.mp3

# creates ogg
arecord -f cd -t raw | oggenc - -r -o out.ogg

However I am not sure how to record the audio coming out of my speakers directly.


I should note that I have figured out how to do this using PulseAudio and Audacity - there's a good tutorial here however it broke my microphone input and also I would like to be able to do it from the command line.


Solution

  • Revisiting this 5 months later, I finally figured it out.

    From the answer here:

    1. sudo apt-get install pulseaudio-utils lame mpg123
    2. pacmd list-sinks | grep -e 'name:' -e 'index' -e 'Speakers', find the string in between <> brackets - for me it's alsa_output.pci-0000_00_1b.0.analog-stereo
    3. start playing some audio
    4. parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | lame -r -V0 - out.mp3
    5. control + c to stop

    Now for the tricky part, the file for some reason cannot be listened to with aplay - it just sounds like static. Listen to it with mpg123 instead.