我正在使用 ProcessBuilder 从 java 运行 SoX 来修剪 wav 文件。我确信我应该能够运行 SoX,因为在其他 JUnit 测试中,我设法成功运行了以下命令:
sox/sox --version
sox/sox --i -r test/test.wav
sox/sox --i -D test/test.wav
sox/sox --i -b test/test.wav
sox/sox --i -c test/test.wav
但是当我尝试如下修剪文件时:
sox/sox -V3 "/Users/username/workspace/Thesis Corpus Integrator/test/test.wav" -b 16 "/Users/username/workspace/Thesis Corpus Integrator/test/newWaveFile.wav" channels 1 trim 0:00:00.000 =0:00:30.000
它抛出一个IOException
错误:error=2, No such file or directory
。我尝试在终端上运行该命令,它可以正常工作。如果重要的话,我会在 macbook 上通过 eclipse 的 JUnit 测试运行它。
这是我用来在 ProcessBuilder 中构建它的代码:
StringBuilder command = new StringBuilder(soxCommand) // soxCommand resolves to sox/sox, and is used in all the other tests without any problems
if (WavCutter.getMetadata(srcFile.getAbsolutePath(),
MetadataField.SAMPLE_RATE) != 16000) {
command.append(" -V3");
command.append(" -G");
command.append(" \"" + srcFile.getAbsolutePath() + '\"');
command.append(" -b 16");
command.append(" \"" + destFile.getAbsolutePath() + '\"');
command.append(" channels 1");
command.append(" gain -h");
command.append(" rate 16000");
command.append(" trim");
command.append(" " + startTime.toString());
command.append(" " + '=' + endTime.toString());
Process soxProcess = new ProcessBuilder(command.toString())
.start();
我也尝试过同样的事情,但使用了 ArrayList。