You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The multi-threaded version is very complicated. I just want to call for streaming recognize each time I need it rather than having it run as the main continuous loop of my app.
Is there a simple way to do that?
Once my other code is done, it will go back and capture audio, submit it to GRPC and transcribe the results and finish.
The version that records a file and then calls the REST service is not fast enough for near real-time transcription. I need the streaming version.
Yes - remember, this is sample code. It's not a library in itself - you should feel free to change it how you see fit.
Assuming you have interim_results=False, listen_print_loop doesn't need to be a loop, and it doesn't need to print. It could instead return the result once it's finalized (or you could detect END_OF_SPEECH and return an accumulation of results then). Or you could forego the listen_print_loop entirely and simply get the next result by getting the next iterator result - ie result = next(recognize_stream). The main idea is that recognize_stream is just an iterator of responses - you should feel free to do anything you want with them.
Depending on if you want to keep the connection, or the microphone, open, you might want to exit the cloud_speech.beta_create_Speech_stub or record_audio context managers. If you want them both to close after you get a result, you can just rename the main function to not be the main function, and call it from your real main function (after modifying it to return results, of course).
Activity
jerjou commentedon Oct 25, 2016
Yes - remember, this is sample code. It's not a library in itself - you should feel free to change it how you see fit.
Assuming you have
interim_results=False,listen_print_loopdoesn't need to be a loop, and it doesn't need to print. It could instead return the result once it's finalized (or you could detectEND_OF_SPEECHand return an accumulation of results then). Or you could forego thelisten_print_loopentirely and simply get the next result by getting the next iterator result - ieresult = next(recognize_stream). The main idea is thatrecognize_streamis just an iterator of responses - you should feel free to do anything you want with them.Depending on if you want to keep the connection, or the microphone, open, you might want to exit the
cloud_speech.beta_create_Speech_stuborrecord_audiocontext managers. If you want them both to close after you get a result, you can just rename themainfunction to not be the main function, and call it from your real main function (after modifying it to return results, of course).thecloudist commentedon Oct 25, 2016
Cheers. Very helpful.
chore: Update gapic-generator-python to v1.11.2 (#615)