vkaravir / JSAV

JavaScript Algorithm Visualization library
MIT License
112 stars 40 forks source link

Narration #207

Closed jwonderly closed 6 years ago

jwonderly commented 6 years ago

Adds support for narration of calls to umsg() for slideshows, making use of the SpeechSynthesis functionality of the user's browser.

Narration is disabled by default. It can be enabled globally by setting JSAV_OPTIONS.narrationEnabled = true, and it can be enabled/disabled for an individual slideshow.

Enabling narration will add a button to the left of the settings button that users can click to toggle narration for the slideshow.

When a user clicks the narration button, an event is logged. If clicking the button turns on narration, then jsav-narration-on is logged. If clicking the button turns off narration, then jsav-narration-off is logged.

The vast majority of the work for this feature was done by @ehsanelgendi.

vkaravir commented 6 years ago

Hi @jwonderly, Thank you for working on this! And apologies for taking some time to review.

Overall looks good, but there's one thing I hope you could change before I merge this into master. Currently this will break in browsers that don't support the Speech Synthesis API. I'd like it to check for the support for speechSynthesisand SpeechSynthesisUtterance` before using those features. While JSAV doesn't have a list of officially supported browsers, there's no need for this feature to break older browsers. Could you change the code to check for these?

I'll also comment on a few other things that could be changed but don't need to.

jwonderly commented 6 years ago

Hi Ville, Thanks for the feedback! Sorry it's taken so long for me to address your comments; I've had a busy week.

Here's a summary of the changes I made in response to your comments:

If a developer wants to extend the default list for a single visualization, then they can do:

var avOptions = {
    narration: {
        appendReplacements = [
            {searchValue: /\\theta/gi, replaceValue: 'theta'}
        ]
    }
};
var av = new JSAV('myAV', avOptions);

If a developer wants to override the default list, they can do:

var avOptions = {
    narration: {
        overrideReplacements = [
            {searchValue: /\\theta/gi, replaceValue: 'theta'}
        ]
    }
};
var av = new JSAV('myAV', avOptions);

I chose to do it this way because when providing an array of length N for avOptions.narration.replacements , jQuery's extend method simply overwrites the first N elements in JSAV_OPTIONS.narration.replacements

If you find these changes acceptable, I will update the documentation.

vkaravir commented 6 years ago

Looks really good @jwonderly, thank you for making the changes! And apologies for taking so long, I thought I had already merged this.