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:
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
{
string outfile = "-b 32 --resample 22.05 -m m \"" + pworkingDir + fileName + "\" \"" + pcopyDir + fileName.Replace(".wav", ".mp3") + "\"";
psi.FileName = @"D:\lame3.99.5\lame.exe";
psi.Arguments = outfile;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
psi.UseShellExecute = false;
p = System.Diagnostics.Process.Start(psi);
if (waitFlag)
{
p.WaitForExit(10000);
p.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
p.Close();
}
}
}
calling from
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);
}
}
Another way is this
OpenFileDialog op = new OpenFileDialog();
SaveFileDialog sf=new SaveFileDialog();
sf.Filter="MP3 File (*.mp3)|*.mp3;";
if (op.ShowDialog() == DialogResult.OK && sf.ShowDialog()==DialogResult.OK)
{
var infile = op.FileName;
var outfile =sf.FileNames ;
string lameArgs = "-b 8 -f -m m ";
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.Arguments = string.Format("{0} {1} {2}",lameArgs,infile,outfile);
p.Start();
p.WaitForExit();
int exitCode = p.ExitCode;
if (exitCode != 0)
MessageBox.Show("File Converted Successfully");
}
But no file are getting generated