SpeechRecognitionPhrase
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
TheSpeechRecognitionPhrase interface of theWeb Speech API represents a phrase that can be passed to the speech recognition engine forcontextual biasing.
In this article
Instance properties
SpeechRecognitionPhrase.boostRead onlyExperimentalA floating point number representing the amount of boost you want to apply to the corresponding
phrase.SpeechRecognitionPhrase.phraseRead onlyExperimentalA string containing the word or phrase you want boosted in the recognition engine's bias.
Examples
>Basic usage
The following code first creates an array containing the phrases to boost and theirboost values. We convert this data into anObservableArray ofSpeechRecognitionPhrase objects by mapping the original array elements toSpeechRecognitionPhrase() constructor calls:
const phraseData = [ { phrase: "azure", boost: 5.0 }, { phrase: "khaki", boost: 3.0 }, { phrase: "tan", boost: 2.0 },];const phraseObjects = phraseData.map( (p) => new SpeechRecognitionPhrase(p.phrase, p.boost),);After creating aSpeechRecognition instance, we add our contextual biasing phrases by setting thephraseObjects array as the value of theSpeechRecognition.phrases property:
const recognition = new SpeechRecognition();recognition.continuous = false;recognition.lang = "en-US";recognition.interimResults = false;recognition.processLocally = true;recognition.phrases = phraseObjects;// …This code is excerpted from ouron-device speech color changer (run the demo live). SeeUsing the Web Speech API for a full explanation.
Specifications
| Specification |
|---|
| Web Speech API> # speechrecognitionphrase> |