Skip to content

Commit 5166682

Browse files
Replace SpeechRecognitionPhraseList with ObservableArray in explainer (#170)
* Update start session algorithm to fire not-allowed error if microphone access is denied (#166) Co-authored-by: Evan Liu <evliu@google.com> * Update index.bs --------- Co-authored-by: Evan Liu <evliu@google.com>
1 parent aa59647 commit 5166682

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

explainers/contextual-biasing.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ A web-based application for doctors could be biased towards recognizing complex
3030

3131
## New API Components
3232

33-
Contextual biasing is implemented through a new `phrases` attribute on the `SpeechRecognition` interface, which uses two new supporting interfaces: `SpeechRecognitionPhrase` and `SpeechRecognitionPhraseList`.
33+
Contextual biasing is implemented through a new `phrases` attribute on the `SpeechRecognition` interface, which uses the new `SpeechRecognitionPhrase` interface.
3434

3535
### 1. `SpeechRecognition.phrases` attribute
36-
This attribute is assigned a `SpeechRecognitionPhraseList` object to provide contextual hints for the recognition session.
36+
This attribute is an `ObservableArray<SpeechRecognitionPhrase>` that allows developers to provide contextual hints for the recognition session. It can be modified like a JavaScript `Array`.
3737

3838
### 2. `SpeechRecognitionPhrase` interface
3939
Represents a single phrase and its associated boost value.
@@ -42,27 +42,27 @@ Represents a single phrase and its associated boost value.
4242
- `phrase`: The text string to be boosted.
4343
- `boost`: A float between 0.0 and 10.0. Higher values make the phrase more likely to be recognized.
4444

45-
### 3. `SpeechRecognitionPhraseList` interface
46-
Represents a collection of `SpeechRecognitionPhrase` objects. It can be created with an array of phrases and managed dynamically with `addItem()` and `removeItem()` methods.
4745

4846
### Example Usage
4947

5048
```javascript
5149
// A list of phrases relevant to our application's context.
52-
const phrases = [
50+
const phraseData = [
5351
{ phrase: 'Zoltan', boost: 3.0 },
5452
{ phrase: 'Grog', boost: 2.0 },
5553
];
5654

5755
// Create SpeechRecognitionPhrase objects.
58-
const phrases = phrases.map(p => new SpeechRecognitionPhrase(p.phrase, p.boost));
59-
60-
// Create a SpeechRecognitionPhraseList.
61-
const phraseList = new SpeechRecognitionPhraseList(phrases);
56+
const phraseObjects = phraseData.map(p => new SpeechRecognitionPhrase(p.phrase, p.boost));
6257

6358
const recognition = new SpeechRecognition();
64-
// Assign the phrase list to the recognition instance.
65-
recognition.phrases = phraseList;
59+
60+
// Assign the phrase objects to the recognition instance.
61+
// The attribute is an ObservableArray, so we can assign an array to it.
62+
recognition.phrases = phraseObjects;
63+
64+
// We can also dynamically add/remove phrases.
65+
recognition.phrases.push(new SpeechRecognitionPhrase('Xylia', 2.5));
6666

6767
// Some user agents (e.g. Chrome) might only support on-device contextual biasing.
6868
recognition.processLocally = true;

0 commit comments

Comments
 (0)