提问人:Kendal Johnson 提问时间:11/16/2023 最后编辑:toyota SupraKendal Johnson 更新时间:11/16/2023 访问量:14
向 PsycoPy 脚本添加代码以在 185wpm 处显示单词故事
Add code to PsycoPy script to display a word story at 185wpm
问:
每当我在脚本中插入自定义代码块时,PsychoPy 都会使实验崩溃。我 100% 确定这是由于我缺乏编码经验,而不是 PsychoPy 的任何问题。 我正在使用 PsychoPy v2021.2.3,我知道这是一个旧版本,但我需要将这个版本用于我的一项研究。但是,如果我可以使用更新的版本实现我的目标,并且可以在计算机上运行两个版本的 psychopy,那么我可以考虑此选项。除非我目前拥有的编码脚本可以修复。我还需要完成的脚本在理想情况下与构建器连接,直到我更流利地使用 python 编码,因为我可能会尝试将眼动追踪组件和脑电图标记添加到输出数据中。
目的目标是以每分钟 185 个单词的速度在屏幕上一行一行地显示书面的“Word Story”(白色屏幕上的黑色 Arial 字体),直到屏幕上均匀地填满 24 行文本。短暂停顿 2 秒后,屏幕应该会清除,故事会继续填满下一个屏幕,依此类推,直到整个故事呈现完毕。 在故事之前,例行脚本应该以欢迎屏幕(黑屏和白色文本)开头:“欢迎,你即将阅读一个书面故事。按空格键开始“——空格键将脚本推进到书面故事。 故事结束后,故事结束后,结尾画面应自动显示 20 秒,并显示“感谢您的阅读,请立即与研究人员见面”——(在带有白色文本的黑屏上)。
问题我创建了一个脚本,其中包含 WelcomeScreen、Blank500、WordStory、Blank500 和 End Screen 的基本流程作为构建器的起点。完整的故事在脚本中编码,并在变量 “text” 下的 # 初始化例程 “WordStory” 的组件中定义。我已经创建了一个音频故事和无声图片故事,具有类似的例程设置,效果很好。这只是我在构建时遇到麻烦的书面故事演示,因为所有为我需要呈现刺激的规范插入代码块的尝试都失败了。 如果这有帮助并且可以修改,我已经将 github 链接附加到当前脚本“MikeHooter.py”,以便它实现目标或帮助我理解我应该编写和插入的内容以取得更好的成功。https://github.com/KendalJohnson/SharingZone/blob/main/MikeHooter.py
这些是我一直在尝试使用的作品,但是我认为限制屏幕尺寸不是一个好主意,因为我看到人们遇到了这个问题。我也不确定高度。我也不认为它需要event.wait_keys():
import psychopy
from psychopy import core, visual, event
# Set up the experiment
win = visual.Window([800, 600], color="white")
# Set up the text stimulus
text = visual.TextStim(win, text="PUT MY TEXT HERE", height=0.5, font="Arial", color="black")
# Set the words per minute speed
words_per_minute = 185
# Set the lines per screen
lines_per_screen = 24
# Calculate the time per line
time_per_line = 60.0 / (words_per_minute * lines_per_screen)
# Set up the pause time
pause_time = 2.0
# Split the text into lines
lines = text.text.split("\n")
# Set the current line to 0
current_line = 0
# While there are still lines to display
while current_line < len(lines):
# Display the current line
text.text = lines[current_line]
text.draw()
# Wait for the appropriate time
core.wait(time_per_line)
# Increment the current line
current_line += 1
# Check if the screen is full
if current_line % lines_per_screen == 0:
# Clear the screen
core.flip()
# Wait for the pause time
core.wait(pause_time)
# Wait for a key press
event.wait_keys()
# Close the window
win.close()
非常感谢您,因为对此的任何帮助都非常感谢。
答: 暂无答案
评论