我有Mp3音频文件与相同的音乐,这是以不同的采样率和比特深度编码。
例如:
我希望使用Mp3将所有这些Mp3文件转换为Wav格式(格式)。
在转换到Wav格式之前,我想确保所有Mp3文件必须转换成一个标准的采样速率和位深度:192 Kbps,48 KHz。
在最终将Mp3转换为Wav格式之前,我是否需要将Mp3重新采样到所需的Mp3速率和比特深度?或者可以在转换为Wav格式时完成?
感谢您能提供一个示例代码。
谢谢。
发布于 2015-02-21 15:39:45
是的,在将所有.mp3文件转换为.wav格式之前,您需要将它们重新采样到所需的速率。这是因为转换方法NAudio.Wave.WaveFileWriter.CreateWaveFile(string filename, IWaveProvider sourceProvider)没有与速率或频率相对应的参数。方法签名(取自GitHub中的代码)如下所示:
/// <summary>
/// Creates a Wave file by reading all the data from a WaveProvider
/// BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished,
/// or the Wave File will grow indefinitely.
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="sourceProvider">The source WaveProvider</param>
public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
{因此,正如您所看到的,您不能在转换为.wav时传递速率或频率。你可以这样做:
int outRate = 48000;
var inFile = @"test.mp3";
var outFile = @"test resampled MF.wav";
using (var reader = new Mp3FileReader(inFile))
{
var outFormat = new WaveFormat(outRate, reader.WaveFormat.Channels);
using (var resampler = new MediaFoundationResampler(reader, outFormat))
{
// resampler.ResamplerQuality = 48;
WaveFileWriter.CreateWaveFile(outFile, resampler);
}
}https://stackoverflow.com/questions/28647205
复制相似问题