title: Stream audio with websocket and get back audio transcription obtained with Google speech API
body: <p>I have  a client which takes audio from mic then sends it to a remote server via websocket stream.</p>
  
  <p>Server side I get the audio stream from websocket</p>
  
  <pre><code>const WebSocket = require('websocket-stream');
  const wss = WebSocket.createServer({host: '192.168.254.161', port: 8090},handle);
  
  function handle(stream)  {
    stream.pipe(recognizeStream); 
    stream.on('close', function (){
      console.log("stream closed")
    }).on('error', function() {
      console.log("stream error")
    })
  }
  
  wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(message) {
          console.log('%s bytes received', message.length);
          ws.send("some mesage")
    }).on('close', function () {
         ws.send("End of audio data")
    }).on('error',function (err) {
        console.log("error:",err)
    });
  });
  </code></pre>
  
  <p>and send it to Google Speech API using SpeechClient with streamingRecognize </p>
  
  <pre><code>const recognizeStream = client
    .streamingRecognize(request)
    .on('error', console.error)
    .on('data', (data) =&gt; {
      process.stdout.write(
        data.results[0] &amp;&amp; data.results[0].alternatives[0]
          ? `Transcription: ${data.results[0].alternatives[0].transcript}\n`
          : `\n\nReached transcription time limit, press Ctrl+C\n`
      );
    });
  </code></pre>
  
  <p>All works and I get the transcript written to che server console..</p>
  
  <p>Now I need to send the transcript back via websocket, but I cannot find how to do it. The only place where I can send something back is in the ws event handler, but here I do not have access to the transcript data </p>