0

I have used a AudioInputStream , i get it from text to speech with MaryTTS . i want to send this audio to the client Angular in this case .How can i do this with http ? I have put the audio to an array of bytes and how can I send it ?

this methode returns an array of bytes .I want to send it to an angular app and play the audio .Any help please ?

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;

}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

you're going to have to make a stream. take a look at: npm stream-buffer

Lukas Sorensen
  • 397
  • 2
  • 12