Recording Audio – Using ALSA Loop Device from Web-Based Player

alsaaudiorecording

I am trying to save voicemail messages from Verizon Fios phone in best
quality possible. The voicemail messages are available online, but for playing only (Java based player),
no saving. Officially, there is no supported way how to save original digital voice messages as files from Fios Digital Voice
service (no paid service, no anything, no reason why).

My only idea was to record digital data from the player while on the way
to the soundcard. I tried Linux ALSA configuration with loop device.

# cat /etc/asound.conf

# default device
pcm.!default {
    type plug
    slave.pcm "loop"
}

# output device
pcm.loopout {
    type dmix
    ipc_key 328211
    slave.pcm "hw:Loopback,0,0"
}

# input device
pcm.loopin {
    type dsnoop
    ipc_key 686592
    slave.pcm "hw:Loopback,1,0"
}

# duplex plug device
pcm.loop {
    type plug
    slave {
      pcm {
         type asym
         playback.pcm "loopout"
         capture.pcm "loopin"
      }
    }
}

This seems to be working and records audio, for example when playing
something on Youtube the audio output goes to the loop device (default
audio output) and I can capture it (not sure how it exactly works,
I tested both 44.1kHz and 48 Khz)

arecord -f cd -D loop | aplay -f cd -D hw:0,0
arecord -f dat -D loop | aplay -f dat -D hw:0,0

But when I tried to capture Verizon Java audio player output, it is garbled
and the length does not seem to match. I suspect it might be mono at 8 kHz
and I tried different things, changing the frequency and formats,
but nothing helped.

Do you have any idea what is wrong here and how to record the messages?
Is the problem in ALSA configuration? Or possibly kernel issue? (I am using
3.4.88). Any ideas would be very welcome.

Best Answer

Interesting question, a long time ago I was thinking about simple recording of digital audio and video, possible via some virtual audio and video drivers, but never got there.

I used your configuration file and had exactly same problem as you described. (I removed OSS compatibility drivers from ALSA to be sure, tested different kernels - did not seem to matter, and used Debian Wheezy)

$ alsaplayer -d front audio.mp3

$ mplayer -vo null -ao alsa:device=front video.mp4
AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)

$ mplayer -ao alsa:device=front audio.mp3
AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)

the above commands all play OK to speakers

$ arecord -f cd -D loop | aplay -f cd -D front
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

now recording from loop and playing to front

$ alsaplayer audio.mp3
$ alsaplayer -d loop audio.mp3

$ mplayer -vo null video.mp4
$ mplayer -vo null -ao alsa:device=loop video.mp4
AO: [alsa] 48000Hz 2ch s16le (2 bytes per sample)

$ mplayer -ao alsa:device=loop audio.mp3
AO: [alsa] 48000Hz 2ch floatle (4 bytes per sample)

all sending audio to loop and playing to speakers OK

$ mplayer audio.mp3
AO: [alsa] 48000Hz 2ch floatle (4 bytes per sample)

but here the sound is broken - very distorted!!! Just playing to default device. Playback specified via loop worked!

After trying various changes I tested this modification of asound.conf

pcm.!default {
    type plug
    slave.pcm "loopout"
}

It solved the problem! When the default device is loopout it works. Trying arecord -f cd -D loopin | aplay -f cd -D front did not have any effect. Not sure how the loop works but this was able to capture the audio. Or a bug in ALSA? Are you using Debian? Does it work for you?

Notes to other suggestions to solve the problem:

To dump the network stream: I assume if the application does not want you to save data, the transfer would be encrypted (https ???). In case the player does not check the server certificate how do you capture the data? What is your favorite quick & easy method how to become man in the middle and capture the stream?

Pulseaudio: How do I get it running on Debian Wheezy? The Wiki says it just works. It did not.

/etc/init.d/pulseaudio start
[warn] PulseAudio configured for per-user sessions ... (warning).

How do I troubleshoot what is going on? (Tools, diag?)

Jack: I did not find any simple instructions how to install Jack. It seems quite complex. Does it assume Pulseaudio running? The documentation is confusing. Do you have a link for a nice quickstart (how to install and test to make sure it is working?)

Do you assume that most audio applications (like Fios Voicemail Java player) will be able to play to Pulseaudio or Jack and not send audio to ALSA?

Related Question