c#项目中Sox.exe的使用
Use of Sox.exe in c# project
我自己做了一个概念验证来测试这个管理音频的工具files.My目的是改变采样率。我的第一个示例运行良好!
public class Test
{
public void SoxMethod()
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\Program Files (x86)\sox-14-4-2\sox.exe";
startInfo.Arguments = "\"C:\Program Files (x86)\sox-14-4-2\input.wav\" -r 16000 output.wav";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.WorkingDirectory= "C:\Program Files (x86)\sox-14-4-2";
using (Process soxProc = Process.Start(startInfo))
{
soxProc.WaitForExit();
}
}
}
但是当我想在我的 bin 文件夹中添加这个工具时却出现异常:目录名称无效
public void SoxMethod()
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "bin/sox-14-4-2/sox.exe";
startInfo.Arguments = "bin/sox-14-4-2/input.wav -r 16000 output.wav";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.WorkingDirectory= "bin/sox-14-4-2";
using (Process soxProc = Process.Start(startInfo))
{
soxProc.WaitForExit();
}
}
也许它很明显,但我不知道我做错了什么
您的工作目录设置错误。请改用 AppDomain.CurrentDomain.BaseDirectory
。这将使进程从 bin
文件夹开始。然后,将您的文件和参数替换为 relative 到 working directory(因此删除路径的 bin
部分)。
public void SoxMethod()
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "sox-14-4-2/sox.exe";
startInfo.Arguments = "sox-14-4-2/input.wav -r 16000 output.wav";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
using (Process soxProc = Process.Start(startInfo))
{
soxProc.WaitForExit();
}
}
我自己做了一个概念验证来测试这个管理音频的工具files.My目的是改变采样率。我的第一个示例运行良好!
public class Test
{
public void SoxMethod()
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\Program Files (x86)\sox-14-4-2\sox.exe";
startInfo.Arguments = "\"C:\Program Files (x86)\sox-14-4-2\input.wav\" -r 16000 output.wav";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.WorkingDirectory= "C:\Program Files (x86)\sox-14-4-2";
using (Process soxProc = Process.Start(startInfo))
{
soxProc.WaitForExit();
}
}
}
但是当我想在我的 bin 文件夹中添加这个工具时却出现异常:目录名称无效
public void SoxMethod()
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "bin/sox-14-4-2/sox.exe";
startInfo.Arguments = "bin/sox-14-4-2/input.wav -r 16000 output.wav";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.WorkingDirectory= "bin/sox-14-4-2";
using (Process soxProc = Process.Start(startInfo))
{
soxProc.WaitForExit();
}
}
也许它很明显,但我不知道我做错了什么
您的工作目录设置错误。请改用 AppDomain.CurrentDomain.BaseDirectory
。这将使进程从 bin
文件夹开始。然后,将您的文件和参数替换为 relative 到 working directory(因此删除路径的 bin
部分)。
public void SoxMethod()
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "sox-14-4-2/sox.exe";
startInfo.Arguments = "sox-14-4-2/input.wav -r 16000 output.wav";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
using (Process soxProc = Process.Start(startInfo))
{
soxProc.WaitForExit();
}
}