Code: Select all
java.lang.RuntimeException: Audio processing failed
at com.assistt.voicecloneservice.service.AudioConverter.convertBase64ToPcmSigned(AudioConverter.java:42)
at com.assistt.voicecloneservice.service.AudioProcessingService.processAndUploadAndInsert(AudioProcessingService.java:35)
at com.assistt.voicecloneservice.api.TtsTextCheckService.doPost(TtsTextCheckService.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:559)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:854)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)
at java.lang.Thread.run(Thread.java:750)
Caused by: javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1121)
at com.assistt.voicecloneservice.service.AudioConverter.convertBase64ToPcmSigned(AudioConverter.java:20)
... 18 more
Code: Select all
public void convertBase64ToPcmSigned(String base64Audio) throws Exception {
byte[] audioByte = Base64.getDecoder().decode(base64Audio);
try (InputStream inputStream = new ByteArrayInputStream(audioByte);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Get AudioInputStream from the input stream
AudioInputStream inputAudioStream = AudioSystem.getAudioInputStream(inputStream);
// Define the target audio format
AudioFormat sourceFormat = inputAudioStream.getFormat();
AudioFormat targetFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED, // PCM_SIGNED format
8000.0f, // Sample rate
16, // Sample size in bits
1, // Channels (Mono)
2, // Frame size
8000.0f, // Frame rate
false // Big-endian
);
AudioInputStream convertedAudioStream = AudioSystem.getAudioInputStream(targetFormat, inputAudioStream);
File outputFile = new File("output.wav");
AudioSystem.write(convertedAudioStream, AudioFileFormat.Type.WAVE, outputFile);
} catch (UnsupportedAudioFileException | IOException e) {
throw new RuntimeException("Audio processing failed", e);
}
}
Code: Select all
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.assistt
VoiceCloneService
1.0-SNAPSHOT
war
1.8
1.8
UTF-8
javax.servlet
javax.servlet-api
4.0.1
provided
org.postgresql
postgresql
42.3.1
org.json
json
20210307
com.jcraft
jsch
0.1.55
Code: Select all
Encoding : PCM_SIGNED
Sample Rate : 40000.0 Hz
Sample Size : 16 bits
Channels : 1
Frame Size : 2 bytes
Frame Rate : 40000.0 frames/second
Big Endian : false
Welche Punkte sollte ich überprüfen oder welche alternativen Lösungen sollte ich versuchen, um dieses Problem zu lösen? Ist eine spezielle Konfiguration erforderlich, um Audiodateien in der JBoss-Umgebung zu verarbeiten?
Ich habe den folgenden Code ausprobiert, um die Daten im Base64-Format zunächst in eine WAV-Datei zu konvertieren und sie dann dateibasiert zu verarbeiten:
Code: Select all
File file = new File(sourceFilePath);
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
if (!inputStream.markSupported()) {
return;
}
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
AudioFormat sourceFormat = audioInputStream.getFormat();
AudioFormat targetFormat = new AudioFormat(
AudioFormat.Encoding.ALAW,
8000,
8,
sourceFormat.getChannels(),
1,
8000,
false
);
AudioInputStream convertedAudioInputStream = AudioSystem.getAudioInputStream(targetFormat, audioInputStream);
AudioSystem.write(convertedAudioInputStream, AudioFileFormat.Type.WAVE, new File(destinationFilePath));
inputStream.close();
audioInputStream.close();
convertedAudioInputStream.close();
Code: Select all
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1189)
at com.assistt.voicecloneservice.service.AudioConverter.convertBase64ToPcmSigned(AudioConverter.java:34)
...