Can I setup a loopback audio device?

16,333

Solution 1

Yes.

Actually there are lots of ways. You can set up a sound dummy sound card device that you can just rip the data out of the device ... however this isn't a very useful format.

More useful to you is something like the arecord utility that allows you to eavesdrop on the alsa output stream and save it to several known formats. Basically anything that you can get to play over the alsa sound system can be copied to a standard format sound file.

Similar tools exist for pulse audio.

Solution 2

If your system, or just the application you want to record, is directing its output to a sound server, look into recording possibilities for that sound server. For example, on Ubuntu, the official sound server is PulseAudio, which comes with the parec command (from the pulseaudio-utils package Install pulseaudio-utils http://bit.ly/software-small). You may need to convert the output from parec into something usable with SoX (Ubuntu: sox Install sox http://bit.ly/software-small).

parec -r --rate=44100 | sox --type raw --rate 44100 - --type ogg recording.ogg

Solution 3

It is supposed to be possible to record directly in to Audacity, but I couldn't get that to work on my system (Ubuntu 10.10). So following the instructions here from the Audacity wiki, I use the ALSA playback device to divert the audio to a file.

This uses an .asoundrc file (in your home directory):

pcm.teeraw {
   type empty
   slave.pcm "tee:default,'/tmp/out.raw',raw"
   # 48000 S16_LE 2ch (aplay -t raw -f dat)
}

For recording from flash (on firefox), I use

FLASH_ALSA_DEVICE=teeraw firefox

The resulting file, /tmp/out.raw is in raw format so converting it needs knowing what the right parameters are. Bizarrely, lame seems able to work this out for itself but sox needs to know it explicitly. So the following all seem to work:

aplay -t raw -f dat -r 44100 /tmp/out.raw # to play
sox -r 44100 -b 16 -e signed -c 2 /tmp/out.raw /tmp/out.wav # to convert to wav
lame /tmp/out.raw # to convert to mp3
Share:
16,333

Related videos on Youtube

D4RIO
Author by

D4RIO

I'm a Chemist and Unix Lover. Worked as C/C++ Senior Programmer on Unix-like systems at Accenture, now I'm Chemical Technician in a Lab and Chemical Engineer student so far. I've long time experience in Unix-like systems (Several Linux distros, FreeBSD, AIX, HP-UX, SunOS), C/ASM/Bash/Perl/PHP programming, and Makefiles. Registered Linux User #452001

Updated on September 18, 2022

Comments

  • D4RIO
    D4RIO over 1 year

    If I can send audio to the output devices, then I can record the same audio as a wave. With filesystems, you can just setup a loopback filesystem and write binary data on a file instead of a device.

    My question is: Can I send the audio signal to a (for instance) WAV file instead of my audio devices? How?

  • Matthew
    Matthew over 11 years
    that didn't work for me, but this variation-on-the-theme did: askubuntu.com/questions/60837/…
  • Suzana
    Suzana over 8 years
    The link from the Audacity wiki is dead.