Changing sound output with Macro/addon/etc

When I’m playing solo, I have my sound going to my speakers, when I party up I switch to my headset. Each time I switch ‘modes’ I do the “Esc/System/Sound/[pick speakers or headset]/Okay/Esc” dance.

Was wondering if anyone knew a way to set up a button to toggle between two known sound outputs. Guessing that WoW doesn’t expose this via the API, but on the off-chance I’m wrong, I’d love to know how to do it.

I’m reasonably comfortable in writing simple add-ons and macros, so a breadcrumb for either would work.

2 Likes

Couldn’t you just set wow to default device, set the headset as default device. Then while they’re plugged in they’ll be default and otherwise your speakers will be.

1 Like

First you would need to list the devices you have installed and select which ones to use

/run local num = Sound_GameSystem_GetNumOutputDrivers()	for index=0,num-1,1 do print(index, Sound_GameSystem_GetOutputDriverNameByIndex(index)) end

Once you know which two to swap between,

/run local x = tonumber(GetCVar("Sound_OutputDriverIndex")) if x == 0 then SetCVar("Sound_OutputDriverIndex", "3") else SetCVar("Sound_OutputDriverIndex", "0") end AudioOptionsFrame_AudioRestart()

Change the 0 and 3 to your prefered devices.

Or Elvenbane’s approach :slight_smile:

13 Likes

Both (actually several devices, but these are the two for WoW) are plugged in all the time.

Hmm…can’t make two replies.

Fizzlemizz…that was the breadcrumb needed. I think I can make that work. Thx.

[New bit below…]
Got distracted with a few things, so only got around to putting this to good use today. I used the first macro that Fizzlemizz provided to get a list then made the following two macros to do the switching for me. The macro without the find argument chars comes in at 213 chars giving up to 42 chars to do a match and stay under the 255 limit. Just replace the string in the :find with whatever unique bit you get from Fizzlemizz’s macro.

Switch to headset:

/run local n=Sound_GameSystem_GetNumOutputDrivers() for i=0,n-1,1 do if Sound_GameSystem_GetOutputDriverNameByIndex(i):find("(GameDAC Game)")  then SetCVar("Sound_OutputDriverIndex", i) AudioOptionsFrame_AudioRestart() end end

Switch to sound bar:

/run local n=Sound_GameSystem_GetNumOutputDrivers() for i=0,n-1,1 do if Sound_GameSystem_GetOutputDriverNameByIndex(i):find("(S/PDIF)")  then SetCVar("Sound_OutputDriverIndex", i) AudioOptionsFrame_AudioRestart() end end

My sound can get funky (the headset is good, but the driver has a habit of dropping the game channel) so I’m not certain when I invoke the macro that I will have a match for “(GameDAC Game)” and the indices seem to change. Looking for a name match seems to do the trick.

Thanks again!

5 Likes

This will let you cycle through all the available devices with a single macro, avoiding issues that might occur when the order they’re listed changes, or new devices are added/become unavailable. It outputs the name of the device selected to the default chat window.

I’m assuming ‘System Default’ is always listed first, so ‘m=1’ skips it. Changing that to ‘m=0’ will include ‘System Default’ in the devices cycled if you need that.

/run local c="Sound_OutputDriverIndex"; local n,m=Sound_GameSystem_GetNumOutputDrivers(),GetCVar(c); if tonumber(m)>=n-1 then m=1 else m=m+1 end; print(Sound_GameSystem_GetOutputDriverNameByIndex(m)); SetCVar(c,m); AudioOptionsFrame_AudioRestart()

If software is functioning correctly then when the default device is changed in Windows, then the software should update the device it’s using to match.

I’ve made desktop shortcuts to batch files that run a program called NIRCMD that can change the default device, without having to open Windows’ settings, but that has no effect on WoW because it only checks the device on launch, then ignores any changes.

11 Likes

This is one of the top google hits when searching for this topic and the solution offered by Fizzlemizz still works great.

I wanted to offer a simpler option that works for me, since I use the speaker icon in Windows to switch my audio device between speakers or headphones.

This changes the “system default” and a simple refresh is all that’s needed:

Update: This no longer works with Dragonflight! (see below)

/run AudioOptionsFrame_AudioRestart()

This method works with Dragonflight:

/run Sound_GameSystem_RestartSoundSystem()
18 Likes

Nice that was what I was looking for. Setting system default doesn’t automatically change when I change windows default audio.

This is PRECICELY what I was looking for. Thank you very much Kleoni for this note. I have the computer speakers, sonos, headset, and also headphones. in windows it’s quite simple to switch them, but then I have to come back to wow and click default again. This solves the problem beautifully! You’re the best! thanks!

Just looked this up and so happy to find this solution. Thank you, works amazing. 1 button can easily switch between headset and speakers.

Updating this comment for Dragonflight

1 Like

It works! Thank you so much!