使用Naudio C#启用麦克风



我有此代码,该代码使用naudio在笔记本电脑上连接的所有麦克风,而当我选择一个麦克风时,它在progressbar中显示了一米的声音。当我收集所有设备时,我将它们收集到Dropdwon列表中,我的问题是,当我从列表中选择一个麦克风时,它不会被激活并在仪表上显示声音,除非我启动Windows Sound Rocorder,否则麦克风如何在不启动Windows Sound Recorder的情况下从代码中启用或激活麦克风?

这是代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio;
using NAudio.CoreAudioApi;
using System.Threading;
using NAudio.Wave;
using NAudio.Mixer;
namespace NaudioVisualizer
{
    public partial class Form1 : Form
    {
        public int a = 1;
        public Form1()
        {
            InitializeComponent();
            MMDeviceEnumerator de = new MMDeviceEnumerator();
            var device = de.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active);
            comboBox1.Items.AddRange(device.ToArray());
        }
       private void timer1_Tick(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem != null)
            {
                var device = (MMDevice)comboBox1.SelectedItem;
                progressBar1.Value = (int)Math.Round(device.AudioMeterInformation.MasterPeakValue * 100);
            }
        }

    }
}

我也有同样的问题尝试使用以下代码:

var waveIn = new WaveIn();
waveIn.StartRecording();

最新更新