Skip to main content
 首页 » 编程设计

c#之使用 C# 程序从 PC 麦克风获取音频

2024年02月20日11webabcd

我需要使用 C# 程序从装有 Windows 7 的 PC 捕获音频。我需要获得 20 khz 之前的所有频率。你知道有没有办法做到这一点?

请您参考如下方法:

只需尝试使用 winmm.dll api 函数即可。这是一个简单的例子。

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

函数签名MSDN: mciSendString function .

命令列表 MSDN: Command Strings .