I'm having difficults to understand the dynamics of a python script excerpt related to chunk generators and transcription process.
Here is the full code: https://cloud.google.com/speech-to-text/docs/samples/speech-transcribe-streaming-mic#code-sample
And I'm not getting this part of the script:
with MicrophoneStream(RATE, CHUNK) as stream:
audio_generator = stream.generator()
requests = (
speech.StreamingRecognizeRequest(audio_content=content)
for content in audio_generator
)
responses = client.streaming_recognize(streaming_config, requests)
# Now, put the transcription responses to use.
listen_print_loop(responses)
I could manage that 'audio_generator' variable receives a kind of function return (chunks of audio stream from microphone). But then, the 'request' variable gets multiple 'speech.StreamingRecognizeRequest' objects which are fed into 'client.streaming_recognize' requests. Then, 'responses' objects are handled in 'listen_print_loop' for showing the text result. However, I can't see why script is able to loop indefinitely and how it ends by saying "exit".
I tried searching for threads explaination (because of queue usage) and "yield" for function return, but I'm not getting how this part works.