471,049 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

How to convert any audio format to mp3 using NAudio

sainathsagar
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
1 8780
Willjoe
12 Byte
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
1 Week Ago #2

Post your reply

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

Similar topics

10 posts views Thread by bonnie.tangyn | last post: by
4 posts views Thread by thomasc1020 | last post: by
6 posts views Thread by BeMe | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.