我使用了 AudioInputStream ,我使用 MaryTTS 从文本到语音得到它。在这种情况下,我想将此音频发送给客户端 Angular。我如何使用 http 执行此操作?我已将音频放入一个字节数组中,我该如何发送它?
这个方法返回一个字节数组。我想将它发送到一个角度应用程序并播放音频。有什么帮助吗?
public byte[] generateVoice( ) {
LocalMaryInterface maryInterface = null;
try {
maryInterface = new LocalMaryInterface();
} catch (MaryConfigurationException e) {
System.err.println("Could not initialize MaryTTS interface: " + e.getMessage());
e.printStackTrace();
}
try {
if (maryInterface != null) audio = maryInterface.generateAudio("this is the first audio");
} catch (SynthesisException e) {
System.err.println("Synthesis failed: " + e.getMessage());
}
byte[] buffer = new byte[0];
try {
buffer = new byte[audio.available()];
while ((audio.read(buffer)) != -1) {
System.out.println("the buffer is being filled");
}
} catch (IOException e) {
e.printStackTrace();
}
return buffer;
}