Skip to content

Instantly share code, notes, and snippets.

@ivanistheone
Forked from GGulati/Jarvis.py
Last active March 29, 2017 00:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanistheone/b988d3de542c1bdd6a90 to your computer and use it in GitHub Desktop.
Save ivanistheone/b988d3de542c1bdd6a90 to your computer and use it in GitHub Desktop.
Code that goes with blog post https://ggulati.wordpress.com/2016/02/24/coding-jarvis-in-python-3-in-2016/ —with modifications for Mac OS X.

Speech recognition demo by ggulati

Original https://gist.github.com/GGulati/1ebaeaaa7f7408647fef via https://ggulati.wordpress.com/2016/02/24/coding-jarvis-in-python-3-in-2016/ via https://news.ycombinator.com/item?id=11172727

I did some modifications to try to get it to work on Mac OS.

Install

These are the instructions for Mac OS 10.10.x

brew install portaudio flac swig
pip install -r requirements.txt

Note installing pyobjc pulls in a kitchen sink full of stuff, so you'll have to go get a coffee.

Super fix

Monkey patch the file lib/python2.7/site-packages/pyttsx/drivers/nsss.py by adding the line

from objc import super

at the top of the file.

Still no cigar

Apparently pyttsx isn't maintained anymore, so the program hangs: RapidWareTech/pyttsx#26

from __future__ import print_function
import speech_recognition
import pyttsx
speech_engine = pyttsx.init('nsss')
speech_engine.setProperty('rate', 150)
recognizer = speech_recognition.Recognizer()
microphone = speech_recognition.Microphone()
def listen():
with microphone as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
print("Got it! Now to recognize it...")
try:
# recognizer.recognize_sphinx(audio) # == not very good out of the box
value = recognizer.recognize_google(audio)
return value
except speech_recognition.UnknownValueError:
print("Could not understand audio")
except speech_recognition.RequestError as e:
print("Recog Error; {0}".format(e))
return ""
speech_engine.say('Say something!')
# speech_engine.runAndWait() # hangs here...
said = listen()
print(said)
# speech_engine.say('I heard you say ' + said)
# speech_engine.runAndWait() # hangs here...
altgraph==0.12
macholib==1.7
modulegraph==0.12.1
py2app==0.9
PyAudio==0.2.9
pyobjc==3.0.4
pyttsx==1.1
SpeechRecognition==3.3.0
pocketsphinx==0.0.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment