LameMP3FileWriter:不支持的编码格式MuLaw参数名称:格式

时间:2015-03-05 22:06:19

标签: wav naudio lame

尝试将12年前的wav文件转换为mp3,

8K,8bit,单声道,Mu-Law格式,WAV

我在LameMP3FileWriter行中收到此错误:

LameMP3FileWriter:不支持的编码格式MuLaw参数名称:格式

static void Main(string[] args)
{
    string wavFilePath = @"C:\temp\Message.wav";
    string mp3FilePath = @"C:\temp\Message.mp3";
    if (!File.Exists(mp3FilePath))
    {
        byte[] bytearrwav = File.ReadAllBytes(wavFilePath);
        byte[] bytearrmp3 = ConvertWavToMp3(bytearrwav);
        File.WriteAllBytes(mp3FilePath, bytearrmp3);
    }
}

public static byte[] ConvertWavToMp3(byte[] wavFile)
{
    try
    {
        using (var retMs = new MemoryStream())
        using (var ms = new MemoryStream(wavFile))
        using (var rdr = new WaveFileReader(ms))
        using (var wtr = new LameMP3FileWriter(retMs, rdr.WaveFormat, 128))
        {
            rdr.CopyTo(wtr);
            return retMs.ToArray();
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        return null;
    }
}

有人能告诉我如何将这种类型的wav转换为mp3吗?

2 个答案:

答案 0 :(得分:3)

在将文件转换为MP3之前,您需要将文件转换为更标准的格式。使用WaveFormatConversionStream.CreatePcmStream从mu law变为线性PCM 16位。然后下一个挑战是LAME可能不会喜欢8kHz音频,所以上采样到至少16kHz,可能更高的另一个WaveFormatConversionStreamMediaFoundationResampler

答案 1 :(得分:1)

我最终使用SOX和LAME exes转换为可用的wav文件,然后转换为mp3。事实证明这是一个简单有效的解决方案。这是代码的主要部分:

            // create temp file
            tempFile = this.FolderFromFile(inputFileAndPath) + "tempFile.wav";

            // Part 1:  Convert mu-Law WAV to floating point WAV
            // perform work with no display of console window
            // Example:  SOX.EXE  MachMsg1.wav  -e floating-point  MsgFloatingPoint.wav
            using (this)
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process
                {
                    StartInfo = new System.Diagnostics.ProcessStartInfo
                    {
                        FileName = soxFileAndPath,
                        Arguments = inputFileAndPath + "  " + "-e floating-point" + "  " + tempFile,
                        UseShellExecute = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true
                    }
                };
                proc.Start();
            }


            // Part 2:  Convert floating point WAV to MP3 using highest quality possible
            // perform work with no display of console window
            // Example:  LAME.EXE  -V4  MsgFloatingPoint.wav  MsgFloatingPoint.mp3
            using (this)
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process
                {
                    StartInfo = new System.Diagnostics.ProcessStartInfo
                    {
                        FileName = lameFileAndPath,
                        Arguments = "-V4" + "  " + tempFile + "  " + outputFileAndPath,
                        UseShellExecute = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true
                    }
                };
                proc.Start();
            }

SOX命令行实用程序: 网址:http://sox.sourceforge.net/

版本:2015年2月22日发布的SoX 14.4.2

LAME编译的命令行实用程序: 网址:http://www.rarewares.org/mp3-lame-bundle.php

版本:LAME 3.99.5于2014年5月22日发布,Bundle使用英特尔编译器14.0.3编译。

  Hydrogenaudio recommended settings
      -- Best quality, "archiving"2 : -b 320 
           CBR 320 is the strongest setting for MP3, with the lowest risk of artifacts. With the exception of a few situations,
           quality is rarely better than the highest VBR profiles described below. 
      -- High quality, HiFi, home or quiet listening : -V0 (avg. 245 kbps) or -V1 (avg. 225 kbps) or -V2 (avg. 190 kbps) or  -V3 (avg. 175 kbps). 
           These settings are considered to produce transparent encoding (transparent = most people can't distinguish the MP3
           from the original in an ABX blind test). Audible differences between these presets exist, but are rare. 
      -- Portable, background noise and low bitrate requirement, small sizes : -V4 (avg. 160 kbps) or -V5 (avg. 130 kbps)
           or -V6 (avg. 115 kbps) -V6 produces an "acceptable" quality, while -V4 should be close to perceptual transparency. 
      -- Very low bitrate, small sizes, eg. for voice, radio, mono encoding : --abr 80 (stereo) or --abr 56 -m m (mono) 
           For very low bitrates, up to 100kbps, ABR is most often the best solution.