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

原文链接: http://www.cnblogs.com/Khan-Sadas/p/11427678.html

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

你可能感兴趣的:(C#获取设备话筒主峰值(实时音频输出分贝量))