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

Update the on-device speech recognition methods #143

Open
wants to merge 4 commits 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
52 changes: 47 additions & 5 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ interface SpeechRecognition : EventTarget {
undefined start(MediaStreamTrack audioTrack);
undefined stop();
undefined abort();
static Promise<boolean> availableOnDevice(DOMString lang);
static Promise<AvailabilityStatus> availableOnDevice(DOMString lang);
static Promise<boolean> installOnDevice(DOMString lang);

// event methods
Expand Down Expand Up @@ -200,6 +200,13 @@ enum SpeechRecognitionMode {
"cloud-only", // Cloud speech recognition only.
};

enum AvailabilityStatus {
"unavailable",
"downloadable",
"downloading",
"available"
};

[Exposed=Window]
interface SpeechRecognitionErrorEvent : Event {
constructor(DOMString type, SpeechRecognitionErrorEventInit eventInitDict);
Expand Down Expand Up @@ -254,7 +261,7 @@ dictionary SpeechRecognitionEventInit : EventInit {

<dt><dfn attribute for=SpeechRecognition>lang</dfn> attribute</dt>
<dd>This attribute will set the language of the recognition for the request, using a valid BCP 47 language tag. [[!BCP47]]
If unset it remains unset for getting in script, but will default to use the <a spec=html>language</a> of the html document root element and associated hierarchy.
If unset it remains unset for getting in script, but will default to use the language of the html document root element and associated hierarchy.
This default value is computed and used when the input request opens a connection to the recognition service.</dd>

<dt><dfn attribute for=SpeechRecognition>continuous</dfn> attribute</dt>
Expand Down Expand Up @@ -314,12 +321,47 @@ See <a href="https://lists.w3.org/Archives/Public/public-speech-api/2012Sep/0072
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>
<dd>The availableOnDevice method returns a Promise that resolves to a boolean indicating whether on-device speech recognition is available for a given BCP 47 language tag. [[!BCP47]]</dd>
<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.

When invoked, run these steps:
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>
<dd>The installOnDevice method returns a Promise that resolves to a boolean indicating whether the installation of on-device speech recognition for a given BCP 47 language tag initiated successfully. [[!BCP47]]</dd>
<dd>
The {{SpeechRecognition/installOnDevice}} method returns a {{Promise}} that resolves to a {{boolean}} indicating whether the installation of on-device speech recognition for a given [[!BCP47]] language tag initiated successfully.

When invoked, run these steps:
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.
1. Let <var>promise</var> be <a>a new promise</a>.
1. Initiate the download of the on-device speech recognition language for <var>lang</var>.
<p class=note>
Note: The user agent can prompt the user for explicit permission to download the on-device speech recognition language pack.
</p>
1. [=Queue a task=] on the [=relevant global object=]'s [=task queue=] to run the following step:
- If the initiation of the download succeeds, resolve <var>promise</var> with <code>true</code>, otherwise resolve it with <code>false</code>.
<p class="note">
Note: The <code>false</code> resolution of the Promise does not indicate the specific cause of failure. User agents are encouraged to provide more detailed information about the failure in developer tools console messages. However, this detailed error information is not exposed to the script. This is non-normative.
</p>
1. Return <var>promise</var>.
</dd>

</dl>
<p>When the <dfn>on-device availability algorithm</dfn> with <var>lang</var> and <var>promise</var> is invoked, the user agent MUST run the following steps:
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. In parallel, determine the availability status for <var>lang</var>:
- If the on-device speech recognition language pack for <var>lang</var> is unsupported, let <var>status</var> be {{AvailabilityStatus/unavailable}}.
- Else if the on-device speech recognition language pack for <var>lang</var> is supported but not installed, let <var>status</var> be {{AvailabilityStatus/downloadable}}.
- Else if the on-device speech recognition language pack for <var>lang</var> is downloading, let <var>status</var> be {{AvailabilityStatus/downloading}}.
- Else if the on-device speech recognition language pack for <var>lang</var> is installed, let <var>status</var> be {{AvailabilityStatus/available}}.
1. [=Queue a task=] on the [=relevant global object=]'s [=task queue=] to run the following step:
- Resolve <var>promise</var> with <var>status</var>.

<p>When the <dfn>start session algorithm</dfn> with <var>requestMicrophonePermission</var> is invoked, the user agent MUST run the following steps:

Expand Down Expand Up @@ -669,7 +711,7 @@ interface SpeechSynthesisVoice {

<dt><dfn attribute for=SpeechSynthesisUtterance>lang</dfn> attribute</dt>
<dd>This attribute specifies the language of the speech synthesis for the utterance, using a valid BCP 47 language tag. [[!BCP47]]
If unset it remains unset for getting in script, but will default to use the <a spec=html>language</a> of the html document root element and associated hierarchy.
If unset it remains unset for getting in script, but will default to use the language of the html document root element and associated hierarchy.
This default value is computed and used when the input request opens a connection to the recognition service.</dd>

<dt><dfn attribute for=SpeechSynthesisUtterance>voice</dfn> attribute</dt>
Expand Down