在C#中从麦克风获取数据

Has*_*rab 11 c# audio microphone

我正在尝试从麦克风(或线路输入)录制音频数据,然后使用C#重播它.

有关如何实现这一目标的任何建议?

Mar*_*ath 14

看一下使用NAudio的开源.NET Voice Recorder项目.有一篇关于Coding4Fun的文章解释了它是如何工作的.


Ale*_*eks 3

请参阅控制台和多线程录制和播放

class Program
{

    static void Main(string[] args)
    {
        rex.Data += new RecorderEx.DataEventHandler(rex_Data);
        rex.Open += new EventHandler(rex_Open);
        rex.Close += new EventHandler(rex_Close);
        rex.Format = pcmFormat;
        rex.StartRecord();
        Console.WriteLine("Please press enter to exit!");
        Console.ReadLine();
        rex.StopRecord();
    }

    static RecorderEx rex = new RecorderEx(true);
    static PlayerEx play = new PlayerEx(true);
    static IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(1, 16, 44100);

    static void rex_Open(object sender, EventArgs e)
    {
        play.OpenPlayer(pcmFormat);
        play.StartPlay();
    }

    static void rex_Close(object sender, EventArgs e)
    {
        play.ClosePlayer();
    }

    static void rex_Data(object sender, DataEventArgs e)
    {
        byte[] data = e.Data;
        play.AddData(data);
    }
}
Run Code Online (Sandbox Code Playgroud)