Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Canvas presentation time issue

Dear all,

This post follows this one : 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.


  • I am not sure how this works with pyaudio, but generally, you have to be careful blocking the cpu during a loop. Things like wait, sleep, etc. block the computer such that nothing can happen during that duration, including keeping track of durations. So when you want your loop to not last longer than 2 seconds, you have to make sure your iterations are very short. What happens in your case, (I think) is that

    block =

    is doing such blocking, lasting for a few hundred millisecond, maybe? such that the temporal resolution of your loop is limited by this bit. If you can, try to reduce the size of the chunks to maybe only 10-20 ms. Still not ideal, but then your temporal delay will be much less

    Alternatively, you can always set the time limit to something clearly smaller (1500ms), and in case too much time is left add an additional wait period before the next trial, rather than the current response period.

    I hope this makes sense.


    Buy Me A Coffee

  • Thanks for answering so promptly, it makes perfect sense !

    I investigated a bit and calculated the timing of different elements in the script and it seems that this bit :

    # Listen for sounds until a timeout occurs.
    start_time = clock.time()
    print(f"Trial n° {Trial_nbr} starts recording")
    while clock.time() - start_time <= timeout:
            block =
        except IOError as e:
        loudness = get_rms(block)
    end_time = clock.time()
    # Close the audio stream
    print("%f ms total duration" % (end_time - start_time))

    runs for an average of 2015 ms - which seems totally acceptable given that the ~15 ms delay is quite consistant.

    The part that seems to take some time (and is more inconsistant) is this one :

    # Opens the microphone
    stream =

    it seems to take between 150 to 350 ms and delays the sound recording - does that sound possible to you ? (pun not intended).

    Therefore, and I am really not sure it's the right thing to do - so I'm might need some guidance on this - I place this part of the script in the prepare part of the script so that it doesn't load when timing is of the essence. It seems that this way the canvas presentation matches the timeout duration (~2000 ms) but is there something else I'm not considering that might make this a wrong solution ?

    Thanks for your help !

  • Yeah, that sounds legit. Again, I don't know how it works with audio, but for eye tracking it is similar, that first a connection to the device must be established that can take some few hundred milliseconds. And it generally also makes sense to move the time-consuming part to parts of the sequence that are not time-sensitive. The risk then is that the connection is open for "unnecessary" long durations, such that bad things can happen if anything unexpected happens. But normally, there shouldn't be a problem.

    As last time, I would advice you to just try it out, maybe take some benchmarks and if everything looks fine, you're good to go!


    Buy Me A Coffee

  • Makes perfect sense, thanks for your input ! I might as well just try to open the stream between the fixation cross on the stimuli sequence - might just do the trick !

    Anyways, appreciate your input ! Thanks

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games