2010-05-17 81 views
10

我试图从麦克风(或线路输入)录制音频数据,然后使用C#重新播放它。从C#中的麦克风获取数据#

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

+0

的[管理访问麦克风输入和系统体积(可能重复http://stackoverflow.com/questions/1191613/managed-access-to-microphone-input-and-系统容量) – 2010-05-17 22:53:44

+7

你能告诉我们为什么你不得不讽刺地表明你发现了一个可行的搜索,特别是因为“C#”在许多搜索引擎中是无用的术语? – 2010-05-18 04:29:47

+0

拥有。只要说xD – 2012-06-05 17:36:56

回答

3

参见Console and multithreaded recording and playback

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