【发布时间】:2015-11-29 13:08:33
【问题描述】:
所以我试图运行一个 for 循环,只要声音持续,声音就会与图像一起播放。我可以看到图像显示很短的时间,也可以听到声音播放。但随后一切都停止了,我无法在 0.85 秒内在窗口中输入(我应该输入“j”或“f”)。在此之后,应该开始新的试验,但事实并非如此。不知道是不是因为我收到了这个错误:
sound1 = sound.SoundPygame(value=stimulussound)
AttributeError: 'SoundPygame' object has no attribute 'SoundPygame'
我不明白为什么我会收到这个错误,因为 sound1 是在第一次试播时播放的。但是在声音停止后,图像消失了,屏幕上显示了注视点,但注视点在 0.85 秒后并没有消失……而且如果我按 F 的 J,它确实将其保存在变量中!它还节省了反应时间! 无论如何,这是我的代码,为什么在第一个运行良好之后开始第二次试用?
#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()
【问题讨论】:
标签: python audio pygame psychopy