title: Sending raw audio bytes from Javascript client to Spring Web Socket Handler
body: <p>What's the best way to send raw audio bytes to a web socket handler in spring? I have the following web socket handler which can receive text messages correctly from client.</p>
  
  <pre><code>public class TranscribeHandler implements WebSocketHandler {
      WebSocketSession session;
  
  @Override
  public void afterConnectionEstablished(WebSocketSession session) throws Exception {
      this.session = session;
      System.out.println("Connection established Transcribe");
  }
  
  @Override
  public void handleMessage(WebSocketSession var1, WebSocketMessage&lt;?&gt; var2) throws Exception {
      System.out.println("Got message");
  }
  
  @Override
  public void afterConnectionClosed(WebSocketSession var1, CloseStatus var2) throws Exception {
      System.out.println("Connection closed");
  }
  
  @Override
  public boolean supportsPartialMessages() {
      return false;
  }}
  </code></pre>
  
  <p>Here's client code that processes audio from microphone</p>
  
  <pre><code>this.ws = new $WebSocket("ws://localhost:8082/transcribe");
  //Creates a websocket session with server successfully
  
  var scriptNode = context.createScriptProcessor(256, 1, 1);
  var scriptNode.addEventListener('audioprocess', function(e) {
    var audioBytes = e.inputBuffer.getChannelData(0);
    this.ws.send(audioBytes).publish().connect();
  }
  </code></pre>
  
  <p>The audioBytes I get is a 'Float32Array', which I am sending directly to the server socket session. The server handler receives this message in string format which looks something like this:</p>
  
  <p>{"0":-0.0005212430842220783,"1":-0.0008100871928036213,"2":-0.0008365644607692957,"3":-0.0020894776098430157,"4":-0.0006563755450770259, 
  ...
  ...
  254":-0.0005547034088522196,"255":0.0010016305604949594}</p>
  
  <p>I want to convert this string message into raw bytes[]. How do I do that? I am thinking there should be a simple way of directly sending the audio bytes through a socket instead of me processing the string format. If anyone has tried to do this please help. Thanks.</p>