diff --git a/speech_recognition/recognizers/google_cloud.py b/speech_recognition/recognizers/google_cloud.py index 122104fa..883e51b5 100644 --- a/speech_recognition/recognizers/google_cloud.py +++ b/speech_recognition/recognizers/google_cloud.py @@ -105,7 +105,8 @@ def recognize( if len(response.results) == 0: raise UnknownValueError() - transcript = "" - for result in response.results: - transcript += result.alternatives[0].transcript.strip() + " " + transcript = " ".join( + result.alternatives[0].transcript.strip() + for result in response.results + ) return transcript diff --git a/tests/recognizers/test_google_cloud.py b/tests/recognizers/test_google_cloud.py index 340bda94..4b4d1a7c 100644 --- a/tests/recognizers/test_google_cloud.py +++ b/tests/recognizers/test_google_cloud.py @@ -41,7 +41,7 @@ def test_transcribe_with_google_cloud_speech(SpeechClient, monkeypatch): actual = recognize(MagicMock(spec=Recognizer), audio_data) - assert actual == "how old is the Brooklyn Bridge " + assert actual == "how old is the Brooklyn Bridge" SpeechClient.assert_called_once_with() client.recognize.assert_called_once_with( config=RecognitionConfig(