By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,828 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

How to convert any audio format to mp3 using NAudio

sainathsagar
P: 7
Expand|Select|Wrap|Line Numbers
  1.  
  2.  public void AudioConvert(){
  3.  
  4.  FileStream fs = new FileStream(InputFileName, FileMode.Open, FileAccess.Read);
  5.  
  6.  NAudio.Wave.WaveFormat format = new NAudio.Wave.WaveFormat();
  7.  
  8.  NAudio.Wave.WaveStream rawStream = new RawSourceWaveStream(fs, format);
  9.  
  10.  NAudio.Wave.WaveStream wsDATA = WaveFormatConversionStream.CreatePcmStream(rawStream);
  11.  
  12.  WaveStream wsstream = wst.CanConvertPcmToMp3(2, 44100);
  13.  
  14.  .....
  15.  }
  16.  
  17. // Here is the class 
  18. public class WaveFormatConversionStreamTests
  19. {
  20.     public WaveStream CanConvertPcmToMp3(int channels,int sampleRate)
  21.     {           
  22.       WaveStream ws = CanCreateConversionStream( new WaveFormat(sampleRate, 
  23.                                                  16, channels),
  24.       new Mp3WaveFormat(sampleRate, channels, 0, 128000/8));
  25.       return ws;
  26.     }
  27. }
  28.  
  29.  
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.
Aug 3 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.