Skip to content

Commit 6356249

Browse files
Introduce start session algorithm (#138)
* Introduce start session algorithm * Nits * Nit #2 * Use InvalidStateError instead of UnknownError * Fix typo
1 parent 59f74d4 commit 6356249

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

index.bs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ This does not preclude adding support for this as a future API enhancement, and
9999
User consent can include, for example:
100100
<ul>
101101
<li>User click on a visible speech input element which has an obvious graphical representation showing that it will start speech input.</li>
102-
<li>Accepting a permission prompt shown as the result of a call to <code>SpeechRecognition.start</code>.</li>
102+
<li>Accepting a permission prompt shown as the result of a call to <a method for=SpeechRecognition>start()</a>.</li>
103103
<li>Consent previously granted to always allow speech input for this web page.</li>
104104
</ul>
105105
</li>
@@ -142,6 +142,14 @@ This does not preclude adding support for this as a future API enhancement, and
142142
The term "final result" indicates a SpeechRecognitionResult in which the final attribute is true.
143143
The term "interim result" indicates a SpeechRecognitionResult in which the final attribute is false.
144144

145+
{{SpeechRecognition}} has the following internal slots:
146+
147+
<dl dfn-type=attribute dfn-for="SpeechRecognition">
148+
: <dfn>[[started]]</dfn>
149+
::
150+
A boolean flag representing whether the speech recognition started. The initial value is <code>false</code>.
151+
</dl>
152+
145153
<xmp class="idl">
146154
[Exposed=Window]
147155
interface SpeechRecognition : EventTarget {
@@ -277,15 +285,19 @@ See <a href="https://lists.w3.org/Archives/Public/public-speech-api/2012Sep/0072
277285

278286
<dl>
279287
<dt><dfn method for=SpeechRecognition>start()</dfn> method</dt>
280-
<dd>When the start method is called it represents the moment in time the web application wishes to begin recognition.
281-
When the speech input is streaming live through the input media stream, then this start call represents the moment in time that the service must begin to listen.
282-
Once the system is successfully listening to the recognition the user agent must raise a start event.
283-
If the start method is called on an already started object (that is, start has previously been called, and no <a event for=SpeechRecognition>error</a> or <a event for=SpeechRecognition>end</a> event has fired on the object), the user agent must throw an "{{InvalidStateError!!exception}}" {{DOMException}} and ignore the call.</dd>
288+
<dd>
289+
1. Let <var>requestMicrophonePermission</var> to <code>true</code>.
290+
1. Run the <a>start session algorithm</a> with <var>requestMicrophonePermission</var>.
291+
</dd>
284292

285293
<dt><dfn method for=SpeechRecognition>start({{MediaStreamTrack}} audioTrack)</dfn> method</dt>
286-
<dd>The overloaded start method does the same thing as the parameterless start method except it performs speech recognition on provided {{MediaStreamTrack}} instead of the input media stream.
287-
If the {{MediaStreamTrack/kind}} attribute of the {{MediaStreamTrack}} is not "audio" or the {{MediaStreamTrack/readyState}} attribute is not "live", the user agent must throw an "{{InvalidStateError!!exception}}" {{DOMException}} and ignore the call.
288-
Unlike the parameterless start method, the user agent does not check whether [=this=]'s [=relevant global object=]'s [=associated Document=] is [=allowed to use=] the [=policy-controlled feature=] named "<code>microphone</code>".</dd>
294+
<dd>
295+
1. Let <var>audioTrack</var> be the first argument.
296+
1. If <var>audioTrack</var>'s {{MediaStreamTrack/kind}} attribute is NOT <code>"audio"</code>, throw an {{InvalidStateError}} and abort these steps.
297+
1. If <var>audioTrack</var>'s {{MediaStreamTrack/readyState}} attribute is NOT <code>"live"</code>, throw an {{InvalidStateError}} and abort these steps.
298+
1. Let <var>requestMicrophonePermission</var> be <code>false</code>.
299+
1. Run the <a>start session algorithm</a> with <var>requestMicrophonePermission</var>.
300+
</dd>
289301

290302
<dt><dfn method for=SpeechRecognition>stop()</dfn> method</dt>
291303
<dd>The stop method represents an instruction to the recognition service to stop listening to more audio, and to try and return a result using just the audio that it has already received for this recognition.
@@ -309,6 +321,16 @@ See <a href="https://lists.w3.org/Archives/Public/public-speech-api/2012Sep/0072
309321

310322
</dl>
311323

324+
<p>When the <dfn>start session algorithm</dfn> with <var>requestMicrophonePermission</var> is invoked, the user agent MUST run the following steps:
325+
326+
1. If the [=current settings object=]'s [=relevant global object=]'s [=associated Document=] is NOT [=fully active=], throw an {{InvalidStateError}} and abort these steps.
327+
1. If {{[[started]]}} is <code>true</code> and no <a event for=SpeechRecognition>error</a> or <a event for=SpeechRecognition>end</a> event has fired, throw an {{InvalidStateError}} and abort these steps.
328+
1. Set {{[[started]]}} to <code>true</code>.
329+
1. If <var>requestMicrophonePermission</var> is <code>true</code> and [=request permission to use=] "<code>microphone</code>" is [=permission/"denied"=], abort these steps.
330+
1. Once the system is successfully listening to the recognition, [=fire an event=] named <a event for=SpeechRecognition>start</a> at [=this=].
331+
332+
</p>
333+
312334
<h4 id="speechreco-events">SpeechRecognition Events</h4>
313335

314336
<p>The DOM Level 2 Event Model is used for speech recognition events.

0 commit comments

Comments
 (0)