From 8ccee0ed7341fcb8fb6b90df358e924968f5693f Mon Sep 17 00:00:00 2001 From: Evan Liu Date: Wed, 25 Jun 2025 14:45:57 -0700 Subject: [PATCH 1/2] Update start session algorithm to fire not-allowed error if microphone access is denied (#166) Co-authored-by: Evan Liu --- explainers/contextual-biasing.md | 22 +++++++++++----------- index.bs | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/explainers/contextual-biasing.md b/explainers/contextual-biasing.md index 419ca84..045ff97 100644 --- a/explainers/contextual-biasing.md +++ b/explainers/contextual-biasing.md @@ -30,10 +30,10 @@ A web-based application for doctors could be biased towards recognizing complex ## New API Components -Contextual biasing is implemented through a new `phrases` attribute on the `SpeechRecognition` interface, which uses two new supporting interfaces: `SpeechRecognitionPhrase` and `SpeechRecognitionPhraseList`. +Contextual biasing is implemented through a new `phrases` attribute on the `SpeechRecognition` interface, which uses the new `SpeechRecognitionPhrase` interface. ### 1. `SpeechRecognition.phrases` attribute -This attribute is assigned a `SpeechRecognitionPhraseList` object to provide contextual hints for the recognition session. +This attribute is an `ObservableArray` that allows developers to provide contextual hints for the recognition session. It can be modified like a JavaScript `Array`. ### 2. `SpeechRecognitionPhrase` interface Represents a single phrase and its associated boost value. @@ -42,27 +42,27 @@ Represents a single phrase and its associated boost value. - `phrase`: The text string to be boosted. - `boost`: A float between 0.0 and 10.0. Higher values make the phrase more likely to be recognized. -### 3. `SpeechRecognitionPhraseList` interface -Represents a collection of `SpeechRecognitionPhrase` objects. It can be created with an array of phrases and managed dynamically with `addItem()` and `removeItem()` methods. ### Example Usage ```javascript // A list of phrases relevant to our application's context. -const phrases = [ +const phraseData = [ { phrase: 'Zoltan', boost: 3.0 }, { phrase: 'Grog', boost: 2.0 }, ]; // Create SpeechRecognitionPhrase objects. -const phrases = phrases.map(p => new SpeechRecognitionPhrase(p.phrase, p.boost)); - -// Create a SpeechRecognitionPhraseList. -const phraseList = new SpeechRecognitionPhraseList(phrases); +const phraseObjects = phraseData.map(p => new SpeechRecognitionPhrase(p.phrase, p.boost)); const recognition = new SpeechRecognition(); -// Assign the phrase list to the recognition instance. -recognition.phrases = phraseList; + +// Assign the phrase objects to the recognition instance. +// The attribute is an ObservableArray, so we can assign an array to it. +recognition.phrases = phraseObjects; + +// We can also dynamically add/remove phrases. +recognition.phrases.push(new SpeechRecognitionPhrase('Xylia', 2.5)); // Some user agents (e.g. Chrome) might only support on-device contextual biasing. recognition.processLocally = true; diff --git a/index.bs b/index.bs index 0638cba..ff960f0 100644 --- a/index.bs +++ b/index.bs @@ -512,8 +512,9 @@ following steps: 1. Abort these steps. 1. Set {{[[started]]}} to `true`. 1. If |requestMicrophonePermission| is `true` and [=request - permission to use=] "`microphone`" is [=permission/"denied"=], abort - these steps. + permission to use=] "`microphone`" is [=permission/"denied"=]: + 1. [=Queue a task=] to [=fire an event=] named error at [=this=] using {{SpeechRecognitionErrorEvent}} with its {{SpeechRecognitionErrorEvent/error}} attribute initialized to {{SpeechRecognitionErrorCode/not-allowed}} and its {{SpeechRecognitionErrorEvent/message}} attribute set to an implementation-defined string detailing the reason. + 1. Abort these steps. 1. Once the system is successfully listening to the recognition, queue a task to [=fire an event=] named start at [=this=]. From 1499cc806ce93a9aa04c600037474eca144e660d Mon Sep 17 00:00:00 2001 From: Evan Liu Date: Wed, 2 Jul 2025 14:57:10 -0700 Subject: [PATCH 2/2] Update index.bs --- index.bs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index ff960f0..0638cba 100644 --- a/index.bs +++ b/index.bs @@ -512,9 +512,8 @@ following steps: 1. Abort these steps. 1. Set {{[[started]]}} to `true`. 1. If |requestMicrophonePermission| is `true` and [=request - permission to use=] "`microphone`" is [=permission/"denied"=]: - 1. [=Queue a task=] to [=fire an event=] named error at [=this=] using {{SpeechRecognitionErrorEvent}} with its {{SpeechRecognitionErrorEvent/error}} attribute initialized to {{SpeechRecognitionErrorCode/not-allowed}} and its {{SpeechRecognitionErrorEvent/message}} attribute set to an implementation-defined string detailing the reason. - 1. Abort these steps. + permission to use=] "`microphone`" is [=permission/"denied"=], abort + these steps. 1. Once the system is successfully listening to the recognition, queue a task to [=fire an event=] named start at [=this=].