From ec7b539cebe62302e10255f08cf15108cb516ec7 Mon Sep 17 00:00:00 2001 From: Evan Liu Date: Mon, 9 Jun 2025 15:55:21 -0700 Subject: [PATCH] Add deprecated grammar support back --- index.bs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/index.bs b/index.bs index c7684a4..cfabfe7 100644 --- a/index.bs +++ b/index.bs @@ -172,6 +172,7 @@ interface SpeechRecognition : EventTarget { constructor(); // recognition parameters + attribute SpeechGrammarList grammars; attribute DOMString lang; attribute boolean continuous; attribute boolean interimResults; @@ -271,6 +272,25 @@ dictionary SpeechRecognitionEventInit : EventInit { required SpeechRecognitionResultList results; }; +// The object representing a speech grammar. This interface has been deprecated and exists in this spec for the sole purpose of maintaining backwards compatibility. +[Exposed=Window] +interface SpeechGrammar { + attribute DOMString src; + attribute float weight; +}; + +// The object representing a speech grammar collection. This interface has been deprecated and exists in this spec for the sole purpose of maintaining backwards compatibility. +[Exposed=Window] +interface SpeechGrammarList { + constructor(); + readonly attribute unsigned long length; + getter SpeechGrammar item(unsigned long index); + undefined addFromURI(DOMString src, + optional float weight = 1.0); + undefined addFromString(DOMString string, + optional float weight = 1.0); +}; + // The object representing a phrase for contextual biasing. [SecureContext, Exposed=Window] interface SpeechRecognitionPhrase { @@ -293,6 +313,10 @@ interface SpeechRecognitionPhraseList {

SpeechRecognition Attributes

+
grammars attribute
+
The grammars attribute stores the collection of SpeechGrammar objects which represent the grammars that are active for this recognition. + This attribute does nothing and exists in this spec for the sole purpose of maintaining backwards compatibility.
+
lang attribute
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 language of the html document root element and associated hierarchy. @@ -754,6 +778,50 @@ For a non-continuous recognition it will hold only a single value.

+

SpeechGrammar

+ +

The SpeechGrammar object represents a container for a grammar.

+

Grammar support has been deprecated and removed. The grammar objects remain in the spec for backwards compatibility purposes only and do not affect speech recognition.

+

This structure has the following attributes:

+ +
+
src attribute
+
The required src attribute is the URI for the grammar.
+ +
weight attribute
+
The optional weight attribute controls the weight that the speech recognition service should use with this grammar. + By default, a grammar has a weight of 1. + Larger weight values positively weight the grammar while smaller weight values make the grammar weighted less strongly.
+
+ +

SpeechGrammarList

+ +

The SpeechGrammarList object represents a collection of SpeechGrammar objects. +This structure has the following attributes:

+

Grammar support has been deprecated and removed. The grammar objects remain in the spec for backwards compatibility purposes only and do not affect speech recognition.

+ +
+
length attribute
+
The length attribute represents how many grammars are currently in the array.
+ +
item(index) getter
+
The item getter returns a SpeechGrammar from the index into an array of grammars. + The user agent must ensure that the length attribute is set to the number of elements in the array. + The user agent must ensure that the index order from smallest to largest matches the order in which grammars were added to the array.
+ +
addFromURI(src, weight) method
+
This method appends a grammar to the grammars array parameter based on URI. + The URI for the grammar is specified by the src parameter, which represents the URI for the grammar. + Note, some services may support builtin grammars that can be specified by URI. + The weight parameter represents this grammar's weight relative to the other grammar. + +
addFromString(string, weight) method
+
This method appends a grammar to the grammars array parameter based on text. + The content of the grammar is specified by the string parameter. + This content should be encoded into a data: URI when the SpeechGrammar object is created. + The weight parameter represents this grammar's weight relative to the other grammar. +
+

The SpeechSynthesis Interface

The SpeechSynthesis interface is the scripted web API for controlling a text-to-speech output.