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 is a 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)
This exercise is part of the course
Spoken Language Processing in Python
Learn how to load, transform, and transcribe speech from raw audio files in Python.
Speech recognition is still far from perfect. But the SpeechRecognition library provides an easy way to interact with many speech-to-text APIs. In this section, you'll learn how to use the SpeechRecognition library to easily start converting the spoken language in your audio files to text.
Exercise 1: SpeechRecognition Python libraryExercise 2: Pick the wrong speech_recognition APIExercise 3: Using the SpeechRecognition libraryExercise 4: Using the Recognizer classExercise 5: Reading audio files with SpeechRecognitionExercise 6: From AudioFile to AudioDataExercise 7: Recording the audio we needExercise 8: Dealing with different kinds of audioExercise 9: Different kinds of audioExercise 10: Multiple Speakers 1Exercise 11: Multiple Speakers 2Exercise 12: Working with noisy audioWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.