From 4c2d2344a98616655f208d09f3856b334d2f9a8b Mon Sep 17 00:00:00 2001 From: ftnext Date: Sun, 22 Dec 2024 17:04:09 +0900 Subject: [PATCH 1/3] [feat] Delegate to google-auth --- speech_recognition/recognizers/google_cloud.py | 2 -- tests/recognizers/test_google_cloud.py | 18 +++--------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/speech_recognition/recognizers/google_cloud.py b/speech_recognition/recognizers/google_cloud.py index 122104fa..839df26a 100644 --- a/speech_recognition/recognizers/google_cloud.py +++ b/speech_recognition/recognizers/google_cloud.py @@ -42,8 +42,6 @@ def recognize( assert isinstance( audio_data, AudioData ), "``audio_data`` must be audio data" - if credentials_json_path is None: - assert os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") is not None assert isinstance(language, str), "``language`` must be a string" assert preferred_phrases is None or all( isinstance(preferred_phrases, (type(""), type(""))) diff --git a/tests/recognizers/test_google_cloud.py b/tests/recognizers/test_google_cloud.py index 340bda94..bd22961b 100644 --- a/tests/recognizers/test_google_cloud.py +++ b/tests/recognizers/test_google_cloud.py @@ -15,11 +15,7 @@ @patch("google.cloud.speech.SpeechClient") -def test_transcribe_with_google_cloud_speech(SpeechClient, monkeypatch): - monkeypatch.setenv( - "GOOGLE_APPLICATION_CREDENTIALS", "path/to/credentials.json" - ) - +def test_transcribe_with_google_cloud_speech(SpeechClient): client = SpeechClient.return_value # ref: https://cloud.google.com/speech-to-text/docs/transcribe-gcloud?hl=ja#make_an_audio_transcription_request client.recognize.return_value = RecognizeResponse( @@ -84,11 +80,7 @@ def test_transcribe_with_specified_credentials(SpeechClient): @patch("google.cloud.speech.SpeechClient") -def test_transcribe_show_all(SpeechClient, monkeypatch): - monkeypatch.setenv( - "GOOGLE_APPLICATION_CREDENTIALS", "path/to/credentials.json" - ) - +def test_transcribe_show_all(SpeechClient): client = SpeechClient.return_value client.recognize.return_value = RecognizeResponse( results=[ @@ -151,11 +143,7 @@ def test_transcribe_show_all(SpeechClient, monkeypatch): @patch("google.cloud.speech.SpeechClient") -def test_transcribe_with_specified_api_parameters(SpeechClient, monkeypatch): - monkeypatch.setenv( - "GOOGLE_APPLICATION_CREDENTIALS", "path/to/credentials.json" - ) - +def test_transcribe_with_specified_api_parameters(SpeechClient): client = SpeechClient.return_value client.recognize.return_value = RecognizeResponse( results=[ From a97ccb700becbbaf872a6d51cff6f0e415f2a823 Mon Sep 17 00:00:00 2001 From: ftnext Date: Sun, 22 Dec 2024 17:11:30 +0900 Subject: [PATCH 2/3] [docs] Links to setup local credentials --- README.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 522777b7..da70104d 100644 --- a/README.rst +++ b/README.rst @@ -155,9 +155,13 @@ Google Cloud Speech Library for Python (for Google Cloud Speech-to-Text API user ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The library `google-cloud-speech `__ is **required if and only if you want to use Google Cloud Speech-to-Text API** (``recognizer_instance.recognize_google_cloud``). - You can install it with :command:`python3 -m pip install SpeechRecognition[google-cloud]`. -(ref: `official installation instructions `__) +(ref: `official installation instructions `__) + +**Prerequisite**: Create local authentication credentials for your Google account + +* `Before you begin (Transcribe speech to text by using client libraries) `__ +* Detail: `User credentials (Set up ADC for a local development environment) `__ Currently only `V1 `__ is supported. (`V2 `__ is not supported) From a5a2fb201038a8006f4d5544bf76ba5be3adc541 Mon Sep 17 00:00:00 2001 From: ftnext Date: Sun, 22 Dec 2024 17:29:24 +0900 Subject: [PATCH 3/3] [style] Remove unused import --- speech_recognition/recognizers/google_cloud.py | 1 - 1 file changed, 1 deletion(-) diff --git a/speech_recognition/recognizers/google_cloud.py b/speech_recognition/recognizers/google_cloud.py index 839df26a..56489ea7 100644 --- a/speech_recognition/recognizers/google_cloud.py +++ b/speech_recognition/recognizers/google_cloud.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os from urllib.error import URLError from speech_recognition.audio import AudioData