Is there a way to interrupt Microphone stream that is sent to Google for Speech to Text?

303 Views Asked by At

I am attempting to write a Python script that will transcribe a conversation via a microphone connected to a PC. My specific application will be playing an internet stream of a radio contest, letting the mic listen to the speakers, and transcribe/append the result into a text file.

I am using the examples that Google gives for their Speech to Text examples for Python here: https://cloud.google.com/speech-to-text/docs/streaming-recognize#speech-streaming-recognize-php

And GitHub example here: https://github.com/googleapis/python-speech/blob/master/samples/microphone/transcribe_streaming_mic.py

The example is using pyaudio.

I have gotten this example to work as expected. It listens to the mic, sends the request to Google and I get the transcription back. I talk and get back what I said. I was also able to write this text out to a file as I want.

As another test, I started up a talk radio station for it to listen to. What I noticed is that the stream waits for a break or a pause in the talking to send the full "request" to Google. In the stream generator it is waiting for chunk to be None. Depending upon who is talking pauses are few and far between. For my specific need, time is of the essence. I cannot wait 30 seconds, a minute or more to receive a response.

I know that it will potentially cost more by making more API calls, but I am looking for a way to cut off the microphone or add a pause every 10, 20, or configurable seconds. Rather than waiting for it to get to a pause, I want to cut it off and let it start buffering the next request.

Has any one modified this example code from Google, or done any custom code that allows the MicrophoneStream class to stop itself after a pre-set number of seconds?

Thanks for any help you can provide.

0

There are 0 best solutions below