From b6a306552d8c7c8d83c063bb8ba52b0ed2dfa2b2 Mon Sep 17 00:00:00 2001 From: Madhuri Agarwal Date: Wed, 6 Mar 2024 15:42:56 +0530 Subject: [PATCH 1/5] Update samples for google-cloud-speech to improve usability --- speech/snippets/transcribe_streaming_v2.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/speech/snippets/transcribe_streaming_v2.py b/speech/snippets/transcribe_streaming_v2.py index 1ade93d5321..7aaec468de2 100644 --- a/speech/snippets/transcribe_streaming_v2.py +++ b/speech/snippets/transcribe_streaming_v2.py @@ -17,13 +17,17 @@ # [START speech_transcribe_streaming_v2] from google.cloud.speech_v2 import SpeechClient -from google.cloud.speech_v2.types import cloud_speech +from google.cloud.speech_v2 import StreamingRecognizeRequest +from google.cloud.speech_v2 import RecognitionConfig +from google.cloud.speech_v2 import StreamingRecognizeResponse +from google.cloud.speech_v2 import StreamingRecognitionConfig +from google.cloud.speech_v2 import AutoDetectDecodingConfig def transcribe_streaming_v2( project_id: str, audio_file: str, -) -> cloud_speech.StreamingRecognizeResponse: +) -> StreamingRecognizeResponse: """Transcribes audio from audio file stream. Args: @@ -47,23 +51,23 @@ def transcribe_streaming_v2( for start in range(0, len(content), chunk_length) ] audio_requests = ( - cloud_speech.StreamingRecognizeRequest(audio=audio) for audio in stream + StreamingRecognizeRequest(audio=audio) for audio in stream ) - recognition_config = cloud_speech.RecognitionConfig( - auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), + recognition_config = RecognitionConfig( + auto_decoding_config=AutoDetectDecodingConfig(), language_codes=["en-US"], model="long", ) - streaming_config = cloud_speech.StreamingRecognitionConfig( + streaming_config = StreamingRecognitionConfig( config=recognition_config ) - config_request = cloud_speech.StreamingRecognizeRequest( + config_request = StreamingRecognizeRequest( recognizer=f"projects/{project_id}/locations/global/recognizers/_", streaming_config=streaming_config, ) - def requests(config: cloud_speech.RecognitionConfig, audio: list) -> list: + def requests(config: RecognitionConfig, audio: list) -> list: yield config yield from audio From 8b7530b9e6b94d809a327fc2761330936cd91c0a Mon Sep 17 00:00:00 2001 From: Madhuri Agarwal Date: Wed, 6 Mar 2024 17:28:40 +0530 Subject: [PATCH 2/5] Update transcribe_streaming_v2.py --- speech/snippets/transcribe_streaming_v2.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/speech/snippets/transcribe_streaming_v2.py b/speech/snippets/transcribe_streaming_v2.py index 7aaec468de2..1ade93d5321 100644 --- a/speech/snippets/transcribe_streaming_v2.py +++ b/speech/snippets/transcribe_streaming_v2.py @@ -17,17 +17,13 @@ # [START speech_transcribe_streaming_v2] from google.cloud.speech_v2 import SpeechClient -from google.cloud.speech_v2 import StreamingRecognizeRequest -from google.cloud.speech_v2 import RecognitionConfig -from google.cloud.speech_v2 import StreamingRecognizeResponse -from google.cloud.speech_v2 import StreamingRecognitionConfig -from google.cloud.speech_v2 import AutoDetectDecodingConfig +from google.cloud.speech_v2.types import cloud_speech def transcribe_streaming_v2( project_id: str, audio_file: str, -) -> StreamingRecognizeResponse: +) -> cloud_speech.StreamingRecognizeResponse: """Transcribes audio from audio file stream. Args: @@ -51,23 +47,23 @@ def transcribe_streaming_v2( for start in range(0, len(content), chunk_length) ] audio_requests = ( - StreamingRecognizeRequest(audio=audio) for audio in stream + cloud_speech.StreamingRecognizeRequest(audio=audio) for audio in stream ) - recognition_config = RecognitionConfig( - auto_decoding_config=AutoDetectDecodingConfig(), + recognition_config = cloud_speech.RecognitionConfig( + auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), language_codes=["en-US"], model="long", ) - streaming_config = StreamingRecognitionConfig( + streaming_config = cloud_speech.StreamingRecognitionConfig( config=recognition_config ) - config_request = StreamingRecognizeRequest( + config_request = cloud_speech.StreamingRecognizeRequest( recognizer=f"projects/{project_id}/locations/global/recognizers/_", streaming_config=streaming_config, ) - def requests(config: RecognitionConfig, audio: list) -> list: + def requests(config: cloud_speech.RecognitionConfig, audio: list) -> list: yield config yield from audio From e0dd6c41a64db932c23bc50d7ad7981f6216ea4b Mon Sep 17 00:00:00 2001 From: Madhuri Agarwal Date: Wed, 6 Mar 2024 17:33:38 +0530 Subject: [PATCH 3/5] Handling Issue #11248 Update samples for google-cloud-speech to improve usability --- speech/snippets/transcribe_streaming_v2.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/speech/snippets/transcribe_streaming_v2.py b/speech/snippets/transcribe_streaming_v2.py index 1ade93d5321..7aaec468de2 100644 --- a/speech/snippets/transcribe_streaming_v2.py +++ b/speech/snippets/transcribe_streaming_v2.py @@ -17,13 +17,17 @@ # [START speech_transcribe_streaming_v2] from google.cloud.speech_v2 import SpeechClient -from google.cloud.speech_v2.types import cloud_speech +from google.cloud.speech_v2 import StreamingRecognizeRequest +from google.cloud.speech_v2 import RecognitionConfig +from google.cloud.speech_v2 import StreamingRecognizeResponse +from google.cloud.speech_v2 import StreamingRecognitionConfig +from google.cloud.speech_v2 import AutoDetectDecodingConfig def transcribe_streaming_v2( project_id: str, audio_file: str, -) -> cloud_speech.StreamingRecognizeResponse: +) -> StreamingRecognizeResponse: """Transcribes audio from audio file stream. Args: @@ -47,23 +51,23 @@ def transcribe_streaming_v2( for start in range(0, len(content), chunk_length) ] audio_requests = ( - cloud_speech.StreamingRecognizeRequest(audio=audio) for audio in stream + StreamingRecognizeRequest(audio=audio) for audio in stream ) - recognition_config = cloud_speech.RecognitionConfig( - auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(), + recognition_config = RecognitionConfig( + auto_decoding_config=AutoDetectDecodingConfig(), language_codes=["en-US"], model="long", ) - streaming_config = cloud_speech.StreamingRecognitionConfig( + streaming_config = StreamingRecognitionConfig( config=recognition_config ) - config_request = cloud_speech.StreamingRecognizeRequest( + config_request = StreamingRecognizeRequest( recognizer=f"projects/{project_id}/locations/global/recognizers/_", streaming_config=streaming_config, ) - def requests(config: cloud_speech.RecognitionConfig, audio: list) -> list: + def requests(config: RecognitionConfig, audio: list) -> list: yield config yield from audio From dfbad1eaf3ef233f94f60c8ffd9720c1e89ebd95 Mon Sep 17 00:00:00 2001 From: Madhuri Agarwal Date: Thu, 21 Mar 2024 14:46:54 +0530 Subject: [PATCH 4/5] There are typos in a comment and a log message #11294 --- endpoints/getting-started/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/endpoints/getting-started/main.py b/endpoints/getting-started/main.py index 5e30779360b..db386f1f2e3 100644 --- a/endpoints/getting-started/main.py +++ b/endpoints/getting-started/main.py @@ -53,7 +53,7 @@ def echo(): # [START endpoints_auth_info_backend] def auth_info(): - """Retrieves the authenication information from Google Cloud Endpoints.""" + """Retrieves the authentication information from Google Cloud Endpoints.""" encoded_info = request.headers.get("X-Endpoint-API-UserInfo", None) if encoded_info: info_json = _base64_decode(encoded_info) @@ -89,7 +89,7 @@ def auth_info_firebase(): @app.errorhandler(http_client.INTERNAL_SERVER_ERROR) def unexpected_error(e): """Handle exceptions by returning swagger-compliant json.""" - logging.exception("An error occured while processing the request.") + logging.exception("An error occurred while processing the request.") response = jsonify( {"code": http_client.INTERNAL_SERVER_ERROR, "message": f"Exception: {e}"} ) From e3a74bda192ae4ad21fc6612def9e79570f47462 Mon Sep 17 00:00:00 2001 From: "Leah E. Cole" <6719667+leahecole@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:26:30 -0400 Subject: [PATCH 5/5] Update speech/snippets/transcribe_streaming_v2.py --- speech/snippets/transcribe_streaming_v2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/speech/snippets/transcribe_streaming_v2.py b/speech/snippets/transcribe_streaming_v2.py index 6abef0fbb71..4d51f48e2d3 100644 --- a/speech/snippets/transcribe_streaming_v2.py +++ b/speech/snippets/transcribe_streaming_v2.py @@ -24,7 +24,6 @@ def transcribe_streaming_v2( project_id: str, audio_file: str, ) -> cloud_speech_types.StreamingRecognizeResponse: - """Transcribes audio from audio file stream. Args: