[Tutor] call key on_press event multiple times when key is held down

Carlton Banks noflaco at gmail.com
Mon Jul 10 05:03:41 EDT 2017


Thanks for the response :)
> Den 10. jul. 2017 kl. 10.54 skrev Peter Otten <__peter__ at web.de>:
> 
> 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.
> 
There is no traceback, no error message besides the IOerror caught by the try/execpt. 

>> while True:
>>    time.sleep(0.1)
>>    if listener.key_pressed == True and started == False:
>>        started = True
>>        listener.stream.start_stream()
>>        print "start Stream"
>> 
>>    elif listener.key_pressed == False and started == True:
>>        print "Something coocked"
>>        listener.stream.stop_stream()
> 
> Did you get a non-empty output.wav?

The output.wav is empty

>>        listener.stream.close()
> 
> you see the IOError on the second attempt to record something.

I see the IOerror while i have the key down,  not only on the first or second attempt..

>>        p.terminate()

> As you are only prepared to record once and another record would overwrite 
> the file anyway (at least that's what I suppose
> 

currently I am trying to make one recording work like this,
but would like to have the functionality of keep generating different audio files,
with different utterances..
>>        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).
> 
Not sure if that is the problem here… 
> Note that these are just ideas, I'm not familiar with pyaudio, or pynput, or 
> wave.
> 
And thanks for suggestioning them :)
>>        wf.setnchannels(CHANNELS)
>>        wf.setsampwidth(p.get_sample_size(FORMAT))
>>        wf.setframerate(RATE)
>>        wf.writeframes(b''.join(frames))
>>        wf.close()
>> 
>>        started = False
>> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list