I am trying to do simple voice recognition with the Raspberry Pi, to execute commands like turning the GPIO pins on and off for home automation. I got it working in a terminal pretty quickly using this great tutorial by Steven Hickson, but I wanted to try it with Python instead. I googled it and found this: https://bitbucket.org/drneox/pygsr.
I followed the necessary directions to download and install pyaudio and pygsr, then tried running their example code:
Code: Select all
from pygsr import Pygsr
speech = Pygsr()
speech.record(3) # duration in seconds (3)
phrase, complete_response = speech.speech_to_text('es_ES') # select the language
print phrase
Code: Select all
Traceback (most recent call last):
File "/home/pi/Documents/speech_recognition.py", line 4, in <module>
speech.record(3) # duration in seconds
File "/usr/local/lib/python2.7/dist-packages/pygsr/__init__.py", line 29, in record
frames_per_buffer=self.chunk)
File "/usr/lib/pymodules/python2.7/pyaudio.py", line 714, in open
stream = Stream(self, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/pyaudio.py", line 396, in __init__
self._stream = pa.open(**arguments)
IOError: [Errno Invalid sample rate] -9997
'defaultSampleRate': 16000.0
So...now I know the sample rate should be 16,000, but I cannot figure out how to set it. I opened the files __init__.py, and pyaudio.py and looked at lines 29, 714, and 396 respectively (as listed in the error message above), but could not find anything that looked like it was hard-coding the sample rate. I googled "pyaudio set sample rate", expecting there to be some command to manually set the sample rate (again, newbie here) but didn't see anything obvious.
So, here I am. I'd appreciate any help in newbie-friendly terms. I'm guessing I need to do something, somewhere, to make Python accept my device's sample rate, but have no idea how.
Finally, I'm running the version of Raspbian from the official raspberrypi.org download page. This code is running in Python 2.7 because I couldn't get pygsr to work with 3.3.