如何使用Naudio在ProgressBar中显示麦克风级别

时间:2017-11-14 22:27:47

标签: c# naudio

我正在尝试使用Naudio捕获ProgressBar中的麦克风/输入电平。我能够在我的组合框中获得设备列表,但是声级计没有显示在ProgressBar中(有点像VU /峰值计)。以下是代码:

using System;
using System.Linq;
using System.Windows.Forms;
using NAudio.CoreAudioApi;


namespace WindowsFormsApp5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var deviceEnumerator = new MMDeviceEnumerator();
            var devices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active);
            if (devices != null)
            {
                comboBox1.Items.AddRange(devices.ToArray());
            }
        }
        void Mytimer_Tick(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem != null)
            {
                var device = (MMDevice)comboBox1.SelectedItem;
               progressBar1.Value = (int)Math.Round(device.AudioMeterInformation.MasterPeakValue * 100);
            }
        }
    }    
}

0 个答案:

没有答案