-
-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
plugin_meta
, plugin_description
and `plugin_installatio…
…n` macros
- Loading branch information
Showing
12 changed files
with
446 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ dist.zip | |
packages/jspsych/README.md | ||
.turbo | ||
*.pyc | ||
cache.db | ||
docs/__generator__/cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
from pathlib import Path | ||
|
||
from docs.__generator__.plugins import generate_plugin_parameters_section | ||
from docs.__generator__.utils import hash_file | ||
from docs.__generator__.plugins import ( | ||
generate_plugin_author_info, | ||
generate_plugin_installation_section, | ||
generate_plugin_parameters_section, | ||
generate_plugin_summary, | ||
generate_plugin_version_info, | ||
) | ||
|
||
|
||
# https://mkdocs-macros-plugin.readthedocs.io/en/latest/macros/ | ||
def define_env(env): | ||
@env.macro | ||
def plugin_parameters(plugin: str): | ||
return generate_plugin_parameters_section(Path(f"packages/plugin-{plugin}")) | ||
|
||
@env.macro | ||
def plugin_description(plugin: str): | ||
return generate_plugin_summary(Path(f"packages/plugin-{plugin}")) | ||
|
||
@env.macro | ||
def plugin_meta(plugin: str): | ||
plugin_dir = Path(f"packages/plugin-{plugin}") | ||
return f"{generate_plugin_version_info(plugin_dir)} {generate_plugin_author_info(plugin_dir)}\n" | ||
|
||
return generate_plugin_parameters_section( | ||
plugin_dir, hash_file(plugin_dir / "src/index.ts") | ||
) | ||
@env.macro | ||
def plugin_installation(plugin: str): | ||
return generate_plugin_installation_section(Path(f"packages/plugin-{plugin}")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,8 @@ | ||
# audio-button-response | ||
|
||
Current version: 1.1.2. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-audio-button-response/CHANGELOG.md). | ||
|
||
This plugin plays audio files and records responses generated with a button click. | ||
|
||
If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio. | ||
|
||
Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using timeline variables or another dynamic method to specify the audio stimulus, you will need to [manually preload](../overview/media-preloading.md#manual-preloading) the audio. | ||
|
||
The trial can end when the participant responds, when the audio file has finished playing, or if the participant has failed to respond within a fixed length of time. You can also prevent a button response from being made before the audio has finished playing. | ||
|
||
## Parameters | ||
|
||
In addition to the [parameters available in all plugins](../overview/plugins.md#parameters-available-in-all-plugins), this plugin accepts the following parameters. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. | ||
|
||
| Parameter | Type | Default Value | Description | | ||
| ------------------------------ | ---------------- | ---------------------------------------- | ---------------------------------------- | | ||
| stimulus | audio file | *undefined* | Path to audio file to be played. | | ||
| choices | array of strings | *undefined* | Labels for the buttons. Each different string in the array will generate a different button. | | ||
| button_html | HTML string | `'<button class="jspsych-btn">%choice%</button>'` | A template of HTML for generating the button elements. You can override this to create customized buttons of various kinds. The string `%choice%` will be changed to the corresponding element of the `choices` array. You may also specify an array of strings, if you need different HTML to render for each button. If you do specify an array, the `choices` array and this array must have the same length. The HTML from position 0 in the `button_html` array will be used to create the button for element 0 in the `choices` array, and so on. | | ||
| prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). | | ||
| trial_duration | numeric | null | How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant fails to make a response before this timer is reached, the participant's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial will wait for a response indefinitely. | | ||
| margin_vertical | string | '0px' | Vertical margin of the button(s). | | ||
| margin_horizontal | string | '8px' | Horizontal margin of the button(s). | | ||
| response_ends_trial | boolean | true | If true, then the trial will end whenever the participant makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. | | ||
| trial_ends_after_audio | boolean | false | If true, then the trial will end as soon as the audio file finishes playing. | | ||
| response_allowed_while_playing | boolean | true | If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before the button choices are enabled and a response is accepted. Once the audio has played all the way through, the buttons are enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls). | | ||
{{ plugin_meta('audio-button-response') }} | ||
{{ plugin_description('audio-button-response') }} | ||
{{ plugin_parameters('audio-button-response') }} | ||
|
||
## Data Generated | ||
|
||
|
@@ -42,28 +19,7 @@ In `data-only` simulation mode, the `response_allowed_while_playing` parameter d | |
This is because the audio file is not loaded in `data-only` mode and therefore the length is unknown. | ||
This may change in a future version as we improve the simulation modes. | ||
|
||
## Install | ||
|
||
Using the CDN-hosted JavaScript file: | ||
|
||
```js | ||
<script src="https://unpkg.com/@jspsych/[email protected]"></script> | ||
``` | ||
|
||
Using the JavaScript file downloaded from a GitHub release dist archive: | ||
|
||
```js | ||
<script src="jspsych/plugin-audio-button-response.js"></script> | ||
``` | ||
|
||
Using NPM: | ||
|
||
``` | ||
npm install @jspsych/plugin-audio-button-response | ||
``` | ||
```js | ||
import audioButtonResponse from '@jspsych/plugin-audio-button-response'; | ||
``` | ||
{{ plugin_installation('audio-button-response') }} | ||
|
||
## Examples | ||
|
||
|
Oops, something went wrong.