2014-04-08 57 views

回答

1

要獲得幅度,你將不得不處理Microphone類的BufferReady事件:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/gg442302(v=vs.105).aspx

設置代碼

Microphone microphone = Microphone.Default; 
microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady); 
microphone.BufferDuration = TimeSpan.FromMilliseconds(1000); 

byte[] buffer; 
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)]; 

microphone.Start(); 

事件處理程序塊

void microphone_BufferReady(object sender, EventArgs e) 
{ 

    microphone.GetData(buffer); 


    for(int i = 0; i< buffer.Length; i+=2) 
    { 
     //The value of sample is the amplitude of the signal 
     short sample = BitConverter.ToInt16(new byte[2] { buffer[i], buffer[i + 1] }, 0); 
    } 
} 
+0

感謝您的答覆。它在「microphone.BufferReady + = new EventHandler (microphone_BufferReady);」中拋出「System.NullReferenceException」。你能解決這個問題嗎? – user3218743

+0

我可以修復它。只需在WMAppManifest.xml中啓用ID_CAP_MICROPHONE即可。 – user3218743

+0

添加調度員工作 – user3218743