Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: text to speech with button response and keboard response #143

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

CMonnin
Copy link

@CMonnin CMonnin commented Oct 7, 2024

Description

Extending the two plugins html-button-response and html-keyboard-response as two new plugins text-to-speech-button-response and text-to-speech-keyboard-response using the SpeechSynthesisUtterance API to read a string that is displayed to the participant.
The Google Chrome browser comes with some voices. If using another browser it's most likely necessary to install voices locally. The voice can be set using lang: fr-Fr for example. Default is set to lang: en-US.
These two plugins take a string rather than html as stimulus but otherwise act the same way as the two plugins they extend.

Testing

They pass Jest testing except in one case (and the similar one for the keyboard response:

it("should clear the display after the button has been clicked", async () => {
...}

I think it might be related to the clickTarget function from the test-utils. I tried implementing my own by awaiting a new Promise with setTimeout after invoking jest.useRealTimers() and then invoking jest.useFakeTimers() but couldn't get it to work. Any ideas on this would be greatly appreciated!
I've also included Jest mock functions to test the SpeechSynthesisUtterence in the .spec.ts files.

If there is interest it would be cool to incorporate it into the main jsPsych repo. I'd be happy to work on anything else that is required for incorporating into the main repo.

minimal working examples

MWE can be found in the docs but are provided here for convience:

const trial= {
  lang: 'fr-Fr',
  stimulus: 'This is a string',
  choices: ['Button A', 'Button B'],
  type: TextToSpeechButtonResponse,
};
const trial = {
  stimulus: 'This is a string',
  prompt: 'Press any key to continue',
  lang: 'fr-Fr',
  type: TextToSpeechKeyboardResponse,
};

Best,
Cian

feature: adding keyboard as seperate plugin

refactor: working on testing

refactor: trying to write mock

refactor: text-to-speech passing tests. issue with one test

feature: text to speech keyboard response

chore: docs cleanup

fix: keyboard fix
Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: c19c1d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@jspsych-contrib/plugin-text-to-speech-button-reponse Major
@jspsych-contrib/plugin-text-to-speech-keyboard-response Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant