title: Real-time transcription Google Cloud Speech API with gRPC from Electron
body: <p>What I want to achieve is the same real-time transcript process as Web Speech API but using Google Cloud Speech API.</p>
  <p>The main goal is to transcribe live recording through an Electron app with Speech API using gRPC protocol.</p>
  <p>This is a simplified version of what I implemented:</p>
  <pre class="lang-js prettyprint-override"><code>const { desktopCapturer } = window.require('electron');
  const speech = require('@google-cloud/speech');
  
  const client = speech.v1({
    projectId: 'my_project_id',
    credentials: {
      client_email: 'my_client_email',
      private_key: 'my_private_key',
    },
  });
  
  desktopCapturer.getSources({ types: ['window', 'screen'] }, (error, sources) =&gt; {
    navigator.mediaDevices
      .getUserMedia({
        audio: true,
      })
      .then((stream) =&gt; {
        let fileReader = new FileReader();
        let arrayBuffer;
        fileReader.onloadend = () =&gt; {
          arrayBuffer = fileReader.result;
          let speechStreaming = client
            .streamingRecognize({
              config: {
                encoding: speech.v1.types.RecognitionConfig.AudioEncoding.LINEAR16,
                languageCode: 'en-US',
                sampleRateHertz: 44100,
              },
              singleUtterance: true,
            })
            .on('data', (response) =&gt; response);
  
          speechStreaming.write(arrayBuffer);
        };
  
        fileReader.readAsArrayBuffer(stream);
      });
  });
  </code></pre>
  <p>The error response from Speech API is that the audio stream is too slow and we are not sending it in real-time.</p>
  <p>I feel that the reason is that I passed the stream without any formatting or object initialization so the streaming recognition cannot be performed.</p>