如何在 PowerShell 或命令行中将麦克风音量设置为 100%?

问题描述 投票:0回答:1

我正在尝试使用 PowerShell 或 Windows 11 上的命令行将麦克风音量调整到特定级别(例如 100)。我需要一种可靠的方法,无需第三方应用程序即可以编程方式执行。

我想调整第一个栏“VoiceMeeter Output”:

这是我迄今为止尝试过的:

  1. 将 PowerShell 与 WMI 类结合使用 我尝试使用 WMI 类操作音频设置,但遇到了不存在的类和方法的问题:

    $AudioEndpointDevices = [wmiclass]"ROOT\CIMV2:Win32_PerfRawData_Counters_AudioEndpoint"
    

    这导致了错误:“无法将值转换为 «ROOT\CIMV2:Win32_PerfRawData_Counters_AudioEndpoint» en 类型 « 系统.管理.管理类»。错误:“Non trouvé””,并显示找不到 WMI 类的消息。

  2. 使用 AudioDeviceCmdlet 模块 我使用

    Get-AudioDevice
    成功列出并检索了音频设备,但发现没有像
    Set-AudioDeviceVolume
    这样的可用命令来设置音量:

    Get-AudioDevice -List | Where-Object { $_.Type -eq "Recording" }
    

    此步骤效果很好,但我无法继续设置音量。

考虑到这些挑战,是否有人有一个可行的解决方案,可以使用本机 PowerShell 命令或 Windows 上的其他命令行方法以编程方式设置麦克风音量?如果可能的话,我宁愿避免使用第三方工具,但如果小型实用程序是唯一的解决方案,我愿意使用它们。

windows powershell audio command-line scripting
1个回答
0
投票

好的,谢谢@js2010。

仔细查看 GitHub 上的 AudioDeviceCmdlets 文档后,我意识到我已经非常接近第二种方法的解决方案了。很明显,该任务需要分两步完成:首先,选择音频设备的 ID,然后对其执行所需的操作。这是将麦克风音量设置为 100% 的完整 powershell 脚本:

# Script to set microphone volume to 100% using PowerShell

# Import the necessary module
Import-Module AudioDeviceCmdlets

# Specify the device by its ID
$microphoneId = "{0.0.1.00000000}.{a849033f-716e-4d33-80cc-9c5f49b913ba}"

# Select the specific microphone
Set-AudioDevice -Id $microphoneId

# Set the microphone volume to 100%
Set-AudioDevice -RecordingCommunicationVolume 100

# Confirmation output
Write-Output "The microphone volume has been set to 100%."
© www.soinside.com 2019 - 2024. All rights reserved.