35

I am trying to capture sound card output and encode it in Vorbis ogg format using the following command:

arecord -f cd -t raw | oggenc - -r -o file.ogg

However, the computer's microphone input is recorded rather than the sound card output.

The output of the command arecord -l is

**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CONEXANT Analog [CONEXANT Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

The output of the command arecord -L is contained in this pastebin entry.

The arecord man page indicates that the input device can be selected using the -D flag, but gives no syntactical examples.

I would like to know how to change the input for arecord from the microphone to the sound card. I am not interested in GUI-based alternatives such as Audacity. Thanks.

Edit: I am running Debian 7.0 (stable) with arecord version 1.0.25, vorbis-tools version 1.4.0, and ALSA driver version 1.0.24.

5
  • Does your hardware have some mixer control to route the output back to the capture device?
    – CL.
    May 19, 2013 at 8:37
  • @CL. The only pre-installed mixer that I am aware of is alsamixer. If I select the loopback card within alsamixer (F6 key to select sound card), I receive the message This sound device does not have any controls. If I exit the mixer and return, I find that the sound card is restored from loopback to the default card. Attempting to suspend (ctrl-z) and background (bg) the alsamixer process after selecting loopback does not enable successful recording of audio via the arecord command.
    – user001
    May 20, 2013 at 4:15
  • The card selection in alsamixer does not affect the rest of the system; it just changes which controls are shown. What are the recording selection controls of the Conexant device?
    – CL.
    May 20, 2013 at 6:45
  • @CL. For my Conexant device, I have one playback control (Master) and one capture control (Capture) within alsamixer. The capture can be toggled on and off with the spacebar within alsamixer and it is on by default. Please let me know if this is not what you intended. Thanks.
    – user001
    May 20, 2013 at 9:51

6 Answers 6

14

years later the struggle continues... how to specify the recording device, lo and behold:

➜  ~ arecord -l                                                              
**** List of CAPTURE Hardware Devices ****                                   
card 0: PCH [HDA Intel PCH], device 0: CX20590 Analog [CX20590 Analog]       
  Subdevices: 1/1                                                            
  Subdevice #0: subdevice #0                                                 
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]       
  Subdevices: 1/1                                                            
  Subdevice #0: subdevice #0     

➜  ~ arecord -f S16_LE -r 44100 --device="hw:1,0" plik.wav                   
Recording WAVE 'plik.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono 
^C
Aborted by signal Interrupt...  

So the format for device string is hw:<card>,<device>

format of device id

1
  • The values accepted by --device switch are given by arecord -L, not arecord -l. You can use names returned by arecord -L directly. The switch name is confusing as it does not accept "devices" but "PCMs" - from manpage: -L, --list-pcms List all PCMs defined -D, --device=NAME Select PCM by name
    – Strachu
    Sep 6, 2021 at 18:04
11

I had the same problem and found another solution here. The main idea is to use pacat. For me it works like this:

  1. Find monitor device:

    $ pacmd list | grep "\.monitor"
    name: <alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor>
    name: <alsa_output.pci-0000_00_1b.0.analog-stereo.monitor>
            alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor/#0: Monitor of HDA NVidia Digital Stereo (HDMI)
            alsa_output.pci-0000_00_1b.0.analog-stereo.monitor/#2: Monitor of Built-in Audio Analog Stereo```
    
    
  2. Capture audio to file:

    $ pacat --record -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor > dump.raw

  3. Convert file to WAV:

    $ sox -t raw -r 44100 -e signed-integer -L -b 16 -c 2 dump.raw output.wav

That's it!

1
  • 6
    Note that you can use parec instead of pacat --record. You can also avoid the use of sox and use parec -d <monitor> --file-format=wav output.wav. You can list available file formats with parec --list-file-formats.
    – Peque
    Apr 5, 2017 at 17:20
9

I'd suggest using the ALSA loopback driver. To load it:

sudo modprobe snd-aloop

This should add a new capture device to the output from arecord -L.

If you have only one physical soundcard in your computer, you can make the loopback soundcard the default for all apps by creating a file .asoundrc in your home folder with the following content:

pcm.!default {
    type hw
    card 1
    device 0
}

While this file is in place, any sound output from all applications should go to the loopback adapter rather than your actual speakers. Just specify the correct device in your arecord command and once you're done, remove the .asoundrc file to go back to normal.

5
  • Thanks for your suggestions. Despite creating .asoundrc in my home directory and restarting the terminal emulator session, audio is still directed to speakers. The arecord -f cd -t raw | oggenc - -r -o file.ogg command records nothing. Issuing arecord -l provides the same list as before, but with two additional lines for card 1: Loopback (devices 0, 1), each with 8 subdevices (#0-#7). Likewise, arecord -L added the following three lines: sysdefault:CARD=Loopback [newline] Loopback, Loopback PCM [newline] Default Audio Device. Continued in next comment due to character limit.
    – user001
    May 20, 2013 at 3:56
  • Attemping arecord -f cd -t raw --device=sysdefault | oggenc - -r -o file.ogg records a blank audio file for the duration the command is executed (it does not draw audio data from the microphone as before). Unfortunately, sysdefault is degenerate as it is defined to be both CARD=PCH (first line of arecord -L) and CARD=Loopback (last line of arecord -L). Thanks for any follow-up suggestions you are able to provide.
    – user001
    May 20, 2013 at 4:01
  • The loopback allows to record only what is played to its playback device, not to the sound card output.
    – CL.
    May 20, 2013 at 6:51
  • Sorry my answer didn't work - it works on my setup. I'd recommend taking a look at this explanation of the asoundrc file: alsa-project.org/main/index.php/Asoundrc I'm fairly sure if you try a few things and play around with different devices a bit more you should get it working. A bit of a kludge, but do you happen to have a physical 3.5mm->3.5mm cable? If so, you could always just connect your headphones output jack to the mic/line in jack.
    – beveradb
    May 20, 2013 at 20:28
  • If you can't get it working with asoundrc, these links may provide more info to help figure it out: sabi.co.uk/Notes/linuxSoundALSA.html#tasksRecordPlay forum.vectorlinux.com/index.php?topic=7500.0 If you still can't get it working, you could switch to using PulseAudio instead of ALSA. This answer explains how to do this using PulseAudio: askubuntu.com/questions/171287/…
    – beveradb
    May 20, 2013 at 20:30
2

Your hardware does not support capturing its output; once the data has gone into the actual playback device, it's gone.

You need to use some software that duplicates the audio data before it is written to the hardware.

I'd suggest using PulseAudio; there you can simply select one of its outputs as capture source: pavucontrol output monitoring

1
  • I installed pavucontrol and tried recording using gnome-sound-recorder. When I open gnome-sound-recorder and begin recoding (Ctrl-R), the stream appears in the PulseAudio Volume Control window. The stream does not actually record any data, however (the final length is 0:00). Also, are you familiar with how to perform the recording through command line instead of a GUI? Thanks .
    – user001
    May 21, 2013 at 22:16
0
  1. Go to PulseAudio Volume Control -> Input Devices Tab. At the bottom, choose to show "ALL input devices". Check if "Monitor of Internal Audio Analog Stereo" is not muted and the volume going up and down as you play the audio!!

  2. Use Audio Recorder to record Audio Source = Internal Audio Analog Stereo (Audio Input). See screenshot below.

enter image description here

0

I have just installed audio-recorder: https://launchpad.net/audio-recorder which in its options show what you need...

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .