Enhance Google Cloud speech recognition with streaming and asyncio#14
Merged
Enhance Google Cloud speech recognition with streaming and asyncio#14
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a significant refactor of the speech recognition system to support both streaming and non-streaming speech recognition via a new protocol-based abstraction. The changes decouple the code from a direct dependency on Google Cloud's speech client, introduce new handler classes for audio streaming and recognition, and improve error handling and extensibility. The most important changes are grouped below.
Speech Recognition Abstraction and Implementation:
SpeechRecognizer,StreamingSpeechRecognizer,StreamingSpeechSession) instackchan_server/types.pyto standardize the speech recognition API and enable pluggable backends.stackchan_server/speech_recognition/google_cloud.py, supporting both synchronous and streaming recognition.create_speech_recognizerinstackchan_server/speech_recognition/__init__.pyfor instantiating the default speech recognizer.Refactoring and Decoupling:
StackChanAppandWsProxyto use the newSpeechRecognizerabstraction instead of directly depending on Google Cloud's client, improving modularity and testability. [1] [2] [3] [4]Streaming Audio Handling and Error Management:
ListenHandlerinstackchan_server/listen.pyto manage streaming audio input, buffering, timeout handling, and integration with the speech recognizer, along with custom error types (TimeoutError,EmptyTranscriptError).WsProxyto delegate audio listening and error handling toListenHandler, removing redundant internal logic and ensuring proper resource cleanup. [1] [2] [3]Application Code Update:
example_apps/echo.pyto handleEmptyTranscriptErrorduring speech recognition, ensuring graceful session termination on empty transcripts. [1] [2]