0

I have a servlet which creates a byte array and sends it as response.

byte[] to_send = func(text); // function that returns a byte array.
ServletOutputStream stream = response.getOutputStream();
stream.write(to_send);
stream.flush(); 

I am receiving the same using ajax.

var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
         {
            var a = xmlhttp.responseText;
            console.log(a);
            var audio = document.getElementById("myAudio");
            audio.src = a;
            audio.type = "type/ogg";
            }
          }
    xmlhttp.open("GET","myservlet?page=input&text="+a,true);
    xmlhttp.send();
}

I am receiving the giberish response text. Which I want to play using HTML5 audio control.

<audio id="myAudio" controls />

How can I achieve that?

Edit: I did it using data URI. I converted the Byte Array to data URI and sent it back and assigned it to SRC. Wish to know How I can do it using byte array.

WannaBeCoder
  • 1,280
  • 2
  • 17
  • 40

0 Answers0