Recording Function

talKKonnect Audio Recording Function…

talKKonnect framework has an audio recording function. With this function you can record the incoming Mumble channel traffic, sound from microphone input, or both at the same time. To accomplish this, talKKonnect is working together with SoX sound processing program.

SoX is an amazing sound processing package that talKKonnect is calling for audio recording.

You can save the recorded audio files on your Single Board Computer SD card, but preferably you should mount a more durable external media device and use it for recording, in order to minimize wear and tear on a highly imperfect SD card technology.

Assuming you mastered the fundamentals of working with talKKonnect framework so far, here is what you need to do to add audio recording function to talKKonnect.

1. Install SoX Package

apt-get update

apt-get install sox libsox-fmt-mp3 mpg321

2. Load snd-aloop ALSA Loopback Module

In it’s basic configuration talKKonnect is using a very simple ALSA config. Only one program has access to ALSA audio system at one time. ALSA stands for Advanced Linux Sound Architecture (ALSA). It is a basic sound system in Linux. You could also use PulseAudio to have multiple programs access audio hardware simultaneously, if needed. Before working with PulseAudio, you will need to dedicate some time to building a learning curve for working with more complex sound system. talKKonnect may support working with PulseAudio, as it keeps developing. At this time, we recommend working with more simple ALSA sound system in talKKonnect, for less “moving parts” and lower complexity.

2.1 Load Loopback Kernel Module

Check if snd-aloop kernel module is installed and loading correctly.

modprobe snd-aloop

Check if snd_aloop is listed as loaded.

lsmod | grep snd_aloop

Module snd_aloop should be reported as loaded, among other modules.

snd_aloop 24576 1

snd_pcm 102400 2 snd_usb_audio,snd_aloop

snd 73728 12 snd_hwdep,snd_usb_audio,snd_timer,snd_rawmidi,snd_usbmidi_lib,snd_seq_device,snd_aloop,snd_pcm

In order to start snd-aloop module on reboot, add a line to /etc/modules file.

echo 'snd-aloop' >> /etc/modules

Another option is to load snd_aloop from within /etc/rc.local or create a configuration file in /etc/modprobe.d .

3. Create ALSA Config File

We are going to need to use ALSA plugins to create virtual audio devices to give both talKKonnect and SoX access to ALSA sound system. talKKonnect will access the default audio device directly and SoX will record audio from a loopback. There will also be a “snoop” device created, so that SoX can use a microphone simultaneously with talKKonnect and “dmix” device to allow playing of audio, if needed from other programs (to play the recorded audio files).

Copy to your home directory .asoundrc config file, with all the appropriate plug devices defined or the config fine tuned for your application.

File can look like this,

# dmix multi ALSA config for talKKonnect
# Requires snd-aloop module loaded
# record from hw:Loopback,1,0 as loopback output
# capture to device dsnoop or plug:dsnoop
# Other programs play to device plug:dmixer

ctl.!default { # default control; alsamixer will use this
type hw
card 1
}

pcm.usbsound { # the usual usb sound card
type hw
card 1
}

# software mixer for sound card
pcm.dmixer {
type dmix
ipc_key 1024
ipc_perm 0666 # allow other users
slave.pcm "usbsound"
slave {
period_time 0
period_size 1024
buffer_size 4096
rate 48000
channels 2 # must match bindings
}

bindings {
0 0
1 1
}
}

# software mixer for loopback device
pcm.dmixerloop {
type dmix
ipc_key 2048
ipc_perm 0666 # allow other users
slave.pcm "hw:Loopback,0,0"
slave {
period_time 0
period_size 1024
buffer_size 4096
rate 48000
channels 2 # must match bindings
}

bindings {
0 0
1 1
}
}



pcm.!default {
type asym
playback.pcm "out"
capture.pcm "dsnooper"
}

# Multi, splitting between usb soundcard and loopback
pcm.out {
type plug
slave.pcm {
type multi
slaves {
a { channels 2 pcm "dmixer" }
b { channels 2 pcm "dmixerloop" }
}

bindings {
0 { slave a channel 0 }
1 { slave a channel 1 }
2 { slave b channel 0 }
3 { slave b channel 1 }
}
}

ttable [
[ 1 0 1 0 ] # left -> a.left, b.left
[ 0 1 0 1 ] # right -> a.right, b.right
]
}

How does it work? talKKonnect will use a default sound device. SoX will record Mumble traffic from hw:Loopback,1,0 output. dsnoop or plug:dsnooper ALSA plug will be used to capture microphone input. Any other programs can play audio to a device plug:dmixer .

Instead of creating a local .asoundrc file you could also define ALSA plugs in /usr/share/alsa/alsa.conf file instead.

To find more information on ALSA and it’s many possibilities, you can check:

ALSA unofficial Wiki or ALSA Project site wiki .

If you are already used to working with Jack daemon and PulseAudio, you can easily make audio recording work through them, instead of using ALSA loopback and plugins.

4. Audio Recording Options

Specify your audio recording options in talkkonnect.xml, a configuration file for talKKonnect.

audiorecordfunction enabled
true | false
Enable audio recording function
recordonstart
true | false
Start audio recording immediately on talkkonnect launch
recordmode
traffic | ambient | combo
Record Mumble traffic (traffic), Ambient sounds from Mic (ambient), or both (combo)
recordtimeout
(seconds) Record incoming traffic timeout (seconds). “0” for continous recording
recordfromoutput
Example:

hw:Loopback,1,0
Name of the audio output device. It could be Loopback, monitor, ALSA plug, pulse, source from Jack. Depends on the exact sound system config
recordfrominput
Example:

plug:dsnooper
Device name for audio input (Microphone). Depends on the exact sound config, dsnoop, plug:dsnooper, plughw:1,0, etc
recordmictimeout
(seconds) When to stop secording from microphone (seconds). “0” for Continous
recordsoft
sox
External audio software: /usr/bin/sox, arecord, ffmpeg, other
recordsavepath
path to recording directory. Example:

/avrec/audio
Where to save the recorded audio files
recordarchivepath
path to archive directory. Example:

/avrec/archive/audio
Where to archive the recorded audio files
recordprofile
standard |

vox-trimsilence |

vox-trimsilence-

chunks | chunks
Recording mode. Just record (standard); With Vox and trimming silence (vox-trimsilence); With Vox, trimming silence and file chunks (vox-trimsilence-chunks); With file chunks (chunks).
recordfileformat
mp3 | wav
Recording format (wav, mp3, ogg, etc)
recordchunksize
(seconds) Size of audio file chunks in seconds

5. Audio Recording Config Example

Audio recording segment of talKKonnect configuration file talkkonnect.xml can look like this.

<audiorecordfunction enabled="true">
<recordonstart>true</recordonstart>
<recordmode>traffic</recordmode>
<recordtimeout>0</recordtimeout>
<recordfromoutput>hw:Loopback,1,0</recordfromoutput>
<recordfrominput>plug:dsnooper</recordfrominput>
<recordmictimeout>0</recordmictimeout>
<recordsoft>sox</recordsoft>
<recordsavepath>/avrec/audio</recordsavepath>
<recordarchivepath>/avrec/archive/audio</recordarchivepath>
<recordprofile>standard</recordprofile>
<recordfileformat>mp3</recordfileformat>
<recordchunksize></recordchunksize>
</audiorecordfunction>


How does it work?

In this example, recording of Mumble traffic will start immediately upon talKKonnect launch. Recording will be continuous, with no time out. SoX program does the recording. Audio files will be saved to /avrec/audio folder. On new audio recording start, any old audio files, if any were previously recorded, will be archived to /avrec/archive/audio folder.

A USB stick or other external media can be mounted, in order to minimize wear and tear on SD card. If USB stick is identified as /dev/sda in the system, format it with ext3 or ext4 file system

mkfs.ext4 /dev/sda

Optionally, format USB stick with FAT32 or NTFS if you want to read the files later on a Windows computer.

Then mount it,

mkdir /avrec

mount /dev/sda /avrec

“Standard” recording mode means – just record without any additional SoX options like voice activation, trimming the silence or breaking the recording to audio chunks. Audio format will be mp3.

To save disk space, useful option can be recording with voice activation and silence trimming.

<recordprofile>vox-trimsilence</recordprofile>

For better file management, recordings can also be broken to “chunks”. For voice activated recording, silence trimming and breaking file to chunks select an appropriate SoX recording mode.

<recordprofile>vox-trimsilence-chunks</recordprofile>

Chunk size is defined in seconds. For 10 minute chunks,

<recordchunksize>600</recordchunksize>

Note: If using a “combo” recording mode where SoX is mixing the recording from Loopback (Mumble traffic) and dsnoop (microphone) to the same file, an audio sampling rate for OpenAl and ALSA needs to be identical. If sampling rate for recording device in ALSA is set to 48000 Hz, then sampling rate in

/etc/openal/alsoft.conf

should be set to the same value,

frequency = 48000

in order to prevent potential rate conversion problems.

If you want to play the recorded mp3 files, you can use mpg321. But specify that you want to play to plug:dmixer device.

mpg321 --audiodevice plug:dmixer /avrec/audio/<filename>.mp3

6. Audio Recording Keyboard Shortcuts

talKKonnect keyboard shortcuts for recording (if not starting automatically) are:

Ctrl-I => Traffic Recording

Ctrl-J => Ambient (Mic) Recording

Ctrl-K => Combo Recording (Traffic and Mic)

Leave a Reply

Your email address will not be published. Required fields are marked *