Skip to content

Commit 6c7869c

Browse files
authored
Merge pull request Uberi#179 from akabraham/master
Only return transcript in recognize_google()
2 parents e2f4dc5 + c6b3af0 commit 6c7869c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

speech_recognition/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,11 @@ def recognize_google(self, audio_data, key=None, language="en-US", show_all=Fals
737737
# return results
738738
if show_all: return actual_result
739739
if "alternative" not in actual_result: raise UnknownValueError()
740-
alternatives = actual_result["alternative"]
741740
# return alternative with highest confidence score
742-
return sorted(alternatives, key=itemgetter("confidence"))[-1]
741+
ordered_alternatives = sorted(
742+
actual_result["alternative"], key=itemgetter("confidence")
743+
)
744+
return ordered_alternatives[-1]["transcript"]
743745

744746
def recognize_google_cloud(self, audio_data, language="en-US", preferred_phrases=None, show_all=False):
745747
"""

0 commit comments

Comments
 (0)