0
我們可以使用waveViever繪製波形,同時記錄?n音訊疊加的波形,而
private NAudio.Wave.WaveIn wi = null;
int waveInDevices = NAudio.Wave.WaveIn.DeviceCount;
WaveFileWriter waveWriter = null;
SaveFileDialog save;
private void button2_Click(object sender, EventArgs e)
{
save = new SaveFileDialog();
save.Filter = "Wave File (*.wav)|*.wav;";
if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
int deviceNumber = 0;
wi = new WaveIn();
wi.DeviceNumber = deviceNumber;
wi.WaveFormat = new WaveFormat(44100, WaveIn.GetCapabilities(deviceNumber).Channels);
wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);
waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, wi.WaveFormat);
wi.StartRecording();
timer1.Start();
}
private void wi_DataAvailable(object sender, WaveInEventArgs e)
{
if (waveWriter == null) return;
waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded);
waveWriter.Flush();
}
private void timer1_Tick(object sender, EventArgs e)
{
waveViewer1.WaveStream = new WaveFileReader(save.Filename);
}
我使用的代碼語句來記錄文件,你想讀文件中waveViewer.However定時器和情節波形的每一個週期的時間間隔它提供了一個錯誤「的文件是由另一個進程使用」。無論如何要這樣做。我應該使用WaveFileReader(Stream streamInput)的第一個重載嗎?如果是,請您舉例說明第一次超載。