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.
This exercise is part of the course
Spoken Language Processing in Python
Exercise instructions
- Call the
recognize_google()
method onrecognizer
and pass itclean_support_call_audio
. - Set the language argument to
"en-US"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a recognizer class
recognizer = sr.Recognizer()
# Transcribe the support call audio
text = ____.____(
audio_data=____,
language=____)
print(text)