Howdy, Stranger!

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

Supported by

Play sound from a list based on key response until participant chooses to move on

edited December 2024 in OpenSesame

I want to create a loop in which participants can choose to press "1" or "2" to trigger a sound to be played at random from a corresponding sound list. For instance, there may be the following lists of sounds:

List1: 1a.wav, 1b.wav, 1c.wav

List2: 2a.wav, 2b.wav, 2c.wav

Within a loop, participants would see a Sketchpad that says "Press 1 or 2 to hear a sound from the corresponding list." They could then repeatedly press "1", for instance, to hear sounds from that list (one per click, at random), or they could alternate between pressing "1" and "2" to hear sounds from either list.

Once they are satisfied, I want there to be a third option for participants to press, like "0", to move on to the next portion of the experiment.

I believe this will involve a keyboard_response within a loop with allowed responses "1; 2; 0" (for instance), and nested items (of some sort?) which are run conditionally in the sequence depending on which key response is given ("1" or "2", and with "0" triggering the whole loop to end).

Any advice on how I might go about this complex process?

Comments

  • Hi @JKellogg,

    There are probably several ways to do this., but here's one method that is realtively economical.

    Here's the logic:

    1. Set Up the Experiment

    • Add all your sound files (e.g., 1.ogg, 2.ogg) to the File Pool.
    • Use Inline Script items to manage dynamic behavior.

    2. Task Workflow

    Step 2.1: Initialize Variables

    • Before starting the task, create two shuffled lists of sound file names (one for each key, e.g., 1 and 2).
    • Set up a mechanism to track which sounds have been played and reset the list once all sounds are used.

    Step 2.2: Main Loop

    • Create a Loop item to repeat the task until a specific key (e.g., 0) is pressed.

    Step 2.3: Participant Instructions

    • Use a Sketchpad to display instruction

    Step 2.5: Select a Sound

    Add an

    • Inline Script

    to:

    • Determine which key was pressed.
    • Pick the next sound from the corresponding list.
    • Remove the played sound from the list.
    • Reset and reshuffle the list if it is empty.

    Step 2.6: Play the Sound

    • Dynamically play the selected sound using Python (instead of the sampler; I found this to work best because the sample appears to be set in the prepare phase and in my tests I didn't present the sound selected from the code executed immediately before but only did so on the next trial).


    A couple of additional comments:

    • I set "run if" of the loop to only execute the code playing the sound if end_experiment is false (this is the variable used to break the loop if the participant presses 0).
    • I used 1.ogg. 2.ogg, 3.ogg as my list 1, and 4.ogg, 5.ogg, 6.ogg as my list 2 (replace with whatever sounds you're using).
    • the loop as only one row but 100 cycles and a break if condition

    Here's my version. You should be able to adapt it to meet your needs:

    Hope this helps,

    Fabrice.

    Buy Me A Coffee

  • I was able to get this to work perfectly, thank you!

Sign In or Register to comment.