Wednesday, October 20, 2021

Where does Sound Come From

 Clip below make a sense to watch only if your computer (or other internet device) is NOT mute.

I have three audio devices connected to my Windows  10 desktop:
  1. Headphone as part of headset (Mpow 323 model) plugged into USB.
  2. Stereo pair of standalone external speakers plugged into  3.5 socket.
  3. Speakers integrated into Philips Monitor (HDMI).
I often need to switch between speakers and headset (seldom use Philips speaker).  Obviously it could be done by Windows dedicated sound menu, but I feel that its usage is not convenient. I want two things:
  • Ability to switch between sound output devices just by mouse click. 
  • Ability to hear proper audio feedback to be sure that selected device is up and and running.
After some investigation I have achieved the desired outcome with the help of two utilities which I   took here:  Software is documented well enough with chm help files.  (I am not affiliated with the owner of that site, just happy user of his software. Software is free). 
First utility is executable "SoundVolumeView.exe". It is a GUI which allows to explore  available sound devices and controls them (enable, disabler, set default etc...).

On the screenshot above you can see selected devices, which are subjects of this project. Right click of the mouse while on selected device invokes context menu. On that menu you can choose "Property" element and see  pop-up window.  This window among other information has the field "Command-Line Friendly ID". 

This is good: in addition to explore devices and control them with GUI I can achieve desired outcome by the command line or batch file. 

So to set headset as default output device one invokes next command:
 C:\NirSoft\SoundVolumeView.exe /SetDefault "Mpow 323\Device\Speaker\Render" 1

But that solves only first item in my list. What about audio feedback. Here I use another utility within the same package: "nircmd.exe". Among many commands it has command "speak". Command line to invoke it I use in this form:

C:\NirSoft\nircmd.exe speak file  "C:\NirSoft\headphone.xml"

And here is a context of "headphone.xml" file:

<voice required="Gender=Male">
	Headphone Activated

As you can see it has only one xml attribute <voice> which control gender of the speaker and text to speak.

Similar files created for other two devices.   Here is "speakers.xml":

<voice required="Gender=Female">
	Speakers Activated

It took me some time to find out the third distinctive voice. Eventually I have settled with attribute <lang> with decimal code. The result was funny voice with some specific accent. So here is "philips.xml" file. 

<lang langid="419">
   Philips Activated

After that I made three batch files:

C:\NirSoft\SoundVolumeView.exe /SetDefault "Mpow 323\Device\Speaker\Render" 1
C:\NirSoft\nircmd.exe speak file  "C:\NirSoft\headphone.xml"

C:\NirSoft\SoundVolumeView.exe /SetDefault "Realtek High Definition Audio\Device\Speakers\Render" 1
C:\NirSoft\nircmd.exe speak file "C:\NirSoft\speakers.xml"

C:\NirSoft\SoundVolumeView.exe /SetDefault "NVIDIA High Definition Audio\Device\PHL 252B9\Render" 1
C:\NirSoft\nircmd.exe speak file "C:\NirSoft\philips.xml"

The last step was to create three desktop shortcuts. I put here just one as example. Shortcut  doesn't invoke batch file directly. Instead it calls batch file with the help of "nircmd.exe". You see that it is called with  command "exec", parameter "hide", and name of the batch file. Parameter "hide" guarantees that console window attached to the command line  process becomes hidden and does not distract the user.

No comments:

Post a Comment