2
public void AudioConvert()
{    
    FileStream fs = new FileStream(InputFileName, FileMode.Open, FileAccess.Read);            
    NAudio.Wave.WaveFormat format = new NAudio.Wave.WaveFormat();
    NAudio.Wave.WaveStream rawStream = new RawSourceWaveStream(fs, format);
    NAudio.Wave.WaveStream wsDATA = WaveFormatConversionStream.CreatePcmStream(rawStream);
    WaveStream wsstream = wst.CanConvertPcmToMp3(2, 44100);
    .....
}

// Here is the class 
public class WaveFormatConversionStreamTests
{
    public WaveStream CanConvertPcmToMp3(int channels,int sampleRate)
    {           
        WaveStream ws = CanCreateConversionStream(
            new WaveFormat(sampleRate, 16, channels),
            new Mp3WaveFormat(sampleRate, channels, 0, 128000/8));
        return ws;
    }
}

Here, i am trying to convert any audio format to mp3 but my code is throwing exception like "ACMNotPossible" at ConvertPCMToMp3 function call. I am using NAudio 1.6 version dll. Right now i am working on windows 7. Please tell me where i went wrong in this code.

Kinetic
  • 2,640
  • 17
  • 35
sainath sagar
  • 499
  • 2
  • 10
  • 28

1 Answers1

1

WaveFormatConversionStream is a wrapper around the Windows ACM APIs, so you can only use it to make MP3s if you have an ACM MP3 encoder installed. Windows does not ship with one of these. The easiest way to make MP3s is simply to use LAME.exe. I explain how to do this in C# in this article.

Also, if you are using the alpha of NAudio 1.7 and are on Windows 8 then you might be able to use the MP3 encoder which seems to come with Windows 8 as a Media Foundation Transform. Use the MediaFoundationEncoder (the NAudio WPF demo shows how to do this).

Mark Heath
  • 48,273
  • 29
  • 137
  • 194
  • Hi @Mark Heath, I am following your article but couldn't understand how to convert any format audio to mp3 using ACM. I want to do this task only with NAudio. – sainath sagar Aug 05 '13 at 12:20