Skip to content

Commit 59b1992

Browse files
Add deprecated grammar support back (#163)
Co-authored-by: Evan Liu <[email protected]>
1 parent e0a271f commit 59b1992

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

index.bs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ interface SpeechRecognition : EventTarget {
172172
constructor();
173173

174174
// recognition parameters
175+
attribute SpeechGrammarList grammars;
175176
attribute DOMString lang;
176177
attribute boolean continuous;
177178
attribute boolean interimResults;
@@ -271,6 +272,25 @@ dictionary SpeechRecognitionEventInit : EventInit {
271272
required SpeechRecognitionResultList results;
272273
};
273274

275+
// The object representing a speech grammar. This interface has been deprecated and exists in this spec for the sole purpose of maintaining backwards compatibility.
276+
[Exposed=Window]
277+
interface SpeechGrammar {
278+
attribute DOMString src;
279+
attribute float weight;
280+
};
281+
282+
// 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.
283+
[Exposed=Window]
284+
interface SpeechGrammarList {
285+
constructor();
286+
readonly attribute unsigned long length;
287+
getter SpeechGrammar item(unsigned long index);
288+
undefined addFromURI(DOMString src,
289+
optional float weight = 1.0);
290+
undefined addFromString(DOMString string,
291+
optional float weight = 1.0);
292+
};
293+
274294
// The object representing a phrase for contextual biasing.
275295
[SecureContext, Exposed=Window]
276296
interface SpeechRecognitionPhrase {
@@ -293,6 +313,10 @@ interface SpeechRecognitionPhraseList {
293313
<h4 id="speechreco-attributes">SpeechRecognition Attributes</h4>
294314

295315
<dl>
316+
<dt><dfn attribute for=SpeechRecognition>grammars</dfn> attribute</dt>
317+
<dd>The grammars attribute stores the collection of SpeechGrammar objects which represent the grammars that are active for this recognition.
318+
This attribute does nothing and exists in this spec for the sole purpose of maintaining backwards compatibility.</dd>
319+
296320
<dt><dfn attribute for=SpeechRecognition>lang</dfn> attribute</dt>
297321
<dd>This attribute will set the language of the recognition for the request, using a valid BCP 47 language tag. [[!BCP47]]
298322
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.
@@ -756,6 +780,50 @@ For a non-continuous recognition it will hold only a single value.</p>
756780
</dd>
757781
</dl>
758782

783+
<h4 id="speechreco-speechgrammar">SpeechGrammar</h4>
784+
785+
<p>The SpeechGrammar object represents a container for a grammar.</p>
786+
<p class=note>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.</p>
787+
<p>This structure has the following attributes:</p>
788+
789+
<dl>
790+
<dt><dfn attribute for=SpeechGrammar>src</dfn> attribute</dt>
791+
<dd>The required src attribute is the URI for the grammar.</dd>
792+
793+
<dt><dfn attribute for=SpeechGrammar>weight</dfn> attribute</dt>
794+
<dd>The optional weight attribute controls the weight that the speech recognition service should use with this grammar.
795+
By default, a grammar has a weight of 1.
796+
Larger weight values positively weight the grammar while smaller weight values make the grammar weighted less strongly.</dd>
797+
</dl>
798+
799+
<h4 id="speechreco-speechgrammarlist">SpeechGrammarList</h4>
800+
801+
<p>The SpeechGrammarList object represents a collection of SpeechGrammar objects.
802+
This structure has the following attributes:</p>
803+
<p class=note>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.</p>
804+
805+
<dl>
806+
<dt><dfn attribute for=SpeechGrammarList>length</dfn> attribute</dt>
807+
<dd>The length attribute represents how many grammars are currently in the array.</dd>
808+
809+
<dt><dfn method for=SpeechGrammarList>item(<var>index</var>)</dfn> getter</dt>
810+
<dd>The item getter returns a SpeechGrammar from the index into an array of grammars.
811+
The user agent must ensure that the length attribute is set to the number of elements in the array.
812+
The user agent must ensure that the index order from smallest to largest matches the order in which grammars were added to the array.</dd>
813+
814+
<dt><dfn method for=SpeechGrammarList>addFromURI(<var>src</var>, <var>weight</var>)</dfn> method</dt>
815+
<dd>This method appends a grammar to the grammars array parameter based on URI.
816+
The URI for the grammar is specified by the <var>src</var> parameter, which represents the URI for the grammar.
817+
Note, some services may support builtin grammars that can be specified by URI.
818+
The <var>weight</var> parameter represents this grammar's weight relative to the other grammar.
819+
820+
<dt><dfn method for=SpeechGrammarList>addFromString(<var>string</var>, <var>weight</var>)</dfn> method</dt>
821+
<dd>This method appends a grammar to the grammars array parameter based on text.
822+
The content of the grammar is specified by the <var>string</var> parameter.
823+
This content should be encoded into a data: URI when the SpeechGrammar object is created.
824+
The <var>weight</var> parameter represents this grammar's weight relative to the other grammar.
825+
</dl>
826+
759827
<h3 id="tts-section">The SpeechSynthesis Interface</h3>
760828

761829
<p>The SpeechSynthesis interface is the scripted web API for controlling a text-to-speech output.</p>

0 commit comments

Comments
 (0)