Depending on the situation, I use either my speakers or my headset for audio output. Given that my headset is an USB headset it behaves as its own audio device.
Currently I switch between audio output devices by clicking on the speaker icon in the upper right tray, where I select Sound settings, goes to the Output tab and there choses the device I want.
What I wonder is if there might be some easier/quicker way to switch back and forth to my USB headset? Perhaps a dedicated tray icon, a key mapping, or so?
I am running Ubuntu 10.04, with the default Gnome desktop.
In order to change the default audio output device from the command line, you can use the
pacmd
Pulse Audio command-line utility.I found the need to do similarly today, wanting to switch between headphones and speakers, both plugged into separate audio cards. Here's the shell script I wrote to do so:
Notes:
pacmd
utility lists. If you have more than two audio devices and want to swap to a different one, you'll need to replace the logic on line 7 with some conditionals.Well, you can install
pavucontrol
, it shows apps with sound device selection on the first tab, it'll save you some effort. But what you really want I think is to mark you USB headset as default device, then every time you plug it in all sound will be redirected to it, and when you plug it out - it'll be back to speakers. Effortless, really.Of course switching devices by using the Applet is also working fine. But the cool thing about writing a script, is that it is super fast. I put mine for example on the keyboard shortcut alt+s. thus when I want to switch from headphones to speakers, I only need to press alt+s.
Anyway. Andrew said:
That's what I did. I share it, in case someone has troubles with it:
What I did differently is a) find the active sink in a for loop. And b) switch to the next sink by increase the index by 1. Then I modulo the result by the number of sinks. That assures that e.g. when having 3 sinks, (2+1)%3=0. Thus from sink index 2 we would switch to sink index 0.
In this way the switch allows to move upwards through the available sinks.
The question is quite old but my answer may still be useful for GNOME 2 users. I used PulseAudio Mixer Applet for the exact problem described here. You can change input and output devices right in the panel menu. It's the most convenient way I found.
To cycle through your list of sound devices, use the following script:
All credit goes to tsvetan from the Ubuntu forum.
Thanks for the scripts! I added a part for input (microphone) as well in case anyone wants to use it:
I was looking for a way to do this to switch between the internal speakers on my laptop and an apple airport base station which is plugged into my stereo. I decided to assign hotkeys to switch. I wanted the audio preferences window to pop up for a second to give a visual confirmation of the switch and used wmctrl to close the window afterwards.
(I used ctrl+F8 and ctrl+F9 as the hotkeys since the Fn function of these keys on my laptop is to increase and decrease the volume so it seemed obvious to have the ctrl functions change the audio output.)
I used the following 2 (almost identical) scripts:
The first changes to the apple base station (which I assigned to ctrl+F9) and the second one switches back to internal speakers (ctrl+F8). This assumes that these are the only 2 output devices installed.
I built upon Andrews script to make it use notify-osd to announce what it just did. Edit the lines with the names after your needs.
I had the same problem and wrote a small indicator applet for the Ubuntu Unity desktop:
https://github.com/lkettenb/sound-output-switcher
http://www.capslockblog.com/images/misc/Screenshot.png
Here is a little script that cycles the audio sinks for currently focused window: https://gist.github.com/rif/01ffb5e3eb45d2e4e6ebb4652b3b19ce
Requires pacmd and xdotool