如何在我的应用程序中使用 lame.exe?

发布于 2024-10-09 17:39:01 字数 217 浏览 10 评论 0原文

我在 Microsoft Surface 应用程序中捕获波形格式的音频文件。现在由于文件大小的原因,我想将波形文件转换为 mp3 文件。我在互联网上读到,一个很好的可能性是使用 lame

但是我如何从我的应用程序中调用这个 exe 文件呢?以及如何将其纳入我的申请中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

噩梦成真你也成魔 2024-10-16 17:39:01

使用 Process 类调用外部应用程序:

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;

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;
暮色兮凉城 2024-10-16 17:39:01

您可以使用 System.Diagnostics.Process 类和相关类从 .NET 调用可执行文件 - 请参阅 此处 获取文档。

Lame 有相当强大的命令行参数,可以在此处找到。您可以使用 ProcessStartInfo 将命令行参数传递给进程。参数 属性。

You can call an executable from .NET by using the System.Diagnostics.Process class and related classes - see here for the documentation.

Lame has pretty robust command line arguments, which can be found here. You can pass command line arguments to the Process using the ProcessStartInfo.Arguments property.

空名 2024-10-16 17:39:01
public void mciConvertWavMP3(string fileName, bool waitFlag)
{
    //maxLen is in ms (1000 = 1 second)
    string outfile= "-b 32 --resample 22.05 -m m \"" + pworkingDir+fileName + "\" \"" + pworkingDir + fileName.Replace(".wav",".mp3") + "\"";
    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
    psi.FileName = "\"" + pworkingDir + "lame.exe" + "\"";
    psi.Arguments = outfile;
    //psi.WorkingDirectory = pworkingDir;
    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);

    if (waitFlag)
    {
        p.WaitForExit();
        // wait for exit of called application
    }
}

上面的代码取自这里< /a>.

根据使用情况,您可以合并 Process.StartInfo 对象,控制 ShellExecute 等属性,并将应用程序的任何输出重定向到(例如)日志文件或 UI 组件。

要将 exe 与您的项目捆绑在一起,请从 stackoverflow 中查看此问题。就我个人而言,我会采纳第一个建议:

有几种方法可以
完成这个。首先,你应该添加
program.exe 添加到项目中。你会
通过右键单击该项目来执行此操作
在 Visual Studio 中,然后选择“添加”>“
现有项目...选择program.exe,
它会出现在项目中。
查看其属性,可以设置
将“复制到输出目录”改为“复制
始终”,它将出现在您的
旁边的输出目录
应用程序。

如果您坚持上述方法,则相对引用lame.exe(例如“....\Tools\Lame.exe”)。

最后,根据官方 lame 网站: RareWares 提供了多个编译的 LAME 版本,包括具有以下功能的修改版本特殊功能。

public void mciConvertWavMP3(string fileName, bool waitFlag)
{
    //maxLen is in ms (1000 = 1 second)
    string outfile= "-b 32 --resample 22.05 -m m \"" + pworkingDir+fileName + "\" \"" + pworkingDir + fileName.Replace(".wav",".mp3") + "\"";
    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
    psi.FileName = "\"" + pworkingDir + "lame.exe" + "\"";
    psi.Arguments = outfile;
    //psi.WorkingDirectory = pworkingDir;
    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);

    if (waitFlag)
    {
        p.WaitForExit();
        // wait for exit of called application
    }
}

Above code taken from here .

Depending on the usage, you can incorporate a Process.StartInfo object, control properties such as ShellExecute and also redirect any output from the application to (say) a log file or UI component.

To bundle the exe with your project, check this question from stackoverflow out. Personally, I'd go with the first suggestions:

There are several ways you could
accomplish this. First, you should add
program.exe to the project. You would
do this by right-clicking the project
in Visual Studio, and selecting Add >
Existing Item... Select program.exe,
and it will appear in the project.
Viewing its properties, you can set
"Copy to Output Directory" to "Copy
Always", and it will appear in your
output directory beside your
application.

If you stick to the above method, then reference lame.exe relatively ('....\Tools\Lame.exe' for example).

Finally, according to the official lame site : RareWares offers several compiled LAME versions, including modified versions featuring special functionality.

听你说爱我 2024-10-16 17:39:01

LAME 有一个 DLL 版本,如果您找不到使用它的 VB 或 C# 示例,我会感到惊讶。检查此讨论线程:http://www.eggheadcafe.com /software/aspnet/31294459/-lameencdll-and-vbnet.aspx

There is a DLL version of LAME, I would be surprised if you can't find a VB or C# example using it. Check this discussion thread: http://www.eggheadcafe.com/software/aspnet/31294459/-lameencdll-and-vbnet.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文