Skip to content

Commit dbf9893

Browse files
committed
[publish] [important] add sound to capture_response for audio-sst
1 parent 00ee3f3 commit dbf9893

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

docs/tutorials/build_stimunit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ StimUnit('goodbye',win,kb)\
280280

281281
### 6. Get responses with `capture_response()`
282282

283-
The `capture_response()` method in `StimUnit` integrates stimulus presentation, timing, triggers, and response handling into a single, chainable call. It is ideal for:
283+
The `capture_response()` method in `StimUnit` integrates stimulus presentation, timing, triggers, and response handling into a single, chainable call. Like `.show()`, it automatically handles both visual and audio stimuli. It is ideal for:
284284

285285
- Detecting and logging subject responses within a predefined response window
286286
- Determining correct versus incorrect responses for performance analysis

docs/tutorials/build_stimunit_cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ StimUnit('goodbye',win,kb)\
270270

271271
### 6. 使用 `capture_response()` 获取反应
272272

273-
`capture_response()` 方法在 `StimUnit` 中将刺激呈现、计时、触发器和反应处理集成到一个单一的、可链式调用的函数中。它非常适合:
273+
`capture_response()` 方法在 `StimUnit` 中将刺激呈现、计时、触发器和反应处理集成到一个单一的、可链式调用的函数中。`.show()` 类似,它会自动处理视觉和听觉刺激。它非常适合:
274274

275275
- 在预定义的反应窗口内检测和记录被试的反应
276276
- 为性能分析确定正确与不正确的反应

psyflow/StimUnit.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,13 @@ def capture_response(
498498
raise TypeError(f"Invalid duration type: {type(duration)}")
499499
self.set_state(duration=t_val)
500500

501-
# initial draw + trigger scheduling
501+
# --- Initial Flip (trigger locked to onset) ---
502502
for stim in self.stimuli:
503-
stim.draw()
503+
if hasattr(stim, "play") and callable(stim.play):
504+
self.win.callOnFlip(stim.play)
505+
else:
506+
stim.draw()
507+
504508
self.win.callOnFlip(self.send_trigger, onset_trigger)
505509
self.win.callOnFlip(self.set_state,
506510
onset_time=self.clock.getTime(),
@@ -519,12 +523,12 @@ def capture_response(
519523
responded = False
520524
chosen_key = None # track which key to highlight
521525

522-
526+
visual_stims = [s for s in self.stimuli if hasattr(s, "draw") and callable(s.draw)]
523527
n_frames = int(round(t_val / self.frame_time))
524528
for _ in range(n_frames-1):
525529
# draw or blank?
526530
if not (responded and terminate_on_response):
527-
for stim in self.stimuli:
531+
for stim in visual_stims:
528532
stim.draw()
529533
# draw highlight if requested
530534
if highlight_stim and (responded or dynamic_highlight):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "psyflow"
7-
version = "0.1.1"
7+
version = "0.1.2"
88
description = "A utility package for building modular PsychoPy experiments."
99
authors = [
1010
{ name="Zhipeng Cao", email="[email protected]" }

0 commit comments

Comments
 (0)