How to convert any audio format to mp3 using NAudio

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sainathsagar
    New Member
    • Jan 2013
    • 7

    How to convert any audio format to mp3 using NAudio

    Code:
     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 correct me where i went wrong in this code.
  • Willjoe
    Banned
    New Member
    • Jul 2022
    • 12

    #2
    How do I convert audio Format to MP3?
    How to Convert Audio Files to MP3
    Insert the audio CD into your computer's CD drive.
    Click on the arrow below the Rip tab on the Windows Media Player menu.
    Select the option to change the format to MP3.
    Click Rip and the file will be loaded as MP3 [source: Microsoft].


    Regards,
    Will

    Comment

    Working...