TroubleChute Logo
TIPS

Quickly Switch Audio Devices on Windows


Published: Nov 23, 2023
Last Edit: Feb 24, 2024
Windows Tips Audio
1,442 Words, 7 Minutes.

Watch the video:


Timestamps:
0:00 - Intro
1:08 - Install PowerShell Audio Plugin
2:17 - List audio devices
2:56 - Find device names
3:27 - Set default audio device with ONE COMMAND
3:50 - Creating audio device changing script
5:30 - Quick swapping Audio Device settings
6:00 - Change volume automatically

Quickly Switch Audio In/Output Devices on Windows

Using PCVR (Such as an Oculus Quest) is great, but having to switch both the audio input and output devices for both normal and communication takes more than a few clicks - and on my Windows 11 setup it can take some time while Windows thinks about it’s actions before continuing.

Why not automate it? Well, there’s a few ways. The first I’d recommend, and the second is if you hate PowerShell for some reason…

TL;DR

Step 1: Install

Powershell
1
Install-Module -Name AudioDeviceCmdlets

Step 2: Get device list

Powershell
1
Get-AudioDevice -List | ForEach-Object { "- $($_.Name)" } | Sort-Object

Step 3: Change audio devices

Use the following command, swapping <NAME> for your device(s) name. If multiple devices share the text you enter (input or output) all will be set as default.

Powershell
1
(Get-AudioDevice -list | Where-Object Name -like ("*<NAME>*") | Set-AudioDevice).Name

So, in my case I can swap to my Oculus using

Powershell
1
(Get-AudioDevice -list | Where-Object Name -like ("*Oculus Virtual Audio Device*") | Set-AudioDevice).Name

Then back to normal audio using:

Powershell
1
(Get-AudioDevice -list | Where-Object Name -like ("*Analogue 1/2*") | Set-AudioDevice).Name

Heck, change the volume of your current output device with:

Powershell
1
Set-AudioDevice -PlaybackVolume 50

Step 4: Time saved

While not “simpler” than opening settings and changing things, it should save you some time after it’s set up.

If you’d like to learn more about everything above, scroll down and see the rest of this admittedly bloated article in full to learn more about how this works.

Switch Audio Devices with PowerShell

By default this isn’t something built-in, so we need to install a Module. This is incredibly simple to do, and basically just contains more PowerShell code, but simplified into a few commands.

Install AudioDeviceCmdlets from an Administrative PowerShell window using the following command [The link above takes you to the project’s GitHub page]:

Powershell
1
Install-Module -Name AudioDeviceCmdlets

Breakdown of commands

Now, before we start switching let’s learn about what commands we have access to:

Full documentation can be found on the project’s GitHub Page. Here’s a few snippets of the commands we can use:

Powershell
1
2
3
4
5
# Get audio devices
Get-AudioDevice -<List/PlaybackCommunication/Playback/RecordingCommunication/Recording>

# Set audio devices
Set-AudioDevice	<AudioDevice> <-CommunicationOnly/-DefaultOnly>

There are tons of commands from controlling and viewing Volume to the Mute state as well. See the GitHub Page linked above.

What does this all mean?

Running a command like: Get-AudioDevice -PlaybackCommunication or Get-AudioDevice -List can result in something like:

1
2
3
4
5
6
7
Index                : 3
Default              : True
DefaultCommunication : True
Type                 : Playback
Name                 : Analogue 1/2 (5- Audient iD14)
ID                   : {0.0.0.00000000}.{8e032e3b-3728-4213-a055-a8926da8799b}
Device               : CoreAudioApi.MMDevice

Let’s simplify this by getting just what we want. As this is a PowerShell object you can surround it with $( and ), such as: $(Get-AudioDevice -PlaybackCommunication).Name. This command returns:

1
Analogue 1/2 (5- Audient iD14)

Quickly swapping inputs and outputs

Step 1: Get names

To get the names for all your I/O devices, you can run:

Powershell
1
Get-AudioDevice -List | ForEach-Object { "- $($_.Name)" } | Sort-Object

This returns something like:

1
2
3
4
5
6
7
- Analogue 3/4 (5- Audient iD14)
- Analogue 1/2 (5- Audient iD14)
- CABLE Input (VB-Audio Virtual Cable)
- Headphones (Oculus Virtual Audio Device)
- Headset Microphone (Oculus Virtual Audio Device)
- CABLE Output (VB-Audio Virtual Cable)
...

To get your currently default devices you can use:

Powershell

1
Write-Host "Current Outputs:`n$($(Get-AudioDevice -PlaybackCommunication).Name) # Communication`n$($(Get-AudioDevice -Playback).Name) # Playback`n`nCurrent Inputs:`n$($(Get-AudioDevice -RecordingCommunication).Name) # Communication`n$($(Get-AudioDevice -Recording).Name) # Recording"

This should return something like:

1
2
3
4
5
6
7
# Current Outputs:
Analogue 1/2 (5- Audient iD14) # Communication
Analogue 1/2 (5- Audient iD14) # Playback

# Current Inputs:
Analogue 1/2 (5- Audient iD14) # Communication
Analogue 1/2 (5- Audient iD14) # Recording

Step 2: Change Audio Devices

Collect the names of the devices we’ll be using, either by setting defaults yourself and running the last command, or just collecting them from the list.

I am specifically interested in swapping between these groups:

1
2
3
4
5
6
7
Normal audio:
IN  - Analogue 1/2 (5- Audient iD14)
OUT - Analogue 1/2 (5- Audient iD14)

PCVR audio:
IN  - Headphones (Oculus Virtual Audio Device)
OUT - Headset Microphone (Oculus Virtual Audio Device)

While you can change audio devices with specific device IDs, these can change over time and the only thing that shouldn’t change should be the device name. That’s why when changing devices we’ll search the list for that device’s name, but you could get and use the IDs instead.


Step 3: Create Device Change Script/Commands

To change audio devices use one of these commands:

Powershell

1
2
3
Set-AudioDevice <AudioDevice>
Set-AudioDevice <AudioDevice> -CommunicationOnly
Set-AudioDevice <AudioDevice> -DefaultOnly

To change devices we can search the list for the devices names. Including *s in the quotes searches for anything that includes the text between.

Use the command in the following way, where <NAME> is the device’s name(s) you want to search for.

Powershell
1
(Get-AudioDevice -list | Where-Object Name -like ("*<NAME>*") | Set-AudioDevice).Name

So for me, I can swap to my Oculus using:

Powershell
1
(Get-AudioDevice -list | Where-Object Name -like ("*Oculus Virtual Audio Device*") | Set-AudioDevice).Name

Then back to normal audio using:

Powershell
1
(Get-AudioDevice -list | Where-Object Name -like ("*Analogue 1/2*") | Set-AudioDevice).Name

Notice that the commands only have one line to change both input and output devices, that’s because I’ve used a bit of text that’s included in both the input and output device, but you may not be so lucky. In that case use 2 seperate lines such as:

Powershell
1
2
(Get-AudioDevice -list | Where-Object Name -like ("*<SPEAKERS>*") | Set-AudioDevice).Name
(Get-AudioDevice -list | Where-Object Name -like ("*<MICROPHONE>*") | Set-AudioDevice).Name

I am lucky because my normal audio has the same name for input and output (Analogue 1/2 (5- Audient iD14)), so I search for Analogue 1/2, and my PCVR device shares Oculus Virtual Audio Device between it’s input (Headset Microphone (Oculus Virtual Audio Device)) and output (Headphones (Oculus Virtual Audio Device)).

Simply create your own groups as above, and save them into .ps1 files. These are PowerShell Script files. You should be able to Double-Click on them, such as running Oculus Sound.ps1 and Desktop Sound.ps1.

Make sure you save them as .ps1 and not .ps1.txt. Enable show Hidden File Extensions, and save them with a plain text editor such as Notepad. Make sure when saving with Notepad, for example, All files (*.*) - This allows you to save with file extensions other than .txt.


Step 4: Using the sound device changing scripts

It’s simple: Just run the ps1 files with PowerShell.

If double-clicking opens them with something like Notepad, then use the Open With dialog to select PowerShell. It should be located somewhere in Windows such as C:\Windows\System32\WindowsPowerShell\powershell.

Now multiple audio devices should change with a simple double-click saving you minutes, and over the course of however often you change audio devices probably hours of your time - especially if the Sound dialog is slow for you on Windows.

This may not seem worth the effort in the short-term, but in the long term it’s nice to quickly swap audio devices without even thinking about it!


Alternate method

Don’t like PowerShell? This StackExchange article is what inspired this post and the accompanying video.

The most upvoted post involves downloading a Nirsoft tool known as Nircmd. With this downloaded, and placed in a PATH folder (a directory listed in your system’s %PATH% variable) – or in the same folder you’re using CMD/PowerShell from, you can change audio devices in a similar fashion using the following commands:

1
2
3
nircmd setdefaultsounddevice "Speakers" 1
# or
nircmd setdefaultsounddevice "Headphones" 1

1 means default device, and 2 means default communication device.

While this may seem simpler, I would say running one line to install and another line to swap devices is easier, as it doesn’t involve anything about knowing what PATH is, but that’s just me.

You can, however, install using Choco or WinGet using one of the following commands:

1
2
3
4
5
6
7
8
winget install nircmd
# or
choco install nircmd

# Alternatively search either using one of the following commands:
winget search nircmd
# or
choco search nircmd

Feel free to use whichever method you prefer.

TroubleChute © Wesley Pyburn (TroubleChute)
Support Me Privacy Policy Cookies Policy Terms of Service Change privacy settings Contact