Skip to content

Commit 0fb14ff

Browse files
authored
Merge pull request #811 from ftnext/tweak/google-application-credentials
feat(google-cloud-speech): Delegate to google-auth
2 parents 9361057 + a5a2fb2 commit 0fb14ff

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

README.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@ Google Cloud Speech Library for Python (for Google Cloud Speech-to-Text API user
155155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156156

157157
The library `google-cloud-speech <https://pypi.org/project/google-cloud-speech/>`__ is **required if and only if you want to use Google Cloud Speech-to-Text API** (``recognizer_instance.recognize_google_cloud``).
158-
159158
You can install it with :command:`python3 -m pip install SpeechRecognition[google-cloud]`.
160-
(ref: `official installation instructions <https://cloud.google.com/speech-to-text/docs/transcribe-client-libraries#install_the_client_library>`__)
159+
(ref: `official installation instructions <https://cloud.google.com/speech-to-text/docs/transcribe-client-libraries#client-libraries-install-python>`__)
160+
161+
**Prerequisite**: Create local authentication credentials for your Google account
162+
163+
* `Before you begin (Transcribe speech to text by using client libraries) <https://cloud.google.com/speech-to-text/docs/transcribe-client-libraries#before-you-begin>`__
164+
* Detail: `User credentials (Set up ADC for a local development environment) <https://cloud.google.com/docs/authentication/set-up-adc-local-dev-environment#local-user-cred>`__
161165

162166
Currently only `V1 <https://cloud.google.com/speech-to-text/docs/quickstart>`__ is supported. (`V2 <https://cloud.google.com/speech-to-text/v2/docs/quickstart>`__ is not supported)
163167

speech_recognition/recognizers/google_cloud.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import os
43
from urllib.error import URLError
54

65
from speech_recognition.audio import AudioData
@@ -42,8 +41,6 @@ def recognize(
4241
assert isinstance(
4342
audio_data, AudioData
4443
), "``audio_data`` must be audio data"
45-
if credentials_json_path is None:
46-
assert os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") is not None
4744
assert isinstance(language, str), "``language`` must be a string"
4845
assert preferred_phrases is None or all(
4946
isinstance(preferred_phrases, (type(""), type("")))

tests/recognizers/test_google_cloud.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515

1616

1717
@patch("google.cloud.speech.SpeechClient")
18-
def test_transcribe_with_google_cloud_speech(SpeechClient, monkeypatch):
19-
monkeypatch.setenv(
20-
"GOOGLE_APPLICATION_CREDENTIALS", "path/to/credentials.json"
21-
)
22-
18+
def test_transcribe_with_google_cloud_speech(SpeechClient):
2319
client = SpeechClient.return_value
2420
# ref: https://cloud.google.com/speech-to-text/docs/transcribe-gcloud?hl=ja#make_an_audio_transcription_request
2521
client.recognize.return_value = RecognizeResponse(
@@ -84,11 +80,7 @@ def test_transcribe_with_specified_credentials(SpeechClient):
8480

8581

8682
@patch("google.cloud.speech.SpeechClient")
87-
def test_transcribe_show_all(SpeechClient, monkeypatch):
88-
monkeypatch.setenv(
89-
"GOOGLE_APPLICATION_CREDENTIALS", "path/to/credentials.json"
90-
)
91-
83+
def test_transcribe_show_all(SpeechClient):
9284
client = SpeechClient.return_value
9385
client.recognize.return_value = RecognizeResponse(
9486
results=[
@@ -151,11 +143,7 @@ def test_transcribe_show_all(SpeechClient, monkeypatch):
151143

152144

153145
@patch("google.cloud.speech.SpeechClient")
154-
def test_transcribe_with_specified_api_parameters(SpeechClient, monkeypatch):
155-
monkeypatch.setenv(
156-
"GOOGLE_APPLICATION_CREDENTIALS", "path/to/credentials.json"
157-
)
158-
146+
def test_transcribe_with_specified_api_parameters(SpeechClient):
159147
client = SpeechClient.return_value
160148
client.recognize.return_value = RecognizeResponse(
161149
results=[

0 commit comments

Comments
 (0)