Randomised background music

I am helping create an experiment which uses background music. So far I can get it to work using the information found here: One background music during a loop - #13 by Xia_Tao

The issue is that I have 3 different sound files that it needs to randomly pick from, whilst they do the experiment. They will need to hear each of these pieces of background music once.

I can get it to play one, but I am not quite sure how to code it to shuffle and play the others.

Thanks

Jake

So in the end I managed to sort this (somewhat)

In begin experiment I have

background_sound = sound.Sound()

In begin routine I have

if musicfile == 'mozart':
    background_sound = sound.Sound('Mozart.wav')
elif musicfile == 'orion':
    background_sound = sound.Sound('Orion.wav')
elif musicfile == 'blank':
    background_sound = sound.Sound('blank.wav')


if trials.thisN == 0:
    background_sound.play()
    background_sound.setVolume(1)

And in end routine I have:

thisExp.addData('song',background_sound)
if trials.thisN == 143:
    background_sound.stop()

This has worked (for now). However I found that I was having the matrix error and the sound channel error, even though all of the songs are in the same Hz and in stereo (as checked and repeatedly re-saved in Audacity), which has led to me having to use PyGame to get the audio to work properly.

1 Like