import speech_recognition as sr
# create a recognizer object
r = sr.Recognizer()
# use the default microphone as the audio source
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# recognize speech using Google Speech Recognition
try:
print("Google Speech Recognition thinks you said:")
print(r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
This program uses the speech_recognition library to create a recognizer object, which can recognize speech input from a microphone. It then uses the default microphone as the audio source, and prompts the user to say something.
Once the audio is captured, the program uses Google's Speech Recognition service to convert the audio into text. If the speech cannot be recognized, the program will print an error message.
Note that in order to use the Google Speech Recognition service, you will need an internet connection and an API key. Alternatively, you can use other speech recognition services that do not require an API key, such as CMU Sphinx or Wit.ai.
Comments
Post a Comment