Этот метод util помогает создавать, заглушать и объединять выбранные файлы .wav с помощью команд bash в unix.По какой-то причине, когда я запускаю методы, содержащие список WAV-файлов в списке, конкатенация WAV-файлов появляется только тогда, когда я запускаю один и тот же метод дважды.Таким образом, метод playAudio () выдает мне ошибку:
java.io.FileNotFoundException: temp/combine.wav (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at namesayer.util.PlayAudio$1.call(PlayAudio.java:35)
at namesayer.util.PlayAudio$1.call(PlayAudio.java:30)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
java.io.FileNotFoundException: temp/combine.wav (No such file or
directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at namesayer.util.PlayAudio$1.call(PlayAudio.java:35)
at namesayer.util.PlayAudio$1.call(PlayAudio.java:30)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
Мой класс:
//Input of a string with destination of audio file to play - uses AudioStream and AudioPlayer for .wav files
public class PlayAudio {
private String audio;
private List<String> combineAudio = new ArrayList<>();
private AudioStream audioStream;
public PlayAudio(String audio) {
this.audio = audio;
}
public PlayAudio(List<String> combineAudio) {
this.combineAudio = combineAudio;
audio = "temp/combine.wav";
}
public void playAudio() {
Task task = new Task<Void>() {
@Override
protected Void call() throws Exception {
InputStream in = null;
try {
in = new FileInputStream(audio);
audioStream = new AudioStream(in);
AudioPlayer.player.start(audioStream); // play the audio clip with the audio player class
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
new Thread(task).start();
}
public void playCombinedAudio() {
//Silence noise sections of each audio
for (String audio : combineAudio) {
String silenceAudio = "cd data/names\n" +
"cp " + audio + ".wav ../../temp/" + audio + ".wav\n" +
"cd ../../temp\n" +
"ffmpeg -hide_banner -i " + audio + ".wav -af silenceremove=1:0:-30dB:1:5:-30dB " + audio + "CONCAT.wav\n";
ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", silenceAudio);
try {
processBuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
//Combine audio clips together
FileWriter writer = null;
try {
writer = new FileWriter("temp/combineAudio.txt");
for (String str : combineAudio) {
writer.write("file '" + str + "CONCAT.wav'\n");
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
//Concatenate from txt file
String concatAudio = "cd temp/\n" +
"ffmpeg -f concat -safe 0 -i combineAudio.txt -c copy combine.wav\n";
ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", concatAudio);
try {
processBuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
playAudio();
}