2012-06-05 71 views
1

我需要使用C#程序从带有Windows 7的PC捕获音频。我需要获得所有的频率,直到20 kHz。你知道是否有办法做到这一点?使用C#程序从PC麦克风获取音频

+0

我会开始购买能够“听到”高达20kHz的麦克风,然后谷歌“C#录制音频” – Alex

回答

1

只要尝试使用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