speech recognition python package code example
Example 1: python speech recognition
import speech_recognition as sr
def take_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening...')
r.pause_threshold = 1
r.energy_threshold = 50
audio = r.listen(source)
try:
print('Recognizing...')
qry = r.recognize_google(audio, language='en-in')
print(f"user said: {qry}\n")
except Exeption as e:
print(e)
print('Say that again please\n')
return 'None'
return qry
if __name__ == '__main__':
while True:
qry = takecommand().lower()
/\/\/\/\/\/\/\/\/\/\/\--- *HAPPYCODING* ---/\/\/\/\/\/\/\/\/\/\/\
Example 2: how to fix speech recognition in python
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
print("You said " + r.recognize(audio))
except LookupError:
print("Could not understand audio")