Hello,
I’m using psychopy version 2021.2.3 and I have an error in the background music.
What I need?
I’m trying to put through the code a random background music, in ten different routines to play continuously for 30 seconds while a block of ten words is presented on the screen, in which each word is presented in random, for 3 seconds.
The experiment is designed in such a way that: There is a routine with background music with a block of ten words, followed by a routine with a blank text component (in which the background music does not play), followed by another routine with another music condition, and this process is repeated ten times (to cover the ten blocks)
What’s happening?
The background music plays normally with the established conditions, but it does not stop with the completion of the routine. That is, when the second routine of the blank text component enters, the music continues to play, when it shouldn’t.
I’m using the following code
Insert a code component into the routine where the sound will be played. On the “Start Experiment” tab, enter code like this to create the sound object in advance:
background_sound = sound.Sound(‘your_sound_file.wav’)
On the “Start routine” tab, put something like this, so that the sound starts playing, but only on the first iteration:
print("The song played is the number: "+str(numTest) + “BLOCK 1”)
background_sound = sound.Sound(“C:/Users/clesm/OneDrive/Desktop/nice music/nice_music_Num/”+str(testnum)+“.wav”)
background_sound.setVolume(1)
if trials.thisN == ‘0’:
background_sound.play()
On the “End Routine” tab:
if trials.thisN == ‘10’:
print(“Finishing Block A1”)
background_sound.stop()
I don’t understand coding very well, can someone help me please? Pardon my English.