sox and rec without the mic

I'm trying to record the output of my speakers, but when I do this, it also records from the microphone. I'd like to only record the non-microphone devices.

Trying:

$ (AUDIODEV=hw:0,0; rec test.mp3)    
$ rec -d hw:0,0 test.mp3

I've also tried ffmpeg:

$ ffmpeg -f alsa -i hw:CARD=PCH,DEV=0 test.mp3
$ ffmpeg -f alsa -i front:CARD=PCH,DEV=0 test.mp3
$ ffmpeg -f alsa -i surround40:CARD=PCH,DEV=0 test.mp3

I've seen elaborate things such as:

$ parec -v -d analog-output-speaker | sox -t raw -e signed-integer b 16 -r 44100 -c 2 test.mp3

Proposed online, but this still records the mic, and comes with obsolete sox options.

How can I record only non-mic input in ubuntu 14.04+ ?


Pulseaudio

  1. Check for available sources

    $ pactl list short sources
    0    alsa_output.pci-0000_00_05.0.analog-stereo.monitor  module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
    1    alsa_input.pci-0000_00_05.0.analog-stereo   module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
    
  2. Specify the monitor device as input for recording command.

    • Using avconv/ffmpeg

      Install it (only for avconv)

      sudo apt-get update
      sudo apt-get install libav-tools
      

      Record using:

      avconv -f pulse -i alsa_output.pci-0000_00_05.0.analog-stereo.monitor test.mp3
      

      or

      ffmpeg -f pulse -i alsa_output.pci-0000_00_05.0.analog-stereo.monitor test.mp3
      

      AFAIK, Ubuntu install only one tool the other just alias (after, libav was forked from ffmpeg)

      $ file /usr/bin/avconv 
      /usr/bin/avconv: symbolic link to ffmpeg
      
    • Using sox

      Install the needed formats

      sudo apt-get install libsox-fmt-pulse libsox-fmt-mp3
      

      or this to install all formats

      sudo apt-get install libsox-fmt-all
      

      Record using:

      sox -t pulseaudio alsa_output.pci-0000_00_05.0.analog-stereo.monitor -t mp3 test.mp3
      

ALSA

Using ALSA directly, reference: https://trac.ffmpeg.org/wiki/Capture/ALSA

Check recording devices

arecord -l

Record (change the corresponding <card> and <device> index)

ffmpeg -f alsa -i hw:<card>,<device> test.mp3

GUI tools

There are also some advanced GUI tools like: audacity.


This method shows how to record whatever audio is playing on your computer, similar to recording "stereo mix" in windows. This makes recording audio played by any application, including flash videos, possible.

I'm using the Sound Recorder application that comes in standard Ubuntu installations. To set this up using other programs (like Audacity) just substitute it in these instructions.

  1. Install pavucontrol (PulseAudio Volume Control) using apt-get or the Ubuntu Software Center.
  2. Open PulseAudio Volume Control. It should be in the applications menu under Sound and Video.
  3. Open Sound Recorder and start recording. Playing any sound at this point would be helpful, as your level indicator should react once you have finished.
  4. Go to the "Recording" tab in the PulseAudio Volume Control window.
  5. Make sure that "Applications" is selected in the drop down menu on the "Recording" tab.
  6. Choose "Monitor of Internal Audio Analog Atereo" from the "Record Stream from" menu in the Sound Recorder entry of the application list.

This appears to be persistent so that you will only have to do this once, but you will have to repeat these steps to record in another application.

All credit for this answer goes to this post.