Ejemplo: reconocimiento de voz de Python
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")
# if any error occurs this line will run
except Exeption as e:
# if you don't want to print the error comment the bottom line
print(e)
print('Say that again pleasen')
return 'None'
return qry
if __name__ == '__main__':
while True:
qry = takecommand().lower()
# now you can use the takecommand function where you waht to recognize speech
# And please experiment with the above code
# like what pause_threshold and energy_threshold do and don't be afraid
# of errors
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)