Controlling ALSA’s output

I use “Twinkle” on my Ubuntu PC, for receiving and making VoIP calls.

After testing Linphone, Wengo, and several others, Twinkle seemed to be the one which seemed to be pretty robust.

I like to have music going when I’m not on the phone, but that proves to be quiet the distraction during a voice call, as well, I ran into problems with having the headphones in, and the speakers turned on at the same time (microphone feedback, for example).

Twinkle has the ability to run scripts on call incoming, call answered, call hang up, call missed, etc.  I put that to good use and created some scripts.

callincoming.sh

#!/bin/bash
/usr/bin/amixer set “Front” 100%
/usr/bin/amixer set “Side” 100%
/usr/bin/amixer set “Master” 75%

That script would turn the main speakers up, and the headphones (which I’ve got into the “side” speaker plug in the back), to 100% – so we can hear the ringing if I’m away from the keyboard.

The Master is also turned up to 75% which is where I find it’s ‘loud enough’ to be heard, but not deafening that the kids would get significantly disturbed if they were having a day time sleep.

The script can be expanded to kill the radio, or rhythmbox. I’d love to be able to stop the music streaming online, but I can’t get application control that the Sound Preferences offers just yet.

callanswered.sh

#!/bin/bash
/usr/bin/amixer set “Front” 0%
/usr/bin/amixer set “Side” 100%
/usr/bin/amixer set “Mic” 48%
/usr/bin/amixer set “Mic Boost” 0%
/usr/bin/amixer set “Front Mic” 0%
/usr/bin/amixer set “Master” 60%
/usr/bin/amixer set “Input Source”,0 “Mic”

What this script does is turn the “Front” speakers (my primary ones) off – so the caller / callee doesn’t hear themselves. Turns the headphones up to 100% (it’s actually got a control on the cord to the PC, that I turn it down and leave it). Turns the mic to 48% – this is a good level that doesn’t give the kids in the background into the call, but allows good level of voice, without echo.

Mic Boost – this was awful, picture a poorly mixed MP3, like 64k, turned right up, with emphasis on bass, it ‘crackles’ and ‘distorts’ heavily.  So, I kill that because I believe amixer resets after a reboot and setting it down is desired.

Front Mic is not used, but gets turned up to 100% for some reason, so I leave that off! Finally, I set the Input Source to “Mic” to ensure it doesn’t capture from the radio card for example.

callend.sh

#!/bin/bash
/usr/bin/amixer set “Front” 100%
/usr/bin/amixer set “Mic” 0%
/usr/bin/amixer set “Side” 0%
/usr/bin/amixer set “Front Mic” 0%
/usr/bin/amixer set “Mic Boost” 0%
/usr/bin/amixer set “Master” 75%

This script resets the music back to a usable level, kills the mic to stop that awful feedback through the speakers. As the others, can be expanded to start the radio, or rhythmbox for example.

This ability is also useful if we later want to expand the sound to other sound sources – like to the TV for MP3s in the lounge room!

After the scripts are created, chmod them a+x so that they are executable.

Adding the scripts to Twinkle was as easy as opening User Settings, going to “Scripts” and pointing “Outgoing Call, Outgoing Call Answered, Incoming Call Answered” to “callanswered.sh”. Set Incoming Call to “callincoming.sh”, and the call ended options and call failed options to callended.sh.

This entry was posted in Linux, Random, VoIP. Bookmark the permalink.

Leave a Reply

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