Problem with reading the filepaths of sounds from excel file in loop (Coder)

Hi!
So I need to program a task where the first block of the experiment consists of a study word followed by a target word. The second block consists of two study words followed by a target word.
The words need to be presented auditorily. My code worked perfectly when I presented the words on my screen via textstimuli.
However, when I tried to present them auditorily in the loop, I constantly hear the same word that I made in advance (see in my code). I refer in every trial to the excelfile where the filepaths of my sounds are described.
Note that I have now two blocks with 3 trials in each block.
I don’t have any experience programming with sound stimuli, so I hope someone can help me!

Below a piece of my code:

import modules

from psychopy import visual, event, core, gui, data, sound
import pandas, numpy, os
from psychopy import prefs
prefs.general[‘audioLib’] = [‘pyo’]

start the ExperimentHandler, add the output file name and store the dialog box info

thisExp = data.ExperimentHandler(dataFileName = file_name, extraInfo = info)

number of blocks

n_wordsequences = 2

import the design (list of dictionaries)

DesignLD = data.importConditions(“Subtest_3.1_geluiden.xlsx”)

making a sound stimulus in advance with a random sound to overwrite later in the loop

display_sound = sound.Sound (value = my_directory + “/Geluiden/study_word_1_6.wav”)

Increasing word sequences per block

def choose_trials(blocknr):
# create the trials
if blocknr == 0:
Design_block = DesignLD[0:3] # this only takes rows 2-4 from excel file (1 study/ 1 target word)
else:
Design_block = DesignLD[3:6] # this only takes rows 5-7 from excel file (2 study/ 1 target word)
trials = data.TrialHandler(trialList = Design_block, nReps = 1, method = “sequential”)
thisExp.addLoop(trials)
return trials

for sequence in range(n_wordsequences):

trials = choose_trials(sequence)

    ## trial loop
for trial in trials:
    
    ## display the study word for sequence 1 (starting from row 2 in excelfile)
    if (sequence == 0):
        display_sound.value = trial["study_word1_sound"]
        display_sound.play()
        win.flip()
        core.wait(2)
        display_sound.stop()
        
    ## display the study words for sequence 2
    if (sequence == 1):
        ## display study word 1 (starting from row 5 in the excel file)
        display_sound.value = trial["study_word1_sound"]
        display_sound.play()
        win.flip()
        core.wait(2)
        display_sound.stop()
        
        
        ## display study word 2 (starting from row 5 in the excel file)
        display_sound.value = trial["study_word2_sound"]
        display_sound.play()
        win.flip()
        core.wait(2)
        display_sound.stop()
        
    ## display the target word
    display_sound.value = trial["target_word_sound"]
    display_sound.play()
    win.flip()
    core.wait(2)
    display_sound.stop()
    
    ## let the ExperimentHandler proceed to the next trial
    thisExp.nextEntry()

let the experimentHandler know its job is done

thisExp.close()

Below a piece of my excel file:

I hope someone knows what I’m doing wrong!

Kind regards
Luna

I can’t see anything immediately wrong, could it be to do with the code to get Design_block? You could try using a different conditions file and TrialHandler for each block rather than extracting rows from one unified TrialHandler

It is not due to “Design_block”. This worked perfectly when I presented the words as textstimuli. It only did not work when I wanted to switch to audio stimuli.
However, someone found the problem for me!

display_sound.value = trial[“study_word1_sound”] should be:

display_sound.setSound(my_directory + trial[“study_word1_sound”])

“setSound()” is a function specifically made to change Class objects. In my first code I assigned an integer to a value, however, this is not possible!
Thank you anyways for trying to help me.