0
我想從Kinect錄製音頻。我正在使用NAudio
庫。如何用NAudio錄製來自Kinect的音頻
我發現這個代碼:
private void button2_Click(object sender, EventArgs e) //Play Button
{
fileName = "lastReplay.wav";
FileStream FS_Write = File.OpenWrite("lastReplay.wav");
FS_Write.Close();
int deviceNumber = sourceList.SelectedItems[0].Index;
sourceStream = new NAudio.Wave.WaveIn();
sourceStream.DeviceNumber = deviceNumber;
sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100,
NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
NAudio.Wave.WaveInProvider waveIn = new
NAudio.Wave.WaveInProvider(sourceStream);
sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>
(sourceStream_DataAvailable);
waveWriter = new NAudio.Wave.WaveFileWriter(fileName, sourceStream.WaveFormat);
sourceStream.StartRecording();
}
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
{
if (waveWriter == null) return;
waveWriter.Write(e.Buffer, 0, e.BytesRecorded);
waveWriter.Flush();
}
當我開始Kinect的音頻通道需要啓動,所以我用這個:
Stream audioStream = this.sensor.AudioSource.Start();
我怎樣才能改變button2_click
方法接受語音串流?
因爲button2_click作爲一個事件,它必須有你提供的方法簽名。所以除了重寫按鈕類實現click事件的自定義事件 –
好了,但我可以使用audioStream和全局變量,所以我不能使用額外的參數來傳遞這個事件,所以我可以使用它 – bircastri