[Tutor] Having trouble figuring out bug

richard kappler richkappler at gmail.com
Thu Feb 14 00:14:57 CET 2013

I have tried to run the Google speech recognition code found here:

I am getting the following traceback:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "GoogSTT.py", line 43, in listen_for_speech
    data = stream.read(chunk)
  File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 605, in read
    return pa.read_stream(self._stream, num_frames)

which refers to this part of the code:

while (True):
        data = stream.read(chunk)

        slid_win.append (abs(audioop.avg(data, 2)))

        if(True in [ x>THRESHOLD for x in slid_win]):
            if(not started):
                print "starting record"
            started = True
        elif (started==True):
            print "finished"
            #the limit was reached, finish capture and deliver
            filename = save_speech(all_m,p)
            #reset all
            started = False
            slid_win = deque(maxlen=SILENCE_LIMIT*rel)
            all_m= []
            print "listening ..."

I have run another bit of code is very similar to the above, to wit:

while 1:
        data = stream.read(CHUNK_SIZE)
        L = unpack('<' + ('h'*(len(data)/2)), data) # little endian, signed
        L = array('h', L)

and get no errors, the code runs fine and records. Please note that the
line in question is virtually identical in both snippets of code, one
works, one does not. To the best of my ability I have verified what I know
how to, for example chunk is set with a value previous, etc. Not sure where
I'm running into problems, could use some guidance. NOTE: I did not post
the entire code here for brevity, but it is available at the listed website
or, if it is preferred, I can post it in a follow-on email.

regards, Richard


quando omni flunkus moritati
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130213/4f58afd5/attachment.html>

More information about the Tutor mailing list