Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

wav - LameMP3FileWriter: Unsupported encoding format MuLaw Parameter name: format

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:	empMessage.wav";
    string mp3FilePath = @"C:	empMessage.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...