0

So I'm trying to run a for loop in a way that a sound will be played together with an image for as long as the sound lasts. I can see the image displaying for a very short time and also I hear the sound playing. But then it all stops, I'm not able to give input in the window (I should give in 'j' or 'f') in 0.85 seconds. After this a new trial should begin, but it doesn't. Don't know if that's because of this error that I'm getting:

sound1 = sound.SoundPygame(value=stimulussound)

AttributeError: 'SoundPygame' object has no attribute 'SoundPygame'

I don't understand why I get that error since sound1 is being played the first trial. But after the sound stops, the image goes away, the fixationcross is showed on screen, but the fixationcross doesn't go away after 0.85 seconds... And also if I push J of F, it DOES save it in a variable! And it also saves a reactiontime! Anyways, here's my code, why isn't a second trial starting after the first one running great?

#showing instructions
instructions = visual.TextStim(window, text=actualinstructions)
instructions.draw()
window.flip()

#waiting for j-key before rest of experiment runs
if event.waitKeys("j"):
    window.flip()    
    start = True 

#whileloop to start experiment
while start == True:
#forloop
    for i in range (0,192):
    #saving the two needed pathways in a variable
        stimulusimage = conditiesalles[int(i)][int(2)]
        stimulussound = conditiesalles[int(i)][int(3)] #f.e. C:\Users\Ineke\Documents\Python Scripts\Project\stimuli\Sounds\Negative\6.wav



    #lengthofsound: using function 
        sound1 = sound.SoundPygame(value=stimulussound)
        lengthofsound = sound1.getDuration()

    #resetting timer and making a variable that knows the time 
        timerClock.reset()
        currentTime = timerClock.getTime()
        if (currentTime <= lengthofsound):
            #imagestim
            showingimage = visual.ImageStim(window, image=stimulusimage)
            showingimage.draw()
            window.flip()
            #soundPygame
            sound = sound.SoundPygame(value=stimulussound)
            sound.play()

        if (currentTime > lengthofsound):
            timerClock.reset()
            window.flip()

        if (currentTime <= timefixationcross):
            #fixatiekruis
            Fixationcross.fixationscross(window)

            #getKeys j of f = inputuser
            if event.getKeys('j'):
                inputuser = 'j'
                reactiontime = currentTime
            elif event.getKeys('f'):
                inputuser = 'f'
                reactiontime = currentTime
            else: 
                inputuser = "geen input of foute knop gebruikt"
                reactiontime = "geen reactie"
        inputsuser.append(inputuser)
        reactiontimesuser.append(reactiontime)

    #closing the window
    start == False    
    window.close()
Caeline
  • 119
  • 3
  • 13

1 Answers1

2

This error occurs because you overwrite the variable sound in this line:

sound = sound.SoundPygame(value=stimulussound)

... so the variable "sound" it no longer points to the psychopy.sound module once this line has been run. The error message tells you that there is no such attribute as psychopy.sound.SoundPygame.SoundPygame. The solution is simply to rename the variable in the above line to something different than "sound".

As a side note, you seem to create identical sound objects on each trial. sound1 and what you currently call sound are both sound.SoundPygame(value=stimulussound). Why not just have one?

Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
  • Alright I see now what went wrong. Don't get the error anymore now. Also I oversaw the fact I had sound1 and sound; I'm just using sound1 now. But when I try to run the while loop now, my created window just freezes and doesn't react to anything anymore. Can't close it with window.close() either. Do you maybe know how to solve this? Thanks! – Caeline Nov 30 '15 at 20:49
  • Yes, that's because the second-to-last line should have a single equal sign instead of a double, i.e. assign a value to ``start`` instead of doing a comparison. Right now the ``while`` loop just keeps looping forever since ``start`` is ``True`` forever. – Jonas Lindeløv Dec 01 '15 at 17:38