@jspsych/plugin-audio-keyboard-response 1.1.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +266 -235
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +199 -220
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +109 -26
- package/dist/index.js +199 -220
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +123 -3
- package/src/index.ts +145 -133
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.min.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nconst info = <const>{\n name: \"audio-keyboard-response\",\n parameters: {\n /** The audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */\n choices: {\n type: ParameterType.KEYS,\n pretty_name: \"Choices\",\n default: \"ALL_KEYS\",\n },\n /** Any content here will be displayed below the stimulus. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** The maximum duration to wait for a response. */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /** If true, the trial will end when user makes a response. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n pretty_name: \"Response ends trial\",\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n pretty_name: \"Trial ends after audio\",\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n pretty_name: \"Response allowed while playing\",\n default: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **audio-keyboard-response**\n *\n * jsPsych plugin for playing an audio file and getting a keyboard response\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-audio-keyboard-response/ audio-keyboard-response plugin documentation on jspsych.org}\n */\nclass AudioKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // hold the .resolve() function from the Promise that ends the trial\n let trial_complete;\n\n // setup stimulus\n var context = this.jsPsych.pluginAPI.audioContext();\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // record webaudio context start time\n var startTime;\n\n // load audio file\n this.jsPsych.pluginAPI\n .getAudioBuffer(trial.stimulus)\n .then((buffer) => {\n if (context !== null) {\n this.audio = context.createBufferSource();\n this.audio.buffer = buffer;\n this.audio.connect(context.destination);\n } else {\n this.audio = buffer;\n this.audio.currentTime = 0;\n }\n setupTrial();\n })\n .catch((err) => {\n console.error(\n `Failed to load audio file \"${trial.stimulus}\". Try checking the file path. We recommend using the preload plugin to load audio files.`\n );\n console.error(err);\n });\n\n const setupTrial = () => {\n // set up end event if trial needs it\n if (trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", end_trial);\n }\n\n // show prompt if there is one\n if (trial.prompt !== null) {\n display_element.innerHTML = trial.prompt;\n }\n\n // start audio\n if (context !== null) {\n startTime = context.currentTime;\n this.audio.start(startTime);\n } else {\n this.audio.play();\n }\n\n // start keyboard listener when trial starts or sound ends\n if (trial.response_allowed_while_playing) {\n setup_keyboard_listener();\n } else if (!trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", setup_keyboard_listener);\n }\n\n // end trial if time limit is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n end_trial();\n }, trial.trial_duration);\n }\n\n on_load();\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n // remove end event listeners if they exist\n if (context !== null) {\n this.audio.stop();\n } else {\n this.audio.pause();\n }\n\n this.audio.removeEventListener(\"ended\", end_trial);\n this.audio.removeEventListener(\"ended\", setup_keyboard_listener);\n\n // kill keyboard listeners\n this.jsPsych.pluginAPI.cancelAllKeyboardResponses();\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // clear the display\n display_element.innerHTML = \"\";\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n\n trial_complete();\n };\n\n // function to handle responses by the subject\n function after_response(info) {\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n }\n\n const setup_keyboard_listener = () => {\n // start the response listener\n if (context !== null) {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"audio\",\n persist: false,\n allow_held_key: false,\n audio_context: context,\n audio_context_start_time: startTime,\n });\n } else {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n };\n\n return new Promise((resolve) => {\n trial_complete = resolve;\n });\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n}\n\nexport default AudioKeyboardResponsePlugin;\n"],"names":["info","name","parameters","stimulus","type","ParameterType","AUDIO","pretty_name","default","undefined","choices","KEYS","prompt","HTML_STRING","trial_duration","INT","response_ends_trial","BOOL","trial_ends_after_audio","response_allowed_while_playing","AudioKeyboardResponsePlugin","jsPsych","_classCallCheck","this","key","value","display_element","trial","on_load","trial_complete","startTime","_this","context","pluginAPI","audioContext","response","rt","getAudioBuffer","then","buffer","audio","createBufferSource","connect","destination","currentTime","setupTrial","err","console","error","concat","addEventListener","end_trial","innerHTML","start","play","setup_keyboard_listener","setTimeout","clearAllTimeouts","stop","pause","removeEventListener","cancelAllKeyboardResponses","trial_data","finishTrial","after_response","getKeyboardResponse","callback_function","valid_responses","rt_method","persist","allow_held_key","audio_context","audio_context_start_time","Promise","resolve","simulation_mode","simulation_options","load_callback","simulate_data_only","simulate_visual","data","create_simulation_data","_this2","getDisplayElement","respond","pressKey","default_data","randomization","sampleExGaussian","getValidKey","mergeSimulationData","ensureSimulationDataConsistency"],"mappings":"yiBAEA,IAAMA,EAAc,CAClBC,KAAM,0BACNC,WAAY,CAEVC,SAAU,CACRC,KAAMC,EAAaA,cAACC,MACpBC,YAAa,WACbC,aAASC,GAGXC,QAAS,CACPN,KAAMC,EAAaA,cAACM,KACpBJ,YAAa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AAuBtD,EAAOiD,GAEhDrD,KAAKF,QAAQ0C,YAAYiB,EAC3B,GAAC,CAAAxD,IAAA,kBAAAC,MAEO,SAAgBE,EAAwBiD,EAAoBC,GAAyB,IAAAK,EAAA3D,KACrFyD,EAAOzD,KAAK0D,uBAAuBtD,EAAOiD,GAE1ClD,EAAkBH,KAAKF,QAAQ8D,oBAE/BC,EAAU,WACE,OAAZJ,EAAK5C,IACP8C,EAAK7D,QAAQY,UAAUoD,SAASL,EAAK7C,SAAU6C,EAAK5C,KAIxDb,KAAKI,MAAMD,EAAiBC,GAAO,WACjCkD,IACKlD,EAAMR,+BAGTiE,IAFAF,EAAK1C,MAAMU,iBAAiB,QAASkC,EAIzC,GACF,GAAC,CAAA5D,IAAA,yBAAAC,MAEO,SAAuBE,EAAwBiD,GACrD,IAAMU,EAAe,CACnBnF,SAAUwB,EAAMxB,SAChBiC,GAAIb,KAAKF,QAAQkE,cAAcC,iBAAiB,IAAK,GAAI,EAAI,KAAK,GAClErD,SAAUZ,KAAKF,QAAQY,UAAUwD,YAAY9D,EAAMjB,UAG/CsE,EAAOzD,KAAKF,QAAQY,UAAUyD,oBAAoBJ,EAAcV,GAItE,OAFArD,KAAKF,QAAQY,UAAU0D,gCAAgChE,EAAOqD,GAEvDA,CACT,qFAAC5D,CAAA,CAhN8B,UACxBA,EAAIpB,KAAGA"}
|
|
1
|
+
{"version":3,"file":"index.browser.min.js","sources":["../../../node_modules/auto-bind/index.js","../src/index.ts"],"sourcesContent":["'use strict';\n\n// Gets all non-builtin properties up the prototype chain\nconst getAllProperties = object => {\n\tconst properties = new Set();\n\n\tdo {\n\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\tproperties.add([object, key]);\n\t\t}\n\t} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);\n\n\treturn properties;\n};\n\nmodule.exports = (self, {include, exclude} = {}) => {\n\tconst filter = key => {\n\t\tconst match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);\n\n\t\tif (include) {\n\t\t\treturn include.some(match);\n\t\t}\n\n\t\tif (exclude) {\n\t\t\treturn !exclude.some(match);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tfor (const [object, key] of getAllProperties(self.constructor.prototype)) {\n\t\tif (key === 'constructor' || !filter(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (descriptor && typeof descriptor.value === 'function') {\n\t\t\tself[key] = self[key].bind(self);\n\t\t}\n\t}\n\n\treturn self;\n};\n","import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-keyboard-response\",\n version: version,\n parameters: {\n /** The audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)\n * for more examples. Any key presses that are not listed in the array will be ignored. The default value of `\"ALL_KEYS\"`\n * means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean that no responses are allowed.\n */\n choices: {\n type: ParameterType.KEYS,\n default: \"ALL_KEYS\",\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that\n * it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the\n * participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the\n * trial will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use set this parameter to `false` to\n * force the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n pretty_name: \"Trial ends after audio\",\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish\n * playing before a keyboard response is accepted. Once the audio has played all the way through, a valid\n * keyboard response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** Indicates which key the participant pressed. If no key was pressed before the trial ended, then the value will be `null`. */\n response: {\n type: ParameterType.STRING,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus\n * first began playing until the participant made a key response. If no key was pressed before the trial ended, then the\n * value will be `null`.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** Path to the audio file that played during the trial. */\n stimulus: {\n type: ParameterType.STRING,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays audio files and records responses generated with the keyboard.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, when the audio file has finished playing, or if the participant has\n * failed to respond within a fixed length of time. You can also prevent a keyboard response from being recorded before\n * the audio has finished playing.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-keyboard-response/ audio-keyboard-response plugin documentation on jspsych.org}\n */\nclass AudioKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; key: string } = { rt: null, key: null };\n private startTime: number;\n private finish: ({}: { rt: number; response: string; stimulus: string }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n return new Promise(async (resolve) => {\n this.finish = resolve;\n this.params = trial;\n this.display = display_element;\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n // set up end event if trial needs it\n if (trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // show prompt if there is one\n if (trial.prompt !== null) {\n display_element.innerHTML = trial.prompt;\n }\n\n // start playing audio here to record time\n // use this for offsetting RT measurement in\n // setup_keyboard_listener\n this.startTime = this.jsPsych.pluginAPI.audioContext()?.currentTime;\n\n // start keyboard listener when trial starts or sound ends\n if (trial.response_allowed_while_playing) {\n this.setup_keyboard_listener();\n } else if (!trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.setup_keyboard_listener);\n }\n\n // end trial if time limit is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, trial.trial_duration);\n }\n\n // call trial on_load method because we are done with all loading setup\n on_load();\n\n this.audio.play();\n });\n }\n\n private end_trial() {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.setup_keyboard_listener);\n\n // kill keyboard listeners\n this.jsPsych.pluginAPI.cancelAllKeyboardResponses();\n\n // gather the data to store for the trial\n var trial_data = {\n rt: this.response.rt,\n response: this.response.key,\n stimulus: this.params.stimulus,\n };\n\n // clear the display\n this.display.innerHTML = \"\";\n\n // move on to the next trial\n this.finish(trial_data);\n }\n\n private after_response(info: { key: string; rt: number }) {\n this.response = info;\n if (this.params.response_ends_trial) {\n this.end_trial();\n }\n }\n\n private setup_keyboard_listener() {\n // start the response listener\n if (this.jsPsych.pluginAPI.useWebaudio) {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: this.after_response,\n valid_responses: this.params.choices,\n rt_method: \"audio\",\n persist: false,\n allow_held_key: false,\n audio_context: this.jsPsych.pluginAPI.audioContext(),\n audio_context_start_time: this.startTime,\n });\n } else {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: this.after_response,\n valid_responses: this.params.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n }\n\n async simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n return this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n return this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n return data;\n }\n\n private async simulate_visual(\n trial: TrialType<Info>,\n simulation_options,\n load_callback: () => void\n ) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n };\n\n const result = await this.trial(display_element, trial, () => {\n load_callback();\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n\n return result;\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n}\n\nexport default AudioKeyboardResponsePlugin;\n"],"names":["getAllProperties","object","properties","key","autoBind","self","include","exclude","filter","match","pattern","descriptor","info","version","ParameterType","AudioKeyboardResponsePlugin","jsPsych","display_element","trial","on_load","resolve","__async","_a","trial_data","simulation_mode","simulation_options","load_callback","data","respond","default_data"],"mappings":"8JAGA,MAAMA,EAAmBC,GAAU,CAClC,MAAMC,EAAa,IAAI,IAEvB,EACC,WAAWC,KAAO,QAAQ,QAAQF,CAAM,EACvCC,EAAW,IAAI,CAACD,EAAQE,CAAG,CAAC,SAEpBF,EAAS,QAAQ,eAAeA,CAAM,IAAMA,IAAW,OAAO,WAExE,OAAOC,CACR,MAEAE,EAAiB,CAACC,EAAM,CAAC,QAAAC,EAAS,QAAAC,CAAO,EAAI,CAAA,IAAO,CACnD,MAAMC,EAASL,GAAO,CACrB,MAAMM,EAAQC,GAAW,OAAOA,GAAY,SAAWP,IAAQO,EAAUA,EAAQ,KAAKP,CAAG,EAEzF,OAAIG,EACIA,EAAQ,KAAKG,CAAK,EAGtBF,EACI,CAACA,EAAQ,KAAKE,CAAK,EAGpB,EACT,EAEC,SAAW,CAACR,EAAQE,CAAG,IAAKH,EAAiBK,EAAK,YAAY,SAAS,EAAG,CACzE,GAAIF,IAAQ,eAAiB,CAACK,EAAOL,CAAG,EACvC,SAGD,MAAMQ,EAAa,QAAQ,yBAAyBV,EAAQE,CAAG,EAC3DQ,GAAc,OAAOA,EAAW,OAAU,aAC7CN,EAAKF,GAAOE,EAAKF,GAAK,KAAKE,CAAI,EAEhC,CAED,OAAOA,CACR,6kCCpCA,MAAMO,EAAc,CAClB,KAAM,0BACN,QAASC,EAAAA,QACT,WAAY,CAEV,S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P,EAAOO,CAAkB,CAGpE,CAEc,gBACZP,EACAO,EACAC,EACA,CAAAL,OAAAA,EAAA,KACA,KAAA,WAAA,CAAA,MAAMM,EAAO,KAAK,uBAAuBT,EAAOO,CAAkB,EAE5DR,EAAkB,KAAK,QAAQ,kBAAkB,EAEjDW,EAAU,IAAM,CAChBD,EAAK,KAAO,MACd,KAAK,QAAQ,UAAU,SAASA,EAAK,SAAUA,EAAK,EAAE,CAE1D,EAWA,OATe,MAAM,KAAK,MAAMV,EAAiBC,EAAO,IAAM,CAC5DQ,EAAc,EACTR,EAAM,+BAGTU,IAFA,KAAK,MAAM,iBAAiB,QAASA,CAAO,CAIhD,CAAC,CAGH,CAAA,CAAA,CAEQ,uBAAuBV,EAAwBO,EAAoB,CACzE,MAAMI,EAAe,CACnB,SAAUX,EAAM,SAChB,GAAI,KAAK,QAAQ,cAAc,iBAAiB,IAAK,GAAI,oBAAS,EAAI,EACtE,SAAU,KAAK,QAAQ,UAAU,YAAYA,EAAM,OAAO,CAC5D,EAEMS,EAAO,KAAK,QAAQ,UAAU,oBAAoBE,EAAcJ,CAAkB,EAExF,OAAA,KAAK,QAAQ,UAAU,gCAAgCP,EAAOS,CAAI,EAE3DA,CACT,CACF,CAhLMZ,SACG,KAAOH"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,235 +1,214 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var autoBind = require('auto-bind');
|
|
3
4
|
var jspsych = require('jspsych');
|
|
4
5
|
|
|
6
|
+
var _package = {
|
|
7
|
+
name: "@jspsych/plugin-audio-keyboard-response",
|
|
8
|
+
version: "2.0.0",
|
|
9
|
+
description: "jsPsych plugin for playing an audio file and getting a keyboard response",
|
|
10
|
+
type: "module",
|
|
11
|
+
main: "dist/index.cjs",
|
|
12
|
+
exports: {
|
|
13
|
+
import: "./dist/index.js",
|
|
14
|
+
require: "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
typings: "dist/index.d.ts",
|
|
17
|
+
unpkg: "dist/index.browser.min.js",
|
|
18
|
+
files: [
|
|
19
|
+
"src",
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
source: "src/index.ts",
|
|
23
|
+
scripts: {
|
|
24
|
+
test: "jest",
|
|
25
|
+
"test:watch": "npm test -- --watch",
|
|
26
|
+
tsc: "tsc",
|
|
27
|
+
build: "rollup --config",
|
|
28
|
+
"build:watch": "npm run build -- --watch"
|
|
29
|
+
},
|
|
30
|
+
repository: {
|
|
31
|
+
type: "git",
|
|
32
|
+
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
33
|
+
directory: "packages/plugin-audio-keyboard-response"
|
|
34
|
+
},
|
|
35
|
+
author: "Josh de Leeuw",
|
|
36
|
+
license: "MIT",
|
|
37
|
+
bugs: {
|
|
38
|
+
url: "https://github.com/jspsych/jsPsych/issues"
|
|
39
|
+
},
|
|
40
|
+
homepage: "https://www.jspsych.org/latest/plugins/audio-keyboard-response",
|
|
41
|
+
peerDependencies: {
|
|
42
|
+
jspsych: ">=7.1.0"
|
|
43
|
+
},
|
|
44
|
+
devDependencies: {
|
|
45
|
+
"@jspsych/config": "^3.0.0",
|
|
46
|
+
"@jspsych/test-utils": "^1.2.0"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
5
50
|
const info = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
default: undefined,
|
|
13
|
-
},
|
|
14
|
-
/** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
|
|
15
|
-
choices: {
|
|
16
|
-
type: jspsych.ParameterType.KEYS,
|
|
17
|
-
pretty_name: "Choices",
|
|
18
|
-
default: "ALL_KEYS",
|
|
19
|
-
},
|
|
20
|
-
/** Any content here will be displayed below the stimulus. */
|
|
21
|
-
prompt: {
|
|
22
|
-
type: jspsych.ParameterType.HTML_STRING,
|
|
23
|
-
pretty_name: "Prompt",
|
|
24
|
-
default: null,
|
|
25
|
-
},
|
|
26
|
-
/** The maximum duration to wait for a response. */
|
|
27
|
-
trial_duration: {
|
|
28
|
-
type: jspsych.ParameterType.INT,
|
|
29
|
-
pretty_name: "Trial duration",
|
|
30
|
-
default: null,
|
|
31
|
-
},
|
|
32
|
-
/** If true, the trial will end when user makes a response. */
|
|
33
|
-
response_ends_trial: {
|
|
34
|
-
type: jspsych.ParameterType.BOOL,
|
|
35
|
-
pretty_name: "Response ends trial",
|
|
36
|
-
default: true,
|
|
37
|
-
},
|
|
38
|
-
/** If true, then the trial will end as soon as the audio file finishes playing. */
|
|
39
|
-
trial_ends_after_audio: {
|
|
40
|
-
type: jspsych.ParameterType.BOOL,
|
|
41
|
-
pretty_name: "Trial ends after audio",
|
|
42
|
-
default: false,
|
|
43
|
-
},
|
|
44
|
-
/** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */
|
|
45
|
-
response_allowed_while_playing: {
|
|
46
|
-
type: jspsych.ParameterType.BOOL,
|
|
47
|
-
pretty_name: "Response allowed while playing",
|
|
48
|
-
default: true,
|
|
49
|
-
},
|
|
51
|
+
name: "audio-keyboard-response",
|
|
52
|
+
version: _package.version,
|
|
53
|
+
parameters: {
|
|
54
|
+
stimulus: {
|
|
55
|
+
type: jspsych.ParameterType.AUDIO,
|
|
56
|
+
default: void 0
|
|
50
57
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
choices: {
|
|
59
|
+
type: jspsych.ParameterType.KEYS,
|
|
60
|
+
default: "ALL_KEYS"
|
|
61
|
+
},
|
|
62
|
+
prompt: {
|
|
63
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
64
|
+
pretty_name: "Prompt",
|
|
65
|
+
default: null
|
|
66
|
+
},
|
|
67
|
+
trial_duration: {
|
|
68
|
+
type: jspsych.ParameterType.INT,
|
|
69
|
+
default: null
|
|
70
|
+
},
|
|
71
|
+
response_ends_trial: {
|
|
72
|
+
type: jspsych.ParameterType.BOOL,
|
|
73
|
+
default: true
|
|
74
|
+
},
|
|
75
|
+
trial_ends_after_audio: {
|
|
76
|
+
type: jspsych.ParameterType.BOOL,
|
|
77
|
+
pretty_name: "Trial ends after audio",
|
|
78
|
+
default: false
|
|
79
|
+
},
|
|
80
|
+
response_allowed_while_playing: {
|
|
81
|
+
type: jspsych.ParameterType.BOOL,
|
|
82
|
+
default: true
|
|
63
83
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// record webaudio context start time
|
|
75
|
-
var startTime;
|
|
76
|
-
// load audio file
|
|
77
|
-
this.jsPsych.pluginAPI
|
|
78
|
-
.getAudioBuffer(trial.stimulus)
|
|
79
|
-
.then((buffer) => {
|
|
80
|
-
if (context !== null) {
|
|
81
|
-
this.audio = context.createBufferSource();
|
|
82
|
-
this.audio.buffer = buffer;
|
|
83
|
-
this.audio.connect(context.destination);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this.audio = buffer;
|
|
87
|
-
this.audio.currentTime = 0;
|
|
88
|
-
}
|
|
89
|
-
setupTrial();
|
|
90
|
-
})
|
|
91
|
-
.catch((err) => {
|
|
92
|
-
console.error(`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`);
|
|
93
|
-
console.error(err);
|
|
94
|
-
});
|
|
95
|
-
const setupTrial = () => {
|
|
96
|
-
// set up end event if trial needs it
|
|
97
|
-
if (trial.trial_ends_after_audio) {
|
|
98
|
-
this.audio.addEventListener("ended", end_trial);
|
|
99
|
-
}
|
|
100
|
-
// show prompt if there is one
|
|
101
|
-
if (trial.prompt !== null) {
|
|
102
|
-
display_element.innerHTML = trial.prompt;
|
|
103
|
-
}
|
|
104
|
-
// start audio
|
|
105
|
-
if (context !== null) {
|
|
106
|
-
startTime = context.currentTime;
|
|
107
|
-
this.audio.start(startTime);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this.audio.play();
|
|
111
|
-
}
|
|
112
|
-
// start keyboard listener when trial starts or sound ends
|
|
113
|
-
if (trial.response_allowed_while_playing) {
|
|
114
|
-
setup_keyboard_listener();
|
|
115
|
-
}
|
|
116
|
-
else if (!trial.trial_ends_after_audio) {
|
|
117
|
-
this.audio.addEventListener("ended", setup_keyboard_listener);
|
|
118
|
-
}
|
|
119
|
-
// end trial if time limit is set
|
|
120
|
-
if (trial.trial_duration !== null) {
|
|
121
|
-
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
122
|
-
end_trial();
|
|
123
|
-
}, trial.trial_duration);
|
|
124
|
-
}
|
|
125
|
-
on_load();
|
|
126
|
-
};
|
|
127
|
-
// function to end trial when it is time
|
|
128
|
-
const end_trial = () => {
|
|
129
|
-
// kill any remaining setTimeout handlers
|
|
130
|
-
this.jsPsych.pluginAPI.clearAllTimeouts();
|
|
131
|
-
// stop the audio file if it is playing
|
|
132
|
-
// remove end event listeners if they exist
|
|
133
|
-
if (context !== null) {
|
|
134
|
-
this.audio.stop();
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
this.audio.pause();
|
|
138
|
-
}
|
|
139
|
-
this.audio.removeEventListener("ended", end_trial);
|
|
140
|
-
this.audio.removeEventListener("ended", setup_keyboard_listener);
|
|
141
|
-
// kill keyboard listeners
|
|
142
|
-
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
|
143
|
-
// gather the data to store for the trial
|
|
144
|
-
var trial_data = {
|
|
145
|
-
rt: response.rt,
|
|
146
|
-
stimulus: trial.stimulus,
|
|
147
|
-
response: response.key,
|
|
148
|
-
};
|
|
149
|
-
// clear the display
|
|
150
|
-
display_element.innerHTML = "";
|
|
151
|
-
// move on to the next trial
|
|
152
|
-
this.jsPsych.finishTrial(trial_data);
|
|
153
|
-
trial_complete();
|
|
154
|
-
};
|
|
155
|
-
// function to handle responses by the subject
|
|
156
|
-
function after_response(info) {
|
|
157
|
-
// only record the first response
|
|
158
|
-
if (response.key == null) {
|
|
159
|
-
response = info;
|
|
160
|
-
}
|
|
161
|
-
if (trial.response_ends_trial) {
|
|
162
|
-
end_trial();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const setup_keyboard_listener = () => {
|
|
166
|
-
// start the response listener
|
|
167
|
-
if (context !== null) {
|
|
168
|
-
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
169
|
-
callback_function: after_response,
|
|
170
|
-
valid_responses: trial.choices,
|
|
171
|
-
rt_method: "audio",
|
|
172
|
-
persist: false,
|
|
173
|
-
allow_held_key: false,
|
|
174
|
-
audio_context: context,
|
|
175
|
-
audio_context_start_time: startTime,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
180
|
-
callback_function: after_response,
|
|
181
|
-
valid_responses: trial.choices,
|
|
182
|
-
rt_method: "performance",
|
|
183
|
-
persist: false,
|
|
184
|
-
allow_held_key: false,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
return new Promise((resolve) => {
|
|
189
|
-
trial_complete = resolve;
|
|
190
|
-
});
|
|
84
|
+
},
|
|
85
|
+
data: {
|
|
86
|
+
response: {
|
|
87
|
+
type: jspsych.ParameterType.STRING
|
|
88
|
+
},
|
|
89
|
+
rt: {
|
|
90
|
+
type: jspsych.ParameterType.INT
|
|
91
|
+
},
|
|
92
|
+
stimulus: {
|
|
93
|
+
type: jspsych.ParameterType.STRING
|
|
191
94
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
class AudioKeyboardResponsePlugin {
|
|
98
|
+
constructor(jsPsych) {
|
|
99
|
+
this.jsPsych = jsPsych;
|
|
100
|
+
this.response = { rt: null, key: null };
|
|
101
|
+
autoBind(this);
|
|
102
|
+
}
|
|
103
|
+
trial(display_element, trial, on_load) {
|
|
104
|
+
return new Promise(async (resolve) => {
|
|
105
|
+
this.finish = resolve;
|
|
106
|
+
this.params = trial;
|
|
107
|
+
this.display = display_element;
|
|
108
|
+
this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);
|
|
109
|
+
if (trial.trial_ends_after_audio) {
|
|
110
|
+
this.audio.addEventListener("ended", this.end_trial);
|
|
111
|
+
}
|
|
112
|
+
if (trial.prompt !== null) {
|
|
113
|
+
display_element.innerHTML = trial.prompt;
|
|
114
|
+
}
|
|
115
|
+
this.startTime = this.jsPsych.pluginAPI.audioContext()?.currentTime;
|
|
116
|
+
if (trial.response_allowed_while_playing) {
|
|
117
|
+
this.setup_keyboard_listener();
|
|
118
|
+
} else if (!trial.trial_ends_after_audio) {
|
|
119
|
+
this.audio.addEventListener("ended", this.setup_keyboard_listener);
|
|
120
|
+
}
|
|
121
|
+
if (trial.trial_duration !== null) {
|
|
122
|
+
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
123
|
+
this.end_trial();
|
|
124
|
+
}, trial.trial_duration);
|
|
125
|
+
}
|
|
126
|
+
on_load();
|
|
127
|
+
this.audio.play();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
end_trial() {
|
|
131
|
+
this.jsPsych.pluginAPI.clearAllTimeouts();
|
|
132
|
+
this.audio.stop();
|
|
133
|
+
this.audio.removeEventListener("ended", this.end_trial);
|
|
134
|
+
this.audio.removeEventListener("ended", this.setup_keyboard_listener);
|
|
135
|
+
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
|
136
|
+
var trial_data = {
|
|
137
|
+
rt: this.response.rt,
|
|
138
|
+
response: this.response.key,
|
|
139
|
+
stimulus: this.params.stimulus
|
|
140
|
+
};
|
|
141
|
+
this.display.innerHTML = "";
|
|
142
|
+
this.finish(trial_data);
|
|
143
|
+
}
|
|
144
|
+
after_response(info2) {
|
|
145
|
+
this.response = info2;
|
|
146
|
+
if (this.params.response_ends_trial) {
|
|
147
|
+
this.end_trial();
|
|
200
148
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
149
|
+
}
|
|
150
|
+
setup_keyboard_listener() {
|
|
151
|
+
if (this.jsPsych.pluginAPI.useWebaudio) {
|
|
152
|
+
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
153
|
+
callback_function: this.after_response,
|
|
154
|
+
valid_responses: this.params.choices,
|
|
155
|
+
rt_method: "audio",
|
|
156
|
+
persist: false,
|
|
157
|
+
allow_held_key: false,
|
|
158
|
+
audio_context: this.jsPsych.pluginAPI.audioContext(),
|
|
159
|
+
audio_context_start_time: this.startTime
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
163
|
+
callback_function: this.after_response,
|
|
164
|
+
valid_responses: this.params.choices,
|
|
165
|
+
rt_method: "performance",
|
|
166
|
+
persist: false,
|
|
167
|
+
allow_held_key: false
|
|
168
|
+
});
|
|
204
169
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
this.trial(display_element, trial, () => {
|
|
214
|
-
load_callback();
|
|
215
|
-
if (!trial.response_allowed_while_playing) {
|
|
216
|
-
this.audio.addEventListener("ended", respond);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
respond();
|
|
220
|
-
}
|
|
221
|
-
});
|
|
170
|
+
}
|
|
171
|
+
async simulate(trial, simulation_mode, simulation_options, load_callback) {
|
|
172
|
+
if (simulation_mode == "data-only") {
|
|
173
|
+
load_callback();
|
|
174
|
+
return this.simulate_data_only(trial, simulation_options);
|
|
222
175
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
stimulus: trial.stimulus,
|
|
226
|
-
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
227
|
-
response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
|
|
228
|
-
};
|
|
229
|
-
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
230
|
-
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
231
|
-
return data;
|
|
176
|
+
if (simulation_mode == "visual") {
|
|
177
|
+
return this.simulate_visual(trial, simulation_options, load_callback);
|
|
232
178
|
}
|
|
179
|
+
}
|
|
180
|
+
simulate_data_only(trial, simulation_options) {
|
|
181
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
182
|
+
return data;
|
|
183
|
+
}
|
|
184
|
+
async simulate_visual(trial, simulation_options, load_callback) {
|
|
185
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
186
|
+
const display_element = this.jsPsych.getDisplayElement();
|
|
187
|
+
const respond = () => {
|
|
188
|
+
if (data.rt !== null) {
|
|
189
|
+
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const result = await this.trial(display_element, trial, () => {
|
|
193
|
+
load_callback();
|
|
194
|
+
if (!trial.response_allowed_while_playing) {
|
|
195
|
+
this.audio.addEventListener("ended", respond);
|
|
196
|
+
} else {
|
|
197
|
+
respond();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
create_simulation_data(trial, simulation_options) {
|
|
203
|
+
const default_data = {
|
|
204
|
+
stimulus: trial.stimulus,
|
|
205
|
+
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
206
|
+
response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
|
|
207
|
+
};
|
|
208
|
+
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
209
|
+
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
210
|
+
return data;
|
|
211
|
+
}
|
|
233
212
|
}
|
|
234
213
|
AudioKeyboardResponsePlugin.info = info;
|
|
235
214
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nconst info = <const>{\n name: \"audio-keyboard-response\",\n parameters: {\n /** The audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */\n choices: {\n type: ParameterType.KEYS,\n pretty_name: \"Choices\",\n default: \"ALL_KEYS\",\n },\n /** Any content here will be displayed below the stimulus. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** The maximum duration to wait for a response. */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /** If true, the trial will end when user makes a response. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n pretty_name: \"Response ends trial\",\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n pretty_name: \"Trial ends after audio\",\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n pretty_name: \"Response allowed while playing\",\n default: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **audio-keyboard-response**\n *\n * jsPsych plugin for playing an audio file and getting a keyboard response\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-audio-keyboard-response/ audio-keyboard-response plugin documentation on jspsych.org}\n */\nclass AudioKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // hold the .resolve() function from the Promise that ends the trial\n let trial_complete;\n\n // setup stimulus\n var context = this.jsPsych.pluginAPI.audioContext();\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // record webaudio context start time\n var startTime;\n\n // load audio file\n this.jsPsych.pluginAPI\n .getAudioBuffer(trial.stimulus)\n .then((buffer) => {\n if (context !== null) {\n this.audio = context.createBufferSource();\n this.audio.buffer = buffer;\n this.audio.connect(context.destination);\n } else {\n this.audio = buffer;\n this.audio.currentTime = 0;\n }\n setupTrial();\n })\n .catch((err) => {\n console.error(\n `Failed to load audio file \"${trial.stimulus}\". Try checking the file path. We recommend using the preload plugin to load audio files.`\n );\n console.error(err);\n });\n\n const setupTrial = () => {\n // set up end event if trial needs it\n if (trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", end_trial);\n }\n\n // show prompt if there is one\n if (trial.prompt !== null) {\n display_element.innerHTML = trial.prompt;\n }\n\n // start audio\n if (context !== null) {\n startTime = context.currentTime;\n this.audio.start(startTime);\n } else {\n this.audio.play();\n }\n\n // start keyboard listener when trial starts or sound ends\n if (trial.response_allowed_while_playing) {\n setup_keyboard_listener();\n } else if (!trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", setup_keyboard_listener);\n }\n\n // end trial if time limit is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n end_trial();\n }, trial.trial_duration);\n }\n\n on_load();\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n // remove end event listeners if they exist\n if (context !== null) {\n this.audio.stop();\n } else {\n this.audio.pause();\n }\n\n this.audio.removeEventListener(\"ended\", end_trial);\n this.audio.removeEventListener(\"ended\", setup_keyboard_listener);\n\n // kill keyboard listeners\n this.jsPsych.pluginAPI.cancelAllKeyboardResponses();\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // clear the display\n display_element.innerHTML = \"\";\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n\n trial_complete();\n };\n\n // function to handle responses by the subject\n function after_response(info) {\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n }\n\n const setup_keyboard_listener = () => {\n // start the response listener\n if (context !== null) {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"audio\",\n persist: false,\n allow_held_key: false,\n audio_context: context,\n audio_context_start_time: startTime,\n });\n } else {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n };\n\n return new Promise((resolve) => {\n trial_complete = resolve;\n });\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n}\n\nexport default AudioKeyboardResponsePlugin;\n"],"names":["ParameterType"],"mappings":";;;;AAEA,MAAM,IAAI,GAAU;AAClB,IAAA,IAAI,EAAE,yBAAyB;AAC/B,IAAA,UAAU,EAAE;;AAEV,QAAA,QAAQ,EAAE;YACR,IAAI,EAAEA,qBAAa,CAAC,KAAK;AACzB,YAAA,WAAW,EAAE,UAAU;AACvB,YAAA,OAAO,EAAE,SAAS;AACnB,SAAA;;AAED,QAAA,OAAO,EAAE;YACP,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,OAAO,EAAE,UAAU;AACpB,SAAA;;AAED,QAAA,MAAM,EAAE;YACN,IAAI,EAAEA,qBAAa,CAAC,WAAW;AAC/B,YAAA,WAAW,EAAE,QAAQ;AACrB,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,cAAc,EAAE;YACd,IAAI,EAAEA,qBAAa,CAAC,GAAG;AACvB,YAAA,WAAW,EAAE,gBAAgB;AAC7B,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,mBAAmB,EAAE;YACnB,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,qBAAqB;AAClC,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,sBAAsB,EAAE;YACtB,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,wBAAwB;AACrC,YAAA,OAAO,EAAE,KAAK;AACf,S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,CAAC,CAAC;AAEpE,QAAA,OAAO,IAAI,CAAC;KACb;;AA/MM,2BAAI,CAAA,IAAA,GAAG,IAAI;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-keyboard-response\",\n version: version,\n parameters: {\n /** The audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)\n * for more examples. Any key presses that are not listed in the array will be ignored. The default value of `\"ALL_KEYS\"`\n * means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean that no responses are allowed.\n */\n choices: {\n type: ParameterType.KEYS,\n default: \"ALL_KEYS\",\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that\n * it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the\n * participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the\n * trial will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use set this parameter to `false` to\n * force the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n pretty_name: \"Trial ends after audio\",\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish\n * playing before a keyboard response is accepted. Once the audio has played all the way through, a valid\n * keyboard response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** Indicates which key the participant pressed. If no key was pressed before the trial ended, then the value will be `null`. */\n response: {\n type: ParameterType.STRING,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus\n * first began playing until the participant made a key response. If no key was pressed before the trial ended, then the\n * value will be `null`.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** Path to the audio file that played during the trial. */\n stimulus: {\n type: ParameterType.STRING,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays audio files and records responses generated with the keyboard.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, when the audio file has finished playing, or if the participant has\n * failed to respond within a fixed length of time. You can also prevent a keyboard response from being recorded before\n * the audio has finished playing.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-keyboard-response/ audio-keyboard-response plugin documentation on jspsych.org}\n */\nclass AudioKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; key: string } = { rt: null, key: null };\n private startTime: number;\n private finish: ({}: { rt: number; response: string; stimulus: string }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n return new Promise(async (resolve) => {\n this.finish = resolve;\n this.params = trial;\n this.display = display_element;\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n // set up end event if trial needs it\n if (trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // show prompt if there is one\n if (trial.prompt !== null) {\n display_element.innerHTML = trial.prompt;\n }\n\n // start playing audio here to record time\n // use this for offsetting RT measurement in\n // setup_keyboard_listener\n this.startTime = this.jsPsych.pluginAPI.audioContext()?.currentTime;\n\n // start keyboard listener when trial starts or sound ends\n if (trial.response_allowed_while_playing) {\n this.setup_keyboard_listener();\n } else if (!trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.setup_keyboard_listener);\n }\n\n // end trial if time limit is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, trial.trial_duration);\n }\n\n // call trial on_load method because we are done with all loading setup\n on_load();\n\n this.audio.play();\n });\n }\n\n private end_trial() {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.setup_keyboard_listener);\n\n // kill keyboard listeners\n this.jsPsych.pluginAPI.cancelAllKeyboardResponses();\n\n // gather the data to store for the trial\n var trial_data = {\n rt: this.response.rt,\n response: this.response.key,\n stimulus: this.params.stimulus,\n };\n\n // clear the display\n this.display.innerHTML = \"\";\n\n // move on to the next trial\n this.finish(trial_data);\n }\n\n private after_response(info: { key: string; rt: number }) {\n this.response = info;\n if (this.params.response_ends_trial) {\n this.end_trial();\n }\n }\n\n private setup_keyboard_listener() {\n // start the response listener\n if (this.jsPsych.pluginAPI.useWebaudio) {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: this.after_response,\n valid_responses: this.params.choices,\n rt_method: \"audio\",\n persist: false,\n allow_held_key: false,\n audio_context: this.jsPsych.pluginAPI.audioContext(),\n audio_context_start_time: this.startTime,\n });\n } else {\n this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: this.after_response,\n valid_responses: this.params.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n }\n\n async simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n return this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n return this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n return data;\n }\n\n private async simulate_visual(\n trial: TrialType<Info>,\n simulation_options,\n load_callback: () => void\n ) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n };\n\n const result = await this.trial(display_element, trial, () => {\n load_callback();\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n\n return result;\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n}\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