Skip to content

Instantly share code, notes, and snippets.

@teknogeek
Last active November 10, 2022 15:24
Show Gist options
  • Save teknogeek/cd7b416e531fdd338827d19d58723422 to your computer and use it in GitHub Desktop.
Save teknogeek/cd7b416e531fdd338827d19d58723422 to your computer and use it in GitHub Desktop.
Switch audio device between Voicemod and USB Line In
# Requires: Install-Module -Name AudioDeviceCmdlets -Force -Verbose
$targetDevice = $args[0].ToLower()
$targetDeviceID = $null
if ($targetDevice -eq 'usb') {
$targetDeviceID = (Get-AudioDevice -List | Where-Object { $_.Type -eq 'Recording' -and $_.Name -match 'Line \(\d+- USB AUDIO CODEC\)' }).ID
} elseif ($targetDevice -eq 'voicemod') {
$targetDeviceID = (Get-AudioDevice -List | Where-Object { $_.Type -eq 'Recording' -and $_.Name -eq 'Microphone (Voicemod Virtual Audio Device (WDM))' }).ID
} else {
throw 'Invalid target type'
}
if ((Get-AudioDevice -Recording).ID -ne $targetDeviceID) {
Write-Host ('Attempting to set audio device for {0}' -f $targetDevice)
try {
Get-AudioDevice -ID $targetDeviceID | Set-AudioDevice -Verbose
} catch {
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('Unable to find target audio device by ID for {0}' -f $targetDevice)
}
} else {
Write-Host 'Recording device already set, skipping'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment