Search code examples
node.jsspeech-recognitiongrpcspeech-to-textgoogle-speech-api

How to proceed multiple streamingRecognize request in Google Speech-to-Text API?


I have built a web based Speech-to-Text application with Google Speech-to-Text API.

The application flow:

  1. Get audio stream from browser
  2. Stream audio data to a speech recognition service and get real time results as our user talks

enter image description here

I have referenced the sample code in my application, the streamingRecognize request works perfectly with a signal client call, and my server can receive the interim-transcription result from Google Speech API. However, when there are more then one client call streamingRecognize simultaneously, Google Speech API will get stuck. So, may I know how to handle more than one streamingRecognize request concurrently? Do I need to create another client to process the second streamingRecognize request? Thanks.

Back-end server specifications:

  • NodeJS
  • Socket.io

Solution

  • You should be able to create multiple streaming threads by using the same StreamingRecognize() client, the ones that can be used to send the requests in parallel. You can take a look on this and this Github posts where it is discussed this topic.

    I suggest you to try this alternative and verify if you can perform these streaming calls by creating 2 different objects or clients, such as:

    const client = new speech.SpeechClient();
    const recognizeStream = client.streamingRecognize(request)
    ...
    const recognizeStream2 = client.streamingRecognize(request)
    ...
    

    On the other hand, if you want to make audio recognitions for batch, it is rather recommended to use synchronous or asynchronous methods.