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

added charLength to SpeechSynthesisEvent #50

Merged
merged 4 commits into from
Mar 15, 2019
Merged

Conversation

sjdallst
Copy link
Contributor

@sjdallst sjdallst commented Mar 7, 2019

There was already a PR about this same concept, but it seems to have become inactive. Creating this PR to get things moving again. Here is the original discussion. This change has picked up interest from both Microsoft and Google, so now seems like a good time to make the change.


Preview | Diff

@sjdallst
Copy link
Contributor Author

sjdallst commented Mar 7, 2019

Here's the corresponding test PR

@travisleithead
Copy link
Member

Pinging @foolip, and maybe @rniwa or @marcoscaceres could find an appropriate reviewer from Apple/Mozilla? (Not sure who that might be.)

index.bs Outdated
<dt><dfn attribute for=SpeechSynthesisEvent>charLength</dfn> attribute</dt>
<dd>This attribute indicates the length of the text (word or sentence) that will be spoken corresponding to this event.
This attribute is the length, in characters, starting from this event's {{charIndex}}.
The user agent must return this value if the speech synthesis engine supports it or the user agent can otherwise determine it, otherwise the user agent must return undefined.</dd>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem of returning undefined mentioned in #30 (comment) remains to be solved here. If you're also planning to implement this (in Chromium?) we can just do what the implementation will do. There are really only two options:

  • Don't expose the charLength attribute if it's not supported, so that 'charLength' in SpeechSynthesisEvent.prototype is false (makes feature detection possible)
  • If this is a dynamic and depends on the speech synthesis engine at runtime, make the attribute nullable and say null here instead of undefined. There's some precedence for this in WebRTC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that nullable is the way to go, since it ends up being dynamic based on which speech synthesis engine you are using. Should this logic apply to charIndex, elapsedTime, and name as well? The current implementations seem to return the default values for these fields instead of undefined, and it might cause some compat issues if this is changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that it returns 0? If making the distinction between zero and unknown isn't important to clients of the API we could change the spec to do the same. Bull null is fine too.

Would you be up to sending a PR to change the other attributes to change in a similar way?

@foolip
Copy link
Member

foolip commented Mar 13, 2019

@sjdallst @travisleithead thanks for sending this PR! If either of you plan to contribute more to this spec and implementation I'd be happy to give you write access so you can review each others PRs instead of being blocked on me.

index.bs Outdated Show resolved Hide resolved
@marcoscaceres
Copy link
Collaborator

@andrenatal from the Mozilla side, perhaps?

index.bs Outdated
@@ -598,13 +598,15 @@ interface SpeechSynthesisUtterance : EventTarget {
interface SpeechSynthesisEvent : Event {
readonly attribute SpeechSynthesisUtterance utterance;
readonly attribute unsigned long charIndex;
readonly attribute unsigned long? charLength;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why null instead of just zero?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to the "return undefined" bits in https://w3c.github.io/speech-api/#speechsynthesisevent-attributes which don't actually make sense, it's not possible to return undefined through Web IDL. Using elapsedTime zero, name empty string would be fine, and charLength zero too. It's only for charIndex that zero may be ambiguous with a real value.

However, with charLength added, it would be possible to distinguish this case by checking if charLength is zero. @sjdallst do you think that would be OK? The existing Chromium implementation just returns the default values, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, the above doesn’t sound amazing if it’s going to require special IDL treatment. Maybe we need a more in-depth spec review?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be hard to find other things that aren't quite right or not precise enough, but this "return undefined" problem is quite confined, it doesn't interact with other problems in the spec AFAICT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the current state of things is a little ambiguous. If the user agent neglects charIndex completely, the client will see "undefined". If I get a 0 for charIndex, is this because the word or sentence is at the beginning of the text, or is it because the speech synthesizer does not support the charIndex? Returning null would remove some of this ambiguity, so a check for undefined or null would unambiguously tell the client whether this feature is supported, thus allowing for feature checking. Assuming the user agent follows the spec, this would also tell the client who is at fault (user agent or speech synthesis engine)

The current norm is the ambiguous option. I don't know if clients actually code for this ambiguous case, do platform checking, or hope for the best and let themselves break when features aren't supported, but following this norm would probably allow for the easiest and quickest implementation across browsers, and would let us resolve the undefined issue. However, issues might come later when clients have to keep track of what combination of browsers and platforms support these features.

Copy link
Contributor Author

@sjdallst sjdallst Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem arises when the user agent (chromium, etc) supports the feature, but the speech synthesizer does not. For example, Windows, Mac, and, I think, Android have clear implementations for character length from speech events, but Linux (as far as I know) does not. Therefore, it makes sense to implement this feature in Chromium because it is supported by many speech synthesis platforms, but because the Linux version of chromium cannot get the value, it will be stuck returning a default value.

In order to do the prototype chain checking, I think a web platform like chromium would have to keep different versions of the SpeechSynthesisEvent for different platforms depending on whether or not that platform's speech synthesizer supports the attribute. This sounds like it would add a lot of unecessary code for any browser implementer that wanted to do this.

I think that if we just look at charLength, it's not a bad idea to return the default value. Word and sentence events are only fired when a word or sentence is about to spoken, and there aren't any speakable words of 0 characters.

I'm not as well versed in contributing to open source, but maybe charIndex is something that should be looked at in another PR? (yet could still be edited to reflect the current norm of returning a default value)

To @foolip 's point earlier. I think there would still be some slight ambiguity there. If I get an event with 0 charIndex and 0 charLength, the browser definitely doesn't support charLength, but whether it supports charIndex is still unclear. You would have to keep track of multiple events to see if charIndex is supported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux version of chromium cannot get the value, it will be stuck returning a default value.

What's preventing this getting fixed on Linux tho? It seems like we are working around an OS limitation that could be fixed at the OS level at any time in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also noting that null adds further fingerprinting surface because it reveals something unique about the OS's capabilities - or lack of... not a huge thing, but it's a thing additional to consider)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm leaning towards not nullable because I suspect it aligns with existing implementations, note that if we did make it nullable and then all OS limitations were resolved, it would just mean that null is never returned and we can eventually make it non-nullable again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok it seems to me that we're leaning towards not nullable. I'll go ahead and make the change; along with edits to the descriptions of the other attributes.

Co-Authored-By: sjdallst <sjdallst@gmail.com>
@foolip
Copy link
Member

foolip commented Mar 14, 2019

@sjdallst, what are your thoughts on the overall "return undefined" situation? Do you think it's OK to just return the default values instead, or should we go with null everywhere?

@foolip
Copy link
Member

foolip commented Mar 15, 2019

@sjdallst can you summarize what browsers currently do on different platforms if the API is supported but the synthesizer turns out not to at runtime?

@sjdallst
Copy link
Contributor Author

@sjdallst can you summarize what browsers currently do on different platforms if the API is supported but the synthesizer turns out not to at runtime?

Yeah, right now default values from SpeechSynthesisEventInit are being used, (so 0 for charIndex, etc)

@sjdallst
Copy link
Contributor Author

@sjdallst, what are your thoughts on the overall "return undefined" situation? Do you think it's OK to just return the default values instead, or should we go with null everywhere?

I think the discussion here has led us towards doing default values. Nullable goes against current practices, and would eventually be phased out once a browser supports the full SpeechSynthesisEvent on all platforms.

@foolip
Copy link
Member

foolip commented Mar 15, 2019

Thanks for working through this and fixing the other attributes, @sjdallst!

@foolip foolip merged commit 959c2ed into WICG:master Mar 15, 2019
foolip pushed a commit to web-platform-tests/wpt that referenced this pull request Mar 15, 2019
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 1, 2019
…hSynthesisEvent-constructor, a=testonly

Automatic update from web-platform-tests
Add test for charLength in SpeechSynthesisEvent constructor (#15732)

Follows WICG/speech-api#50.
--

wpt-commits: 3531dc2a994d918914e4751b97807ce8d79bf4b7
wpt-pr: 15732
mykmelez pushed a commit to mykmelez/gecko that referenced this pull request Apr 2, 2019
…hSynthesisEvent-constructor, a=testonly

Automatic update from web-platform-tests
Add test for charLength in SpeechSynthesisEvent constructor (#15732)

Follows WICG/speech-api#50.
--

wpt-commits: 3531dc2a994d918914e4751b97807ce8d79bf4b7
wpt-pr: 15732
marcoscaceres pushed a commit to web-platform-tests/wpt that referenced this pull request Jul 23, 2019
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 4, 2019
…hSynthesisEvent-constructor, a=testonly

Automatic update from web-platform-tests
Add test for charLength in SpeechSynthesisEvent constructor (#15732)

Follows WICG/speech-api#50.
--

wpt-commits: 3531dc2a994d918914e4751b97807ce8d79bf4b7
wpt-pr: 15732

UltraBlame original commit: ca56ec92fb4cd73e332c4f393cb4414faddb9211
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 4, 2019
…hSynthesisEvent-constructor, a=testonly

Automatic update from web-platform-tests
Add test for charLength in SpeechSynthesisEvent constructor (#15732)

Follows WICG/speech-api#50.
--

wpt-commits: 3531dc2a994d918914e4751b97807ce8d79bf4b7
wpt-pr: 15732

UltraBlame original commit: ca56ec92fb4cd73e332c4f393cb4414faddb9211
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 4, 2019
…hSynthesisEvent-constructor, a=testonly

Automatic update from web-platform-tests
Add test for charLength in SpeechSynthesisEvent constructor (#15732)

Follows WICG/speech-api#50.
--

wpt-commits: 3531dc2a994d918914e4751b97807ce8d79bf4b7
wpt-pr: 15732

UltraBlame original commit: ca56ec92fb4cd73e332c4f393cb4414faddb9211
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.

None yet

5 participants