C# – Get Audio from PC microphone with a C# program

audiocmicrophone

I need to capture audio from a PC with Windows 7 with a C# program. I need to get all the frequencies until 20 khz. Do you know if there are a way to do it?

Best Answer

Just try to use winmm.dll api function. Here is simple example.

    using System;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace MicrophoneTest
    {
        class Program
        {

            [DllImport("winmm.dll")]
            private static extern int mciSendString(string MciComando, string MciRetorno, int MciRetornoLeng, int CallBack);

            static void Main(string[] args)
            {
                //create Test alias
                mciSendString("open new type waveaudio alias Test", null, 0, 0);

                //start
                mciSendString("record Test", null, 0, 0);

                Thread.Sleep(3000);

                //pause
                mciSendString("pause Test", null, 0, 0);

                //save
                mciSendString("save Test " + "test.wav", null, 0, 0);
                mciSendString("close Test", null, 0, 0);

                //press any key
                Console.ReadKey();
            }
        }
    }

Function signature MSDN: mciSendString function.

List of commands MSDN: Command Strings.