Randomize audios

PennController for IBEX Forums Support Randomize audios

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7386
    li_dx
    Participant

    Hi Jeremy,

    Thank you for creating and maintaining PCIbex! I’ve found it super useful! I’m wondering whether it’s possible to randomize the order by which multiple audios are played in a single trial. Here’s a link to the experiment. I’m building a word learning experiment where at each training trial, participants will see multiple objects and hear multiples non-sense words, and they will need to learn the word-object mapping. As shown in the code below, the order of the three audios at each trial is fixed, and I wonder if they can be randomized? Thanks!

    // Trainings trials 
    Template("training.csv", row =>
        newTrial("training",
            newTimer("break", 1000)
                .start()
                .wait()
            ,
            newImage("image1", row.image1)
                .size(200, 200)
            ,
            newImage("image2", row.image2)
                .size(200, 200)
            ,
            newImage("image3", row.image3)
                .size(200, 200)
            ,
            newCanvas("side-by-side", 700,200)
                .add(  0, 0, getImage("image1"))
                .add(250, 0, getImage("image2"))
                .add(500, 0, getImage("image3"))
                .center()
                .print()
            ,
            newSelector("selection")
                .add(getImage("image1"), getImage("image2"), getImage("image3"))
                .disableClicks()
                .shuffle()
            ,
            newAudio("audio1", row.audio1)
                .play()
                .wait()
            ,
            newTimer("break2", 1000)
                .start()
                .wait()
            ,
            newAudio("audio2", row.audio2)
                .play()
                .wait()
            ,
            newTimer("break3", 1000)
                .start()
                .wait()
            ,
            newAudio("audio3", row.audio3)
                .play()
            ,
            newTimer("break4", 1000)
                .start()
                .wait()
            ,
            getAudio("audio3")
                .wait("first")
        )
        .log("group", row.group)
        .log("item", row.item)
        .log("condition", row.condition)
    )
    #7388
    Jeremy
    Keymaster

    Hi,

    Yes, you can use plain javascript to randomize the order of the audios. Here’s how I would go about it:

    Template("training.csv", row =>
        newTrial("training",
            audios = [row.audio1,row.audio2,row.audio3].sort(v=>0.5-Math.random()),
            newTimer("break", 1000)
                .start()
                .wait()
            ,
            newImage("image1", row.image1)
                .size(200, 200)
            ,
            newImage("image2", row.image2)
                .size(200, 200)
            ,
            newImage("image3", row.image3)
                .size(200, 200)
            ,
            newCanvas("side-by-side", 700,200)
                .add(  0, 0, getImage("image1"))
                .add(250, 0, getImage("image2"))
                .add(500, 0, getImage("image3"))
                .center()
                .print()
            ,
            newSelector("selection")
                .add(getImage("image1"), getImage("image2"), getImage("image3"))
                .disableClicks()
                .shuffle()
            ,
            newAudio("audio1", audios[0])
                .play()
                .wait()
            ,
            newTimer("break2", 1000)
                .start()
                .wait()
            ,
            newAudio("audio2", audios[1])
                .play()
                .wait()
            ,
            newTimer("break3", 1000)
                .start()
                .wait()
            ,
            newAudio("audio3", audios[2])
                .play()
            ,
            newTimer("break4", 1000)
                .start()
                .wait()
            ,
            getAudio("audio3")
                .wait("first")
        )
        .log("group", row.group)
        .log("item", row.item)
        .log("condition", row.condition)
        .log("audio1", audios[0])
        .log("audio2", audios[1])
        .log("audio3", audios[2])
    )

    Jeremy

    #7390
    li_dx
    Participant

    This works great! Thank you so much!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.