Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have downloaded Lame.exe and i am havinng wav files i need to convert them to mp3 how can i do it .My wav files are resultant of WasapiLoopbackCapture();

What I have tried:

C#
public void mciConvertWavMP3(string fileName, bool waitFlag, string pworkingDir, string pcopyDir)
       {
           DirectoryInfo newDir1 = new DirectoryInfo(pcopyDir);
           System.Diagnostics.Process p = new System.Diagnostics.Process();
           string mpfile = fileName.ToLower().Replace(".wav", ".mp3");

           if (newDir1.GetFiles(mpfile).Length == 0)
           {
               System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
               try
               {
                   //Response.Write("Conversion of " + pworkingDir + fileName + " is in progress ...");
                   string outfile = "-b 32 --resample 22.05 -m m \"" + pworkingDir + fileName + "\" \"" + pcopyDir + fileName.Replace(".wav", ".mp3") + "\"";
                   // string outfile = "-V \"" + pworkingDir + fileName + "\" \"" + pcopyDir + fileName.Replace(".wav", ".mp3") + "\"";
                   psi.FileName = @"D:\lame3.99.5\lame.exe";//"\"" + root_dir + "lame.exe" + "\"";
                   psi.Arguments = outfile;
                   psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                   psi.UseShellExecute = false;// Minimized;
                   p = System.Diagnostics.Process.Start(psi);
                   if (waitFlag)
                   {
                       // Response.Write("Converted to " + pcopyDir + fileName.Replace(".wav", ".mp3") + "successfully");
                       //successmsg.Text = "Successfully convert WAV file to MP3 file.";
                       p.WaitForExit(10000);
                       p.Close();
                   }
               }
               catch (Exception ex)
               {
                   //         Response.Write(ex.Message);
                   MessageBox.Show(ex.ToString());
               }
               finally
               {
                   p.Close();

               }
           }
       }

calling from
C#
private void btnMethod5_Click(object sender, EventArgs e)
       {
           OpenFileDialog op = new OpenFileDialog();
           if (op.ShowDialog() == DialogResult.OK)
           {

               pworkingDir= Directory.GetCurrentDirectory();
               string fileName = "allInOne.wav";
               mciConvertWavMP3(fileName, true, pworkingDir, pcopyDirA);
              // mciConvertWavMP3(fileName, true);
           }
       }

Another way is this
C#
OpenFileDialog op = new OpenFileDialog();
SaveFileDialog sf=new SaveFileDialog();
sf.Filter="MP3 File (*.mp3)|*.mp3;";
if (op.ShowDialog() == DialogResult.OK && sf.ShowDialog()==DialogResult.OK)
{
    //mp3towavecodec(op.FileName,sf.FileName);
     var infile = op.FileName;
    var outfile =sf.FileNames ;

    string lameArgs = "-b 8 -f -m m ";//"-V2";
    var lamepath = @"C:\Users\sohaily\Downloads\lame3.99.5 (1)\lame.exe";
    Process p = new Process();
    p.StartInfo = new ProcessStartInfo();
    p.StartInfo.FileName = lamepath;
  //  p.StartInfo.UseShellExecute = false;
   // p.StartInfo.Arguments = String.Format("-b 128 \"{0}\" \"{1}\"", infile, outfile);
    p.StartInfo.Arguments = string.Format("{0} {1} {2}",lameArgs,infile,outfile);
    //p.StartInfo.CreateNoWindow = true;
    p.Start();
    p.WaitForExit();
    int exitCode = p.ExitCode;
    if (exitCode != 0)
        MessageBox.Show("File Converted Successfully");
}

But no file are getting generated
Posted
Updated 4-Nov-16 21:28pm
v3

1 solution

 
Share this answer
 
Comments
Member 12094473 5-Nov-16 5:45am    
Thanks a lot it worked out for me ..
Member 12094473 7-Nov-16 8:53am    
How to Deal with large size of files like for example a wave file of arround 1GB
Mehdi Gholam 7-Nov-16 8:58am    
What is the problem?
Member 12094473 8-Nov-16 7:17am    
No it is resolved now thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900