我遵循了有关如何录制和播放 MP3 的不同主题,但在尝试播放我录制的 MP3 文件时,我仍然总是遇到此异常:
mp3filereader does not support sample rate changes
所以这是我要记录的代码:
waveInStream = new WaveIn();
waveInStream.WaveFormat = new WaveFormat(8000, 16, 1);
writer = new WaveFileWriter(outputfileName, waveInStream.WaveFormat);
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
waveInStream.StartRecording();
waveInStream_DataAvailable 是:
void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
{
writer.Write(e.Buffer, 0, e.BytesRecorded);
}
此时录制的文件应该是PCM未压缩的吧?
在播放之前是否需要将其转码为 MP3?
我的播放代码:
WaveChannel32 inputStream;
WaveStream mp3Reader = new Mp3FileReader(fileName); var pStream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(mp3Reader);
inputStream = new WaveChannel32(mp3Reader);
volumeStream = inputStream;
return volumeStream;
每次调用时都会发生异常,Mp3FileReader
并说如下:
Got a frame at sample rate 44100, in a MP3 sample rate 32000
Mp3FileReader does not support sample rate change