Howdy, Stranger!

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

Supported by

Randomly playing wav. files from the file pool.

edited February 2017 in OpenSesame

Hello,
I'm new to both python and opensesame. So, my struggle is briefly as follows;

  • I need to play 90 different audio files for each participant. (These audio files are one second long, and they are in my file pool.)
  • Mouse clicking response must be received from the subject when each sound is played. (I have an inline code for a slider on the screen that participants should select a point on it and then click to respond.)
  • After that, a new response should be received by playing the next sound.
  • This loop must continue 90 times until all audio files are played randomly.
  • Also, the sound should play while the slider is on the screen, so I need to implement a code to my slider's inline script.

I'm waiting for your suggestions,
Best,

Comments

  • edited February 2017

    Hi ozgendk,

    I have a suggestion for the random sound play for you.
    Important: The sound files in your pool have to have the same name with an ongoing number
    Example: Sound_file_1, Sound_file_2,....., Sound_file_90

    Here is the code for that:

    i=1                                     #control variable
    sound_list = []                         #initialization
    while i <= 90:                              #90 sounds
        sound_list.append("Sound_file_"+ str(i) + ".wav")   #append the name of the current sound in a list
        i=i + 1                             
    
    
    j=1                                         #control variable
    
    while j <= 90:                                  #90 sounds
        #Sound play:
        sound = str(random.choice(sound_list))  #chose a random item of the list
        src = pool[sound]                       #get the path of that item from the pool
        my_sampler = sampler(src, volume=1) #initialize the sampler
        my_sampler.play()                   #play the sampler
    sound_list.remove(sound)                #remove chosen item of the list
        j = j + 1                               
    

    I hope this will help you a bit.

    For the parallel sound playing and the screen presentation (slider) take a look ate the "threading" module. Keep in mind to keep the slider function in the mainthread.

Sign In or Register to comment.