Skip to content

Instantly share code, notes, and snippets.

@GGulati
Last active April 15, 2023 14:00
Show Gist options
  • Save GGulati/1ebaeaaa7f7408647fef to your computer and use it in GitHub Desktop.
Save GGulati/1ebaeaaa7f7408647fef to your computer and use it in GitHub Desktop.
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())
@k-ksharma
Copy link

look into the documentation of pyttsx and choose the correct engine corresponding to linux. no need of win32com client. hope it hrlps @kunci115
i think the engine is espeak or you can left that blank like pyttsx.init()

@ranand16
Copy link

ranand16 commented Feb 5, 2017

i have installed speech recognition but still i get

Traceback (most recent call last):
File "Jarvis.py", line 1, in
import SpeechRecognition
ImportError: No module named SpeechRecognition

@banziyeoh
Copy link

it does not record what i said

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment