Skip to content

Update availableOnDevice and installOnDevice parameters #157

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ interface SpeechRecognition : EventTarget {
undefined start(MediaStreamTrack audioTrack);
undefined stop();
undefined abort();
static Promise<AvailabilityStatus> availableOnDevice(DOMString lang);
static Promise<boolean> installOnDevice(DOMString lang);
static Promise<AvailabilityStatus> availableOnDevice(SpeechRecognitionAvailabilityOptions options);
static Promise<boolean> installOnDevice(SpeechRecognitionInstallationOptions options);

// event methods
attribute EventHandler onaudiostart;
Expand All @@ -199,6 +199,14 @@ interface SpeechRecognition : EventTarget {
attribute EventHandler onend;
};

dictionary SpeechRecognitionAvailabilityOptions {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What are your thoughts on having separate dictionaries for availability/installation? These two are currently identical, but they allow the availability options to differ from the installation options in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Can you give an example of what those would be?

Besides the language, I can see the following:

  • quality / speed type of thing
  • diarization capability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some examples of other options might include:

  • LLM-based speech recognition
  • acoustic echo cancellation
  • spoken/unspoken punctuation
  • language identification
  • Emoji-support

I think in most cases it would be fine to have the same dictionary type for availability/installation, but is this something we want to commit to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could also rename availableOnDevice() and installOnDevice() to available() and install() and include the on-device part (or the options described here: #156 (comment)) in the SpeechRecognitionOptions.

Copy link
Member

Choose a reason for hiding this comment

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

We could yes.

required DOMString lang;
};

dictionary SpeechRecognitionInstallationOptions {
required DOMString lang;
};

enum SpeechRecognitionErrorCode {
"no-speech",
"aborted",
Expand Down Expand Up @@ -389,21 +397,23 @@ See <a href="https://lists.w3.org/Archives/Public/public-speech-api/2012Sep/0072
The user agent must raise an <a event for=SpeechRecognition>end</a> event once the speech service is no longer connected.
If the abort method is called on an object which is already stopped or aborting (that is, start was never called on it, the <a event for=SpeechRecognition>end</a> or <a event for=SpeechRecognition>error</a> event has fired on it, or abort was previously called on it), the user agent must ignore the call.</dd>

<dt><dfn method for=SpeechRecognition>availableOnDevice({{DOMString}} lang)</dfn> method</dt>
<dt><dfn method for=SpeechRecognition>availableOnDevice({{SpeechRecognitionAvailabilityOptions}} options)</dfn> method</dt>
<dd>
The {{SpeechRecognition/availableOnDevice}} method returns a {{Promise}} that resolves to a {{AvailabilityStatus}} indicating the on-device speech recognition availability for a given [[!BCP47]] language tag.
The {{SpeechRecognition/availableOnDevice}} method returns a {{Promise}} that resolves to a {{AvailabilityStatus}} indicating the on-device speech recognition availability for a given [[!BCP47]] language tag and optional configuration options.

When invoked, run these steps:
1. Let <var>lang</var> be <code>options.lang</code>.
1. Let <var>promise</var> be <a>a new promise</a>.
1. Run the <a>on-device availability algorithm</a> with <var>lang</var> and <var>promise</var>. If it returns an exception, throw it and abort these steps.
1. Return <var>promise</var>.
</dd>

<dt><dfn method for=SpeechRecognition>installOnDevice({{DOMString}} lang)</dfn> method</dt>
<dt><dfn method for=SpeechRecognition>installOnDevice({{SpeechRecognitionInstallationOptions}} options)</dfn> method</dt>
<dd>
The {{SpeechRecognition/installOnDevice}} method returns a {{Promise}} that resolves to a {{boolean}} when and whether the installation of on-device speech recognition for a given [[!BCP47]] language tag succeeded.

When invoked, run these steps:
1. Let <var>lang</var> be <code>options.lang</code>.
1. If the [=current settings object=]'s [=relevant global object=]'s [=associated Document=] is NOT [=fully active=], throw an {{InvalidStateError}} and abort these steps.
1. If <var>lang</var> is not a valid [[!BCP47]] language tag, throw a {{SyntaxError}} and abort these steps.
1. If the on-device speech recognition language pack for <var>lang</var> is unsupported, return a resolved {{Promise}} with false and skip the rest of these steps.
Expand Down