Skip to content

Simple auditory and visual stimuli that do not require PsychoPy.

License

Notifications You must be signed in to change notification settings

mscheltienne/stimuli

Repository files navigation

Ruff Code style: black Imports: isort codecov tests doc PyPI version Downloads Conda Version Conda Downloads Conda Platforms

Stimuli

This repository contains auditory and visual stimuli that do not require PsychoPy. The auditory stimuli use the python sounddevice library and the visual stimuli use the python opencv library.

Installation

This repository is available for python ≥ 3.8 on pip with the command pip install stimuli or on conda-forge with the command conda install -c conda-forge stimuli.

Usage

Audio stimulus

from stimuli.audio import Tone

sound = Tone(volume=80, frequency=1000)
sound.play()

The volume can be set independently for each channel (stereo) by providing a tuple (L, R).

Visual stimulus

Visual stimulus can be grouped into 2 categories:

  • simple visuals that are drawn on top of each other
  • feedback visuals that are drawn once and updated

Simple visual

from stimuli.visuals import Text

visual = Text()
visual.background = "lightgrey"  # equivalent to visual.draw_background()
visual.putText("Top secret not-so-secret instructions!")
visual.show()

Feedback visual

import numpy as np

from stimuli.visuals import FillingBar

visual = FillingBar()
visual.background = "lightgrey"  # equivalent to visual.draw_background()
visual.putBar(length=200, width=20, margin=2, color="black", fill_color="teal")

for k in np.arange(0, 1, 0.1):
    visual.fill_perc = k  # update the visual
    visual.show(100)  # wait 100 ms

visual.close()