From 6a113a50250ab697fdedbb801c951de35c8648c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aline=20Guimar=C3=A3es?= Date: Tue, 1 Mar 2022 11:15:36 -0300 Subject: [PATCH 1/2] Google cloud imports --- speech_recognition/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/speech_recognition/__init__.py b/speech_recognition/__init__.py index 37b17292..43c91409 100644 --- a/speech_recognition/__init__.py +++ b/speech_recognition/__init__.py @@ -930,8 +930,6 @@ def recognize_google_cloud(self, audio_data, credentials_json=None, language="en try: import socket from google.cloud import speech - from google.cloud.speech import enums - from google.cloud.speech import types from google.api_core.exceptions import GoogleAPICallError except ImportError: raise RequestError('missing google-cloud-speech module: ensure that google-cloud-speech is set up correctly.') @@ -945,15 +943,15 @@ def recognize_google_cloud(self, audio_data, credentials_json=None, language="en convert_rate=None if 8000 <= audio_data.sample_rate <= 48000 else max(8000, min(audio_data.sample_rate, 48000)), # audio sample rate must be between 8 kHz and 48 kHz inclusive - clamp sample rate into this range convert_width=2 # audio samples must be 16-bit ) - audio = types.RecognitionAudio(content=flac_data) + audio = speech.RecognitionAudio(content=flac_data) config = { - 'encoding': enums.RecognitionConfig.AudioEncoding.FLAC, + 'encoding': speech.RecognitionConfig.AudioEncoding.FLAC, 'sample_rate_hertz': audio_data.sample_rate, 'language_code': language } if preferred_phrases is not None: - config['speechContexts'] = [types.SpeechContext( + config['speechContexts'] = [speech.SpeechContext( phrases=preferred_phrases )] if show_all: @@ -963,7 +961,7 @@ def recognize_google_cloud(self, audio_data, credentials_json=None, language="en if self.operation_timeout and socket.getdefaulttimeout() is None: opts['timeout'] = self.operation_timeout - config = types.RecognitionConfig(**config) + config = speech.RecognitionConfig(**config) try: response = client.recognize(config, audio, **opts) From 9c68e159b771bb3cff678c8615773eb9cab92b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aline=20Guimar=C3=A3es?= Date: Tue, 1 Mar 2022 12:57:38 -0300 Subject: [PATCH 2/2] fix recognize_google_cloud --- speech_recognition/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech_recognition/__init__.py b/speech_recognition/__init__.py index 43c91409..3e1261a4 100644 --- a/speech_recognition/__init__.py +++ b/speech_recognition/__init__.py @@ -964,7 +964,7 @@ def recognize_google_cloud(self, audio_data, credentials_json=None, language="en config = speech.RecognitionConfig(**config) try: - response = client.recognize(config, audio, **opts) + response = client.recognize(config=config, audio=audio) except GoogleAPICallError as e: raise RequestError(e) except URLError as e: