2012-06-05 69 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