0
我在課堂上使用Wave錄製了使用NAudio API的聲音,但是當我播放錄製的字節數組時,它給出了錯誤「波頭已損壞」。 你能否請我指出解決方案。NAudio錄製的字節數組波形標頭損壞
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();
}
}
謝謝,幫助我很多 – Ali 2013-03-19 07:34:11