1
votes

I have this code that uses NAudio to look for all microphones connected on laptop, andwhen I choose one it shows a meter of the sound in a progressbar. when I gather all device, I collect them in a dropdwon list, my issue is that when I choose the one microphone from the list it will not be activated and display the sound on a meter unless I start WINDOWS SOUND RECORDER which seems to activate the mic. how to enable or activate the microphone from the code without starting WINDOWS SOUND RECORDER?

here is the code:

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

            }
        }


    }
}
1

1 Answers

0
votes

I had the same problem try to use the following code :

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