我已经关注了如何录制和播放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
答案 0 :(得分:0)
是的,您已保存了WAV文件,而不是MP3文件。使用LAME.exe之类的东西转换为MP3,或者只使用WaveFileReader而不是Mp3FileReader。在任何情况下,MP3都不支持低采样率,如8kHz,这通常只用于电话。