gpt4 book ai didi

c# - Sox 返回一些值但 StandardOutput.ReadToEnd() 返回空

转载 作者:太空宇宙 更新时间:2023-11-03 21:55:44 25 4
gpt4 key购买 nike

try
{
string filename = "E:\\sox-14-4-0\\mysamplevoice.wav";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "E:\\sox-14-4-0\\sox.exe ";
p.StartInfo.Arguments = filename + " -n stat";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
catch(Exception Ex)
{
Console.WriteLine(Ex.Message);
}

输出总是空的。当我在命令提示符下运行 sox 命令时,我会得到如下响应:

E:\sox-14-4-0>sox mysamplevoice.wav -n stat
Samples read: 26640
Length (seconds): 3.330000
Scaled by: 2147483647.0
Maximum amplitude: 0.515625
Minimum amplitude: -0.734375
Midline amplitude: -0.109375
Mean norm: 0.058691
Mean amplitude: 0.000122
RMS amplitude: 0.101146
Maximum delta: 0.550781
Minimum delta: 0.000000
Mean delta: 0.021387
RMS delta: 0.041831
Rough frequency: 526
Volume adjustment: 1.362

在 C# 中运行相同的命令时,我得到相同的结果,但“输出”的值为空。

最佳答案

您确定 sox.exe 写入 STDOUT 而不是 STDERR 吗?

您可以尝试使用 OutputDataReceived 事件读取数据。

string filename = "E:\\sox-14-4-0\\mysamplevoice.wav";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "E:\\sox-14-4-0\\sox.exe ";
p.StartInfo.Arguments = filename + " -n stat";

p.OutputDataReceived += process_OutputDataReceived;
p.ErrorDataReceived += process_ErrorDataReceived;

p.Start();
p.BeginErrorReadLine();
p.BeginOutputReadLine();


void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
string s = e.Data;
}

void process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
string s = e.Data;
}

关于c# - Sox 返回一些值但 StandardOutput.ReadToEnd() 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12385129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com