Java 8 – javax.sound.sampled.UnsupportedAudioFileException-Fehler auf JBoss ServerJava

Java-Forum
Guest
 Java 8 – javax.sound.sampled.UnsupportedAudioFileException-Fehler auf JBoss Server

Post by Guest »

In einer Anwendung, die ich mit Java 8 entwickelt habe, versuche ich, eine im Base64-Format empfangene WAV-Audiodatei in das PCM_SIGNED-Format zu konvertieren. Der Code funktioniert in der lokalen Umgebung einwandfrei, aber ich erhalte die folgende Fehlermeldung auf JBoss EAP 6.4:

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
Die Methode, bei der ich eine Fehlermeldung erhalte, ist wie folgt:

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);
}
}
Meine pom.xml-Datei:

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





Ich habe den Base64-Teil selbst manuell in eine WAV-Datei konvertiert und es kam mit den folgenden Eigenschaften heraus.

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
Der Fehler tritt nur in der JBoss EAP 6.4-Umgebung auf. Wenn ich lokal teste, werden die Dateien korrekt verarbeitet und konvertiert.
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();
Ich habe die folgende Fehlermeldung in dieser Zeile erhalten: AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);

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)
...

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post