Search code examples
c#.netmp3pixelsenselame

How to use lame.exe in my application?


I capture audio files in the wave format in my Microsoft Surface application. Now for file size reasons, I'd like to convert the wave file into a mp3 file. I read in the Internet that a good possibility to do that is using lame.

But how can I call this exe file from my application? and how can I include it into my application?


Solution

  • Use Process class to call an external application:

    string lameEXE = @"C:\path_of_lame\lame.exe";
    string lameArgs = "-V2";
    
    string wavFile = @"C:\my_wavs\input.wav";
    string mp3File = @"C:\my_mp3s\output.mp3";
    
    Process process = new Process();
    process.StartInfo = new ProcessStartInfo();
    process.StartInfo.FileName = lameEXE;
    process.StartInfo.Arguments = string.Format(
        "{0} {1} {2}",
        lameArgs,
        wavFile,
        mp3File);
    
    process.Start();
    process.WaitForExit();
    
    int exitCode = process.ExitCode;