Using the Recognizer class
Now you've created an instance of the Recognizer
class we'll use the recognize_google()
method on it to access the Google web speech API and turn spoken language into text.
recognize_google()
requires an argument audio_data
otherwise it will return an error.
US English is the default language. If your audio file isn't in US English, you can change the language with the language
argument. A list of language codes can be seen here.
An audio file containing English speech has been imported as clean_support_call_audio
. You can listen to the audio file here. SpeechRecognition has also been imported as sr
.
To avoid hitting the API request limit of Google's web API, we've mocked the Recognizer
class to work with our audio files. This means some functionality will be limited.
Diese Übung ist Teil des Kurses
Spoken Language Processing in Python
Anleitung zur Übung
- Call the
recognize_google()
method onrecognizer
and pass itclean_support_call_audio
. - Set the language argument to
"en-US"
.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Create a recognizer class
recognizer = sr.Recognizer()
# Transcribe the support call audio
text = ____.____(
audio_data=____,
language=____)
print(text)