我通过在类中使用 Wave 使用 NAudio API 录制声音,但是当我播放录制的字节数组时,它会给出错误“波头已损坏”。你能指出我的解决方案吗?
waveInStream = new WaveIn();
writer = new WaveFileWriter(@"C:\Users\Ali\Desktop\abc.wav", waveInStream.WaveFormat);
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs(waveInStream_DataAvailable);
waveInStream.StartRecording();
void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
{
writer.WriteData(e.Buffer, 0, e.BytesRecorded);
//I want to play e.buffer but it gives me error
}
public void play_it( MemoryStream s)
{
//here i convert recorded byte into stream for playing
using (var wfr = new WaveFileReader(s))
using (WaveChannel32 wc = new WaveChannel32(wfr) { PadWithZeroes = false })
using (var audioOutput = new DirectSoundOut())
{
audioOutput.Init(wc);
audioOutput.Play();
while (audioOutput.PlaybackState != PlaybackState.Stopped)
{
Thread.Sleep(20);
}
audioOutput.Stop();
}
}