我正在使用 Java 中的 ProcessBuilder 运行 SoX,它将 WAV 文件修剪为 30 秒长的 WAV 文件。
SoX 正在运行,因为我可以成功修剪文件的前 30 秒并保存为新文件,但它停在那里,但它仍在运行。
这是命令生成的代码:
command.add (soxCommand);
if (SoxWrapper.getMetadata (srcFile, MetadataField.SAMPLE_RATE) != 16000) {
command.add ("-V3");
command.add ("-G");
command.add (FilenameUtils.normalize (srcFile.getAbsolutePath ()));
command.add ("-b 16");
command.add (FilenameUtils.normalize (destFile.getAbsolutePath ()));
command.add ("channels");
command.add ("1");
command.add ("rate");
command.add ("16000");
command.add ("trim");
command.add (startTime.toString ());
command.add ('=' + endTime.toString ());
} else {
command.add ("-V3");
command.add (FilenameUtils.normalize (srcFile.getAbsolutePath ()));
command.add ("-b 16");
command.add (FilenameUtils.normalize (destFile.getAbsolutePath ()));
command.add ("trim");
command.add (startTime.toString ());
command.add ('=' + endTime.toString ());
}
这是进程创建的代码:
private static Process createProcess (List<String> command) {
ProcessBuilder soxProcessBuilder = new ProcessBuilder (command);
soxProcessBuilder.redirectErrorStream (true);
Process soxProcess = null;
try {
soxProcess = soxProcessBuilder.start ();
int soxreturn = soxProcess.waitFor ();
soxLogger.info ("SoX returned: " + soxreturn);
} catch (IOException t) {
logger.error ("SoX Process failed", t);
} catch (InterruptedException e) {
logger.error ("Failed to wait for SoX to finish", e);
}
return soxProcess;
}