2012-08-17 153 views
0

我很語音蒸
我嘗試建立一個語音聊天應用我總結初學者:n音訊串流語音聊天C#

  • 我應該使用UPD作爲ProtocolType插座
  • 我應該使用n音訊串流

的發送機制(僞代碼):

private void but_Click(object sender, EventArgs e) 
    { 
     if (sourceList.SelectedItems.Count == 0) return; 
     int deviceNumber = sourceList.SelectedItems[0].Index; 

     NAudio.Wave.WaveIn sourceStream = new NAudio.Wave.WaveIn(); 
     sourceStream.DeviceNumber = deviceNumber; 
     sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels); 

     sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); 
     sourceStream.StartRecording(); 
    } 

    private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) 
    { 
     if (sourceStream== null) return; 

     send_UPD(e.Buffer, e.BytesRecorded);//sending data UPD 
    } 

我想送會成功,接收器將恢復字節

的發送機制(僞代碼)的陣列:

 NAudio.Wave.DirectSoundOut waveOut = new NAudio.Wave.DirectSoundOut(); 
     NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(/*my recived array of byte*/); 
     waveOut.Init(waveIn); 
     waveOut.Play(); 

我的問題
是上述真實,我能在接收器中使用一個字節數組(如何播放它)?

回答

1

接收器應該使用BufferedWaveProvider,它允許您在播放音頻數據時對其進行排隊。