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

iOS Mobile Safari and WebViews Don't Play All Texts #25

Open
WesWedding opened this issue Mar 9, 2018 · 0 comments
Open

iOS Mobile Safari and WebViews Don't Play All Texts #25

WesWedding opened this issue Mar 9, 2018 · 0 comments

Comments

@WesWedding
Copy link

It appears that the mobile Safari and WebViews on (some?) iOS devices do not provide a SpeechSynthesisEvent that is built in a way that is consistent with the way they are defined at MDN (https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisEvent)

Instead of a "utterance" property, iOS WebKit appears to put the utterance into CurrentTarget.
A minor adjustment to code as follows was enough to fix it for me

Original code

        me.currentContext.utterances.forEach(function (u, index) {
            if (index === 0) {
                u.onstart = function (e) {
                    me.currentContext.currentUtterance = e.utterance
                    p.done();
                    me.internalEvents.onPlay();
                };
            } else {
                u.onstart = function (e) {
                    me.currentContext.currentUtterance = e.utterance
                };
            }
...

Modified code

        me.currentContext.utterances.forEach(function (u, index) {
            if (index === 0) {
                // Note: iOS WebViews (in at least v11.2.6) put the event utterance into currentTarget for some reason.
                u.onstart = function (e) {
                    me.currentContext.currentUtterance = e.utterance || e.currentTarget;
                    p.done();
                    me.internalEvents.onPlay();
                };
            } else {
                u.onstart = function (e) {
                    me.currentContext.currentUtterance = e.utterance || e.currentTarget;
                };
            }

I'll try to remember to submit a pull request sometime tonight. As far as I can tell, this is the only spot where this matters.

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

No branches or pull requests

1 participant