0
我使用ProcessBuilder從java運行SoX來修剪wav文件。我相信我應該能夠運行SOX,原因在其他JUnit測試,我設法成功運行下面的命令:使用Java的ProcessBuilder運行SoX
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
。我嘗試在終端上運行該命令,並且它沒有問題。如果它很重要,我在ebook中通過一個MacBook上的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。
您能向我們展示ProcessBuilder代碼嗎?我希望它不能正確處理文件名中的空格。 – bramp
最初,我並沒有用引號包圍文件路徑,但在失敗後,我嘗試添加引號。 – cesar
@ bramp謝謝。你給了我一個關於如何解決它的大提示。這不是文件名,而是它的作用。 – cesar