Thomas Fischer's Weblog

Life, Linux, LaTeX

Recording VoIP Phone Calls with ALSA

with one comment

Recently I stumbled upon the problem of how to record a phone call when using Skype (or any other VoIP technology) under Linux. For Windows and Mac OS X, there is a bunch of commercial software available, but nothing for Linux. But hey, it is open source and everything is documented, so why not figuring out how to do it anyway?

After searching for options, I found a pointer to the tee device, which works similar like the tee command on the command line: You can transparently pipe data through it and a copy of all data will be written to a file as well. A new ALSA output device can be configured in ~/.asoundrc using the tee device. It can either record the default device or a specific device:

pcm.tee00 {
        type empty
        slave.pcm "tee:'plughw:0,0','/tmp/out0.wav',wav"

Above example will save all audio recording going through plughw:0,0 to file /tmp/out0.wav. If you have different recording and playback devices (e.g. an USB microphone and standard speakers), add multiple section with the corresponding plughw number (also change the device’s name, e.g. pcm.tee10).
In the VoIP application, you have to set the new sound devices for microphone and speakers accordingly:

Skype Audio Settings
(numbers and names of devices may differ for you!)

If you make a test call, you will get two output files: one with your microphone’s recording and one with your speaker’s recording. Using a sound editor like Audacity or SoX, you can edit and merge both files.

This approach, however, has one drawback. Every time an application “opens” a sound device, the output file will be recreated and the previous recording will be lost. With Skype, the hangup sound at the end of the recording is such a case. I haven’t found out if you can configure ALSA’s tee device to append to a file instead of overwriting it, but the solution I came up with is to copy the output files to a different location before the phone call is over. To automatize the process, I wrote the following shell script:


while true ; do
        timestamp=$(date '+%Y%m%d-%H%M%S')
        for wav in /tmp/out*.wav ; do
                test -f "$wav" || break
                newwav="$HOME/out/"$(echo "$wav" | sed -e 's/\/tmp\///;s/.wav$/-'$timestamp'.wav/')
                echo "Copying  $wav  to  $newwav"
                cp "$wav" "$newwav"
        sleep 10

When running, it will copy every 10 seconds all output wav files from /tmp/ to the out/ directory in your home and append a time stamp to the file name. You simply start this script before starting the phone call and exit it with Ctrl+C. Then, the largest of files out0*.wav or out1*.wav, respectively, in the out directory will be your microphone or speaker recording, respectively.


Written by Thomas Fischer

March 20, 2010 at 12:00

Posted in Linux

One Response

Subscribe to comments with RSS.

  1. See for a solution of the same problem without a shell script.

    Alexander E. Patrakov

    July 8, 2010 at 4:18

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: