C#获取设备话筒主峰值(实时音频输出分贝量)

1.引用类库NAudio,Git地址 https://github.com/naudio/NAudiogit

2.添加以下代码和引用:github

public float GetVoicePeakValue()
{
var enumerator = new MMDeviceEnumerator();
var CaptureDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToArray();
var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console);
var selectedDevice = CaptureDevices.FirstOrDefault(c => c.ID == defaultDevice.ID);
return selectedDevice.AudioMeterInformation.MasterPeakValue;
}code

相关文章
相关标签/搜索