基本上我有一个程序,在某些情况下会再现音频文件...我想为特定程序选择音频输出设备,就像我在此菜单中手动执行的操作一样:
Settings > System > Audio > App Volume And Device Preferences
我该怎么做(可能无需安装任何额外的 cmdlet)?
使用 AudioDeviceCmdlets 模块。
打开管理 shell,然后安装:
Install-Module -Name AudioDeviceCmdlets
# accept the "unsafe" powershell gallery
然后创建并运行该函数:
# Usage: set-audio-output-index <n>
function set-audio-output-index {
param ([int]$x)
$AD_X = (Get-AudioDevice -Playback).Index # Save initial device by Index
if ($x -eq $AD_X) {
Write-Host -f DarkRed "`n[ERROR] " -non; Write-Host -f Gray "Device already default!"
Return
} else {
$ids = (Get-AudioDevice -List | where {$_.Type -eq "playback" -AND $_.Default -eq $false } | select -ExpandProperty Index)
if ($x -in $ids) {
try { Set-AudioDevice -Index $x | Out-Null }
catch {
Write-Host -f DarkRed "`n[ERROR] " -non; Write-Host -f DarkYellow "Unknown device error!"
Return
}
} else {
Write-Host -f DarkRed "`n[ERROR] " -non; Write-Host -f DarkYellow "No output device found with that index!"
Write-Host -f DarkYellow "Available indexes are: $ids"
Return
}
}
}
现在列出您的输出设备:
Get-AudioDevice -List
并使用上面的索引设置新的输出设备:
set-audio-output-index <n>