2010-05-17 46 views
10

Tôi đang cố gắng ghi lại dữ liệu âm thanh từ micrô (hoặc dòng), sau đó phát lại lại bằng C#.Lấy dữ liệu từ micrô trong C#

Bất kỳ đề xuất nào về cách tôi có thể đạt được điều này?

+0

thể trùng lặp của [Managed tiếp cận với đầu vào microphone và khối lượng hệ thống] (http://stackoverflow.com/questions/1191613/managed-access-to-microphone-input-and- hệ thống-khối lượng) –

+7

Bạn có thể cho chúng tôi biết tại sao bạn cảm thấy bắt buộc phải mỉa mai trong việc cho thấy rằng bạn đã tìm thấy một tìm kiếm hoạt động, đặc biệt là vì "C#" là một thuật ngữ vô dụng trong nhiều công cụ tìm kiếm? –

+0

Được sở hữu. Chỉ cần nói xD –

Trả lời

3

Xem 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); 
    } 
} 
Các vấn đề liên quan