auditory stimulus resulting in error message NameError: name 'sound' is not defined

363 views
Skip to first unread message

tricia

unread,
Apr 17, 2013, 3:32:42 AM4/17/13
to psychop...@googlegroups.com
Hi,

I'm designing a routine in which an auditory stimulus will play throughout the routine while visual stimuli get updated by a loop.

I'm using a code component for the auditory stimulus as specified in the response here, which includes these instructions.

-- Insert a Code component in the routine. Right click on it and move it to the top so that it occurs before your image stimulus. 

-- In the "Begin Experiment" box, type: 
soundStarted = False 

-- In the "Begin Routine" box, type: 

if not soundStarted: 
    sound.Sound('mySound.wav').play() 
    soundStarted = True 

I'm getting the following error message.

 sound.Sound('list1.wav').play() 
NameError: name 'sound' is not defined

I've checked that my sound file is in the same directory as my experiment. I've tried assigning the sound file to a variable name (list1='list1.wav'). But I keep getting the same error message. Any suggestions about what I'm doing wrong?

Thanks!

Tricia

tricia

unread,
Apr 17, 2013, 3:41:51 AM4/17/13
to psychop...@googlegroups.com
Hi,

I actually just found the solution myself. When I had initialized the sound as list1='list1.wav', I was calling it with sound.Sound(list1).play(), but should have been calling it with sound.Sound('list1.wav').play(). 

Jonathan Peirce

unread,
Apr 17, 2013, 4:34:47 AM4/17/13
to psychop...@googlegroups.com
Actually, using a variable called list1 to store your string 'list1.wav' should be completely fine. I'm sure that wasn't the source of the problem.

The error message "sound is not defined" is caused by the fact that the psychopy sound library hadn't been imported at the top of your script. The reason it's now working is that you've either a) added an additional (standard) Sound Component to your experiment so psychopy has realised it needs to import the sound lib or b) you've got an additional line in your "begin experiment" custom code:
    from psychopy import sound

best wishes,
Jon
--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/Ap63krHgooMJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk



tricia

unread,
Apr 17, 2013, 4:50:40 AM4/17/13
to psychop...@googlegroups.com
Hi Jon,

Ah! That makes much more sense. In playing around with the problem I added a standard sound component and then removed it, but that must have imported the sound lib. Thanks for clarifying this, it's very useful for me in making progress to understand how psychopy works.
best,
Tricia

Michael MacAskill

unread,
Apr 17, 2013, 7:00:57 PM4/17/13
to psychop...@googlegroups.com
Dear Tricia,

The Builder doesn't know explicitly that it needs to access some sound code. So in the "Begin experiment" box, also type on a separate line:


from psychopy import sound


Regards,

Mike
> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
> To post to this group, send email to psychop...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/5GPfj2K6XgYJ.
Reply all
Reply to author
Forward
0 new messages