Sound Switcher IndicatorSound Switcher Indicator for Ubuntu

By Dmitry Kann 3 min read
This post  in Russian

I couldn’t take it anymore so I created an audio input/output switcher indicator for Ubuntu.

Image

I’ve been trying to find one just as long as I’ve been using Ubuntu and Unity. It had to be an application indicator that would allow for easy switching of the default sound device. There’s plenty of indicators for Unity already, including some pretty useless stuff, and yet no such a basic thing as sound selector available. Therefore one has to start the Sound applet, wait for it to open, choose the right tab and then select the required input or output device. Most often I used it to redirect audio to my Logitech Bluetooth adapter to listen to music via decent speakers.

At last I decided to write such an indicator myself, so I began to read up on app indicators. It turned out creating a Unity indicator is pretty simple, especially with Python. So I made the very first prototype that used the pacmd command to switch output device (sink) and parsed its output to build device list.

It was a hundred line Python script, and it worked, but had a number of flaws. Device list wouldn’t update automatically, and changing the default defice elsewhere didn’t reflect in indicator’s menu either. Furthermore, it depended on pulseaudio-utils.

All that wasn’t very neat so I started learning the somewhat intricate PulseAudio API. Among other things, PulseAudio is almost completely asynchronous by design, so its events are best handled by a separate thread.

After a long string of experiments with Python’s non-immaculate multithreading implementation (I’d mention GIL to start with), I made the application run smoothly. The menu consists of three sections: input devices (ordered by name), output devices (same) and static items.

The icon was designed in Inkscape:

Image

Any changes in PulseAudio daemon state are immediately reflected in menu’s contents, even if it’s open.

The next task was to build a .deb package for Ubuntu so that the application could be easily installed by anyone. Now, that was a real challenge. I am certain it’s easier to create a multithreaded app indicator in Python than package it and publish at Launchpad. There’s a lot of information on the subject available, but I couldn’t help the feeling they’re always explaining how to fly a plane without first describing how to take off (if you’re interested in the subject, I’d strongly recommend starting with the Distutils guide, which makes clear a lot of things. The next step could be stdeb).

The application is built and available:

In order to install it:

sudo add-apt-repository ppa:yktooo/ppa
sudo apt-get update
sudo apt-get install indicator-sound-switcher

Bug reports are welcome at GitHub bugtracker. ■

Subscribe to blog updates:

Comments

Share: