How do I manage multiple audio playback devices on Windows Vista/7?

33

22

I've got speakers (audio in) and headphones (USB headset with it's own soundcard) connected to my desktop computer. Under Windows 7, I can right-click the Audio Mixer and select Playback Devices and toggle between my these devices.

Is there an easier way, perhaps a keyboard shortcut, that would make it easier to toggle? I'm working in an shared space were sometimes I want headphones to avoid annoying other people, but at other times speakers are OK. I want to be able to toggle quickly. In an ideal world, the solution to my question would work in Vista too.

Brian Lyttle

Posted 2009-08-14T22:22:13.857

Reputation: 1 011

Answers

19

The solution to all your nagging Windows automation problems: AutoIt!

Put this AutoIt and compile it

;-----Configuration-----
;The title of the sound config window.
Dim $ConfigWindowTitle = "Sound"
;-----End of configuration----

Dim $ItemNumber = 1
If $CmdLine[0] >= 1 Then ;If we have a parameter...
    $ItemNumber = $CmdLine[1] ;...we should press the button the specified number of times.
EndIf

Run("control mmsys.cpl") ;Run the sound control applet and hide it.

WinWaitActive($ConfigWindowTitle) ;Wait for it to be active before sending keystrokes.

Send("{TAB}{TAB}{TAB}{TAB}") ;Put the focus on the list

For $i = 1 to $ItemNumber Step 1
    Send("{DOWN}")
Next

Send("!s") ;Press Alt + S to set the selected device as the default.
WinClose($ConfigWindowTitle)

Now create a shortcut, and in the Target put the path to the compiled executable. For an argument, put the number of the sound device in the list that you want to switch to. (to switch to the top item in the list, put 1, the second item in the list, put 2, etc). If you want a keyboard shortcut, use the Shortcut Key field in the shortcut's properties window.

I'd been looking for something to do what you wanted to do, and found that there's no programmatic way that you can switch audio devices in Vista/7. It's just not something that Microsoft decided that programmers need to do, so I make this script to automate the process. It's not the best since it pops up the window in order to change the device (necessary), but it makes it possible to create shortcuts to change the output device for your sound.

Dan Walker

Posted 2009-08-14T22:22:13.857

Reputation: 8 869

2This is perhaps the most useful answer I've yet to find on this whole site! Thanks again for this.... – JL. – 2010-02-09T16:24:04.460

Very awesome, works great. – WerkkreW – 2010-02-15T09:37:11.667

9

Default Audio Changer is currently the best solution, in my opinion.

It uses undocumented system calls instead of simulating keyboard presses, which means you can use it in fullscreen applications without worry.

cptloop

Posted 2009-08-14T22:22:13.857

Reputation: 335

Great idea, but not only did it not work, now my headset isn't detected at all when plugged in. :( – Nick Spreitzer – 2012-02-03T20:29:19.430

2Highly recommended! 10x better than a AutoIt script. Should be the accepted answer, really. – Otiel – 2012-06-27T18:16:02.127

2

Setup files are here: http://sourceforge.net/projects/defaultaudiocha/files/ Wow this is probably the cleanest playback devices switch solution I've ever seen!! +1

– Geo – 2013-02-19T17:22:59.860

4

@Dan Walker Nice solution, but not perfect ;)

This script uses the existence of a file to actually perform a toggle, so you can use the same shortcut to switch between playback devices. It's just a simple edit:

;-----Configuration-----
;The title of the sound config window.
Dim $ConfigWindowTitle = "Sound"
;-----End of configuration----

Dim $ItemNumber = 1 ; The first itme in the audio list

If FileExists ("a") Then; Use the existence of a file to know if we should toggle
    FileDelete("a")
    $ItemNumber = 3 ; The audio playback device you want to toggle to
Else
    FileOpen("a", 1)
    FileClose("a")
EndIf

Run("control mmsys.cpl") ;Run the sound control applet and hide it.

WinWaitActive($ConfigWindowTitle) ;Wait for it to be active before sending keystrokes.

Send("{TAB}{TAB}{TAB}{TAB}") ;Put the focus on the list

For $i = 1 to $ItemNumber Step 1
    Send("{DOWN}")
Next

Send("!s") ;Press Alt + S to set the selected device as the default.
WinClose($ConfigWindowTitle)

Andy Ray

Posted 2009-08-14T22:22:13.857

Reputation: 280

Nice, I like the toggling – Chaulky – 2011-03-22T02:15:56.343

3

Googled this for a while and the only thing that did the trick for me is a script from AutoHotKey, the only wish I have is to have this done in the background.. Here is the script:

Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlClick,&Set Default
ControlClick,OK

You can change it to meet your needs

fakts

Posted 2009-08-14T22:22:13.857

Reputation:

This worked for me, but I had to use SendInput {Down} instead of ControlSend,SysListView321,{Down}. I also had to change the number of {Downs} to match my audio devices. – Iain – 2011-10-02T19:37:17.207

3

fakt's solution works like a charm. Here a little script for autohotkey that selects the first audio device as default when you press "F4" and the second when pressing "F3". This version works with all Windows Versions. Tested using Win 7 64.

F3::
Run, mmsys.cpl
WinWaitActive,Sound
ControlSend,SysListView321,{Down}
ControlSend,SysListView321,{Down}
Sleep, 50
ControlClick,Button2
ControlClick,OK
return

F4::
Run, mmsys.cpl
WinWaitActive,Sound
ControlSend,SysListView321,{Down}
Sleep, 50
ControlClick,Button2
ControlClick,OK
return

NTyp

Posted 2009-08-14T22:22:13.857

Reputation:

2

@cptloop Default Audio Changer was pretty good, but annoyingly would not set a device as the default communications device after it had been set as the default device.

That lead me to find Audio Switcher, which has several added features:

  • Support for switching recording devices
  • Support for multiple hotkeys
  • Dual switch (swap the default and communications devices)
  • And more!

The only thing I don't like, is that it doesn't allow you to use a single hotkey to toggle between two devices, each needs to be configured with its own hotkey. That said, v2.0 is in development, and promises some feature improvements, as well as plugin support. They have also published the underlying API, so it is possible to create your own tailored solution.

Edit: As per xenolightning/AudioSwitcher_v1#607, the ability to toggle/cycle devices is already implemented in v2.0.

Dave Hughes

Posted 2009-08-14T22:22:13.857

Reputation: 361

0

Another good program to do this is Audio Router. It is a free (GPL) program with 64-bit and 32-bit OS versions. Here's the program's GitHub link:

Audio Router

Here's a simple GIF of how it's used:

enter image description here

user2597747

Posted 2009-08-14T22:22:13.857

Reputation: 261