Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1075756 of SpeechRecognitionEvent

  • Revision slug: Web/API/SpeechRecognitionEvent
  • Revision title: SpeechRecognitionEvent
  • Revision id: 1075756
  • Created:
  • Creator: sgiles
  • Is current revision? Yes
  • Comment Typo

Revision Content

{{APIRef("Web Speech API")}}{{SeeCompatTable}}

The SpeechRecognitionEvent interface of the Web Speech API represents the event object for the {{event("result")}} and {{event("nomatch")}} events, and contains all the data associated with an interim or final speech recognition result.

Properties

SpeechRecognitionEvent also inherits properties from its parent interface, {{domxref("Event")}}.

{{domxref("SpeechRecognitionEvent.emma")}} {{readonlyinline}}
Returns an Extensible MultiModal Annotation markup language (EMMA) — XML — representation of the result.
{{domxref("SpeechRecognitionEvent.interpretation")}} {{readonlyinline}}
Returns the semantic meaning of what the user said.
{{domxref("SpeechRecognitionEvent.resultIndex")}} {{readonlyinline}}
Returns the lowest index value result in the {{domxref("SpeechRecognitionResultList")}} "array" that has actually changed.
{{domxref("SpeechRecognitionEvent.results")}} {{readonlyinline}}
Returns a {{domxref("SpeechRecognitionResultList")}} object representing all the speech recognition results for the current session.

Examples

This code is excerpted from our Speech color changer example.

recognition.onresult = function(event) {
  // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
  // The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
  // It has a getter so it can be accessed like an array
  // The first [0] returns the SpeechRecognitionResult at position 0.
  // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results.
  // These also have getters so they can be accessed like arrays.
  // The second [0] returns the SpeechRecognitionAlternative at position 0.
  // We then return the transcript property of the SpeechRecognitionAlternative object
  var color = event.results[0][0].transcript;
  diagnostic.textContent = 'Result received: ' + color + '.';
  bg.style.backgroundColor = color;
}

Specifications

Specification Status Comment
{{SpecName('Web Speech API', '#speechreco-event', 'SpeechRecognitionEvent')}} {{Spec2('Web Speech API')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(33)}} [1] {{CompatGeckoDesktop(44)}} [2] {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Chrome Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatVersionUnknown}}[1] {{CompatUnknown}} 2.5 {{CompatNo}} {{CompatNo}} {{CompatNo}}
  • [1] Speech recognition interfaces are currently prefixed on Chrome, so you'll need to prefix interface names appropriately, e.g. webkitSpeechRecognition; You'll also need to serve your code through a web server for recognition to work.
  • [2] Can be enabled via the media.webspeech.recognition.enable flag in about:config, although note that currently speech recognition won't work on Desktop Firefox — it will be properly exposed soon, once the required internal permissions are sorted out.

Firefox OS permissions

To use speech recognition in an app, you need to specify the following permissions in your manifest:

"permissions": {
  "audio-capture" : {
    "description" : "Audio capture"
  },
  "speech-recognition" : {
    "description" : "Speech recognition"
  }
}

You also need a privileged app, so you need to include this as well:

  "type": "privileged"

See also

Revision Source

<p>{{APIRef("Web Speech API")}}{{SeeCompatTable}}</p>

<p>The <strong><code>SpeechRecognitionEvent</code></strong> interface of the <a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a> represents the event object for the {{event("result")}} and {{event("nomatch")}} events, and contains all the data associated with an interim or final speech recognition result.</p>

<h2 id="Properties">Properties</h2>

<p><em><code>SpeechRecognitionEvent</code> also inherits properties from its parent interface, {{domxref("Event")}}.</em></p>

<dl>
 <dt>{{domxref("SpeechRecognitionEvent.emma")}} {{readonlyinline}}</dt>
 <dd>Returns an <cite>E</cite><cite>xtensible MultiModal Annotation markup language (EMMA) — XML — representation of the result.</cite></dd>
 <dt>{{domxref("SpeechRecognitionEvent.interpretation")}} {{readonlyinline}}</dt>
 <dd>Returns the semantic meaning of what the user said.</dd>
 <dt>{{domxref("SpeechRecognitionEvent.resultIndex")}} {{readonlyinline}}</dt>
 <dd>Returns the lowest index value result in the {{domxref("SpeechRecognitionResultList")}} "array" that has actually changed.</dd>
 <dt>{{domxref("SpeechRecognitionEvent.results")}} {{readonlyinline}}</dt>
 <dd>Returns a {{domxref("SpeechRecognitionResultList")}} object representing all the speech recognition results for the current session.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<p>This code is excerpted from our <a href="https://github.com/mdn/web-speech-api/blob/master/speech-color-changer/script.js">Speech color changer</a> example.</p>

<pre class="brush: js">
recognition.onresult = function(event) {
&nbsp; // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
&nbsp; // The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
&nbsp; // It has a getter so it can be accessed like an array
&nbsp; // The first [0] returns the SpeechRecognitionResult at position 0.
&nbsp; // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results.
&nbsp; // These also have getters so they can be accessed like arrays.
&nbsp; // The second [0] returns the SpeechRecognitionAlternative at position 0.
&nbsp; // We then return the transcript property of the SpeechRecognitionAlternative object
&nbsp; var color = event.results[0][0].transcript;
&nbsp; diagnostic.textContent = 'Result received: ' + color + '.';
&nbsp; bg.style.backgroundColor = color;
}</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Speech API', '#speechreco-event', 'SpeechRecognitionEvent')}}</td>
   <td>{{Spec2('Web Speech API')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(33)}} <sup>[1]</sup></td>
   <td>{{CompatGeckoDesktop(44)}} <sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>2.5</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<ul>
 <li>[1] Speech recognition interfaces are currently prefixed on Chrome, so you'll need to prefix interface names appropriately, e.g. <code>webkitSpeechRecognition</code>; You'll also need to serve your code through a web server for recognition to work.</li>
 <li>[2] Can be enabled via the <code>media.webspeech.recognition.enable</code> flag in <a href="about:config">about:config</a>, although note that currently speech recognition won't work on Desktop Firefox — it will be properly exposed soon, once the required internal permissions are sorted out.</li>
</ul>

<h3 id="Firefox_OS_permissions">Firefox OS permissions</h3>

<p>To use speech recognition in an app, you need to specify the following permissions in your <a href="/en-US/docs/Web/Apps/Build/Manifest">manifest</a>:</p>

<pre class="brush: json">
"permissions": {
  "audio-capture" : {
    "description" : "Audio capture"
  },
  "speech-recognition" : {
    "description" : "Speech recognition"
  }
}</pre>

<p>You also need a privileged app, so you need to include this as well:</p>

<pre class="brush: json">
  "type": "privileged"</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li>
</ul>
Revert to this revision