Canvas presentation time issue
This post follows this one : https://forum.cogsci.nl/discussion/comment/28157. As it's about a different topic, I thought it would be wiser to create a different thread.
The context :
I'm working on a voice key detection script that runs until a timeout occurs and record a sound file. While the recording runs, the script compares the loudness of the sound to a threshold and extract the response time on that basis. This will be a script that we will use for various purposes (mental calculation, reading, ...).
To try it out, I implemented it to the Lexical-decision task sample OS experiment. I want words/non-words to be presented for 2000 ms and sound to be recorded from stimulus presentation onset. Hence, the word canvas duration is set to 0 and I place my script right after. So far so good.
The issue :
The problem is that the canvas will be shown until the whole script is processed and not necessarily the 2000 ms of sound recording. For example, I tested the timing of canvas presentation and I'm more around 2300/2400 ms of presentation time, which is totally inacceptable for time-sensitive experiment.
The question :
How can I make sure that canvas presentation is "exactly" 2000 ms, that sound recording start "exactly" when canvas is shown, and stops "exactly again" when the canvas disappears ?
I'm sure I'm missing something quite obvious.
Many thanks for your help.
For your perfect illustration, I joined the script as an attachment.