Partilhar via


listen Element

  Microsoft Speech Technologies Homepage

Performs recognition, post-processing and recording, as well as configuring speech recognizers.

<listen attributes>
   <grammar attributes />      // Describes the grammar source
   <bind attributes  />        // Associates recognition results with controls on an HTML page
   <record attributes />       // Enables and configures recording of user speech
   <param attributes />        // Used to pass parameters into the speech platform (optional)
   <audiometer attributes />   //Configures audiometer display (optional)
</listen>

The listen element consists of the following members.

Contents Description
grammar Specifies input grammar resources.
bind Copies one semantic element of recognition results to an HTML page element or calls a method on that element.
record Controls the recording of audio input.
param Specifies a Speech Platform configuration parameter.
audiometer Configures the audiometer element display.
Attributes  
beep Boolean value that specifies whether a beep is heard before recognition begins. Optional. Default is false, that is, no beep occurs before recognition.
id Identifies the listen element. Optional.
initialtimeout Specifies the maximum allowable time, in milliseconds, between the beginning of recognition or end of a prompt and the detection of speech. Optional.
babbletimeout Specifies the maximum time, in milliseconds, for a duration of an utterance. Optional.
maxtimeout Specifies the maximum allowable time, in milliseconds, between the beginning of recognition or the end of a prompt and when results are returned to the browser. Optional.
endsilence Specifies the period of silence, in milliseconds, at the end of an utterance, after which the recognition attempt is considered complete. Optional.
reject Specifies the recognition rejection threshold. Optional.
lang Specifies the language that the speech engine should use. Optional.
mode Specifies which recognition mode to follow. Optional.
Properties  
recoresult Returns the results of recognition. Read-only.
text Returns a string containing the text of the words recognized. Read-only.
recordlocation Specifies the location of the recorded audio file. Used only when recording is enabled. Read-only.
recordtype Specifies the MIME type of the recorded audio file. Used only when recording is enabled. Read-only.
recordduration Specifies the approximate length of the recorded file in milliseconds. Used only when recording is enabled. Read-only.
recordsize Specifies the size of the recorded file in bytes. Used only when recording is enabled. Read-only.
status Contains the status code returned by the recognition platform. Read-only.
reason Returns text from the Speech Platform about the most recent error. Read-only.
Methods  
Start Starts the recognition process.
Stop Stops the recognition process and returns a result.
Cancel Stops the recognition process without returning a result.
Activate Activates a grammar element or one of its rules.
Deactivate Deactivates a grammar element or one of its rules.
Events  
onreco Occurs when the recognizer has a recognition result available for the browser.
onsilence Occurs when no speech is detected by the recognition platform before the duration of time specified in the initialtimeout attribute on the recognition.
onspeechdetected Occurs when the recognition engine detects speech.
onnoreco Occurs when the recognition engine is unable to return valid recognition results.
onerror Occurs when the speech recognition platform is unable to process a recognition request.
Example  
listen Example A simple example using a recognition.

Remarks

The listen element specifies possible speech inputs and provides control of speech recognition processes and results. Only one listen element can be active at a time.

The main elements of the listen element are grammar, which directs user speech to a particular recognition grammar, and bind, which places text from recognition results into a particular HTML input control. The listen element also configures speech recognition and sets recognition options using the param element.

The listen element can perform recognition-only, recognition and recording, or recording-only.

Setting the mode property affects the ways in which the recognition process is started and stopped.

In order to permit the activation of multiple grammars in parallel, multiple listen elements can be active simultaneously.

A Web page can have more than one listen element, and each listen element can be used more than once. However, methods and event handlers cannot be added or changed after their declaration.

Consequently, if the developer intends to have different behaviors for different items on the same page, separate listen elements must be declared. For example, a developer can declare a listen element without an onsilence event handler. If a subsequent item then needs to process an onsilence event, the user must use a second listen element with the event handler defined. The onsilence event cannot be added dynamically to a page after it is rendered.

See Also

dtmf Element |  prompt Element | smex Element