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

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

2.添加如下代码和引用:

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;
}

原文地址:https://www.cnblogs.com/Khan-Sadas/p/11427678.html