Randomize order of audio files

PennController for IBEX Forums Support Randomize order of audio files

This topic contains 3 replies, has 2 voices, and was last updated by Jeremy Jeremy 3 weeks, 1 day ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4874
    Avatar
    mg5171
    Participant

    Hi,
    I’m trying to figure out how to randomize the order of audio files. I’d like to have 2 audio files play back to back in a randomized order (starting automatically on each trial). I see in the documentation that it’s possible to do this with images, but can’t figure out how to do the same with audio files since the Selector environment doesn’t seem to work with them. I’m new to IBEX, but if someone has an example snippet that does something similar (e.g. part of a binary forced-choice experiment), I can probably implement it!
    Thanks.

    #4875
    Jeremy
    Jeremy
    Keymaster

    Hi!
    Unfortunately there’s no pure-PennController way of doing this yet, but here is a simple enough workaround injecting some javascript in a trial script (fisherYates is an Ibex-native function):

    AddHost("https://upload.wikimedia.org/wikipedia/commons/") // This is where the files are
    
    newTrial(
        newButton("start").print().wait().remove()
        ,
        randomAudios = ["8/8f/Nl-winputje.ogg","2/2a/Nl-zonderegisters.ogg"],fisherYates(randomAudios)
        ,
        newAudio(randomAudios[0])
            .play()
            .wait()
        ,
        newAudio(randomAudios[1])
            .play()
            .wait()
        ,
        newButton("ok").print().wait()
    )
    #4878
    Avatar
    mg5171
    Participant

    Thanks; that works like a charm. Is there an easy way with this set up to record the order in which the files were played?

    #4880
    Jeremy
    Jeremy
    Keymaster

    If you log your audio elements using the command log("play"), your results file will report a line whenever the audio file is played, indicating its name and when it started playing, this way you can tell which was played first by comparing the timestamps. Another option is to store randomAudios[0] and randomAudios[1] in a couple of global Var elements that you log at the end of your newTrial, following the same method as described on this tutorial page.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.