1
Speech recognition!!
OathOfCode (2)

Can a repl.it developer put in the speech_recognition library!
PLEASE!!!!!!!!!

import speech_recognition
import pyttsx

speech_engine = pyttsx.init('sapi5') # see http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init
speech_engine.setProperty('rate', 150)

def speak(text):
speech_engine.say(text)
speech_engine.runAndWait()

recognizer = speech_recognition.Recognizer()

def listen():
with speech_recognition.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)

try:
	return recognizer.recognize_sphinx(audio)
	# or: return recognizer.recognize_google(audio)
except speech_recognition.UnknownValueError:
	print("Could not understand audio")
except speech_recognition.RequestError as e:
	print("Recog Error; {0}".format(e))

return ""

speak("Say something!")
speak("I heard you say " + listen())

You are viewing a single comment. View All
1
21natzil (678)

That's a very cool library! You would have to read it from an audio file however, because at the moment repl.it cannot connect to your system's microphone. If you're having trouble finding the packages, click the option bar to the left, and then switch to package search. Search for the pyttsx and enable that, and then also search for SpeechRecognition, and enable that.