[Tutor] call key on_press event multiple times when key is held down
__peter__ at web.de
Mon Jul 10 04:54:13 EDT 2017
Carlton Banks wrote:
> So i tried a different solution, introducing two threads one handling the
> keyboard, and the other one is a while true, that keeps running.
> https://pastebin.com/U0WVQMYP <https://pastebin.com/U0WVQMYP>
> but for some reason, am I constantly running into IOerror, hence
> no frames is being recorded. Any suggestion on why?
Please remember to always provide the traceback.
> while True:
> if listener.key_pressed == True and started == False:
> started = True
> print "start Stream"
> elif listener.key_pressed == False and started == True:
> print "Something coocked"
Did you get a non-empty output.wav?
If yes, my guess is that you can record something the first time you press
the key, and when you release it and close the audio input with
you see the IOError on the second attempt to record something.
As you are only prepared to record once and another record would overwrite
the file anyway (at least that's what I suppose
> wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
to do) perhaps you can omit the while-True loop altogether. Or you omit the
stream.close() call until after that loop (though there seems to be no way
to exit it cleanly at the moment).
Note that these are just ideas, I'm not familiar with pyaudio, or pynput, or
> started = False
More information about the Tutor