| Reference | Downloads | Github

Best way to build an auditory metronome into my experiment


I’m programming an experiment which requires participants to perform a simple choice reaction time task whilst performing a distractor task (foot tapping or articulatory suppression) to the beat of a metronome (100 beats per minute).

I create my experiments in Builder and was originally planning on inserting an audio file of a ticking metronome, but now I think it might be easier & neater to insert a “code component” (Python command) which basically simulates a metronome (100 ticks/beeps per minute) throughout the entire experiment.

Can I get Psychopy to present such a timed sound using python commands? I don’t actually care whether it’s a tick or a beep, etc., as long as it’s 100 beats per minute.

Then ideally I would also be able to suppress the ticking during certain conditions, though is not totally essential (if it just beeps throughout that’s fine too!).

I’d be really grateful for any advice!

You are able to simulate a metronome in the PsychoPy by utilising the psychopy.Sound module and the psychtoolbox. The sound module will allow you to play any sound, or a tone/beep whilst the GetSecs() function from the psychtoolbox will allow you to delay said sound by any amount.

The .play() function from the Sound module does have a parameter of when which can delay the playing of a sound, however this appeared to be inconsistent in my tests which is why I chose to use GetSecs()

For the example I will use this metronome sound, located in the the root project folder sounds\metronome.wav

Here is the basic breakdown of the code component

We assign our desired metronome BPM at the start of the experiment because in this instance, we are not manipulating it on a per-trial basis. Then we use sound.Sound() to create a reference to the locally stored metronome.wav.

Afterwards we use ptb.GetSecs() to return the current real time in seconds and use a conditional if statement to determine if the difference between the last time we obtained the seconds and now exceeds our defined BPM.

If it does, then play the required sound and update the now variable to the most current seconds.

Here is the final result played at 100 BPM

You could modify the if statement to include the and (&&) operator for a boolean shouldPlayMetronome variable to suppress the ticking during conditions