LameMP3FileWriter: Unsupported encoding format MuLaw Parameter name: format

回眸只為那壹抹淺笑 提交于 2019-12-25 03:33:24

问题


Trying to convert a 12 year old wav file to mp3,

8K, 8bit, Mono-channel, Mu-Law format, WAV

and I am getting this error in LameMP3FileWriter line:

LameMP3FileWriter: Unsupported encoding format MuLaw Parameter name: format

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;
    }
}

Could anyone show me how to convert this type of wav to mp3?


回答1:


You need to get your file converted to a more standard format before converting it to MP3. Use WaveFormatConversionStream.CreatePcmStream to go from mu law to linear PCM 16 bit. Then the next challenge will be that LAME probably won't like 8kHz audio, so upsample to at least 16kHz, possibly higher with either another WaveFormatConversionStream or MediaFoundationResampler.




回答2:


I ended up using SOX and LAME exes instead to convert to usable wav file and then convert to mp3. It turned out to be an easy and effective solution. Here's the main part of the code:

            // 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 command line utility: URL: http://sox.sourceforge.net/

Version: SoX 14.4.2 released on 02/22/2015

LAME compiled command line utility: URL: http://www.rarewares.org/mp3-lame-bundle.php

Version: LAME 3.99.5 released on 05/22/2014, Bundle compiled with Intel Compiler 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. 


来源:https://stackoverflow.com/questions/28888685/lamemp3filewriter-unsupported-encoding-format-mulaw-parameter-name-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!