org.jvoicexml.implementation.jsapi10
Class AudioInput

java.lang.Object
  extended by org.jvoicexml.implementation.jsapi10.AudioInput
All Implemented Interfaces:
ExternalResource, UserInput

public final class AudioInput
extends Object
implements UserInput

Audio input that uses the JSAPI 1.0 to address the recognition engine.

Handle all JSAPI calls to the recognizer to make JSAPI transparent to the interpreter.

Version:
$Revision: 1.1 $

Copyright © 2005 JVoiceXML group - http://jvoicexml.sourceforge.net/

Author:
Dirk Schnelle

Field Summary
private  RecognitionEngine engine
          The implementation of a recognition engine.
private static Logger LOGGER
          Logger for this class.
private  Recognizer recognizer
          The speech recognizer.
private  TimerThread timer
          A timer to get the noinput timeout.
 
Constructor Summary
AudioInput(Platform platform)
          Constructs a new audio input.
 
Method Summary
private  boolean activateGrammar(String name, boolean activate)
          Activates the given grammar.
 void activateGrammars(Collection<RuleGrammar> grammars)
          Activates the given grammar.
 void close()
          Closes and releases the acquired resources.
 void deactivateGrammars(Collection<RuleGrammar> grammars)
          Dectivates the given grammar.
 RuleGrammar loadGrammar(Reader reader)
          Creates a RuleGrammar from Java Speech Grammar Format text provided by the Reader.
 RuleGrammar newGrammar(String name)
          Create a new RuleGrammar for this recognizer with a specified grammar name.
 void open()
          Initializes and and acquires the needed resources.
 void record(OutputStream out)
          Records audio received from the user.
 void setInputStream(InputStream in)
          Sets the input stream, where the input should be obtained.
 void startRecognition(EventHandler handler)
          Detects and reports character and/or spoken input simultaneously.
 void stopRecognition()
          Stops a previously started recognition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final Logger LOGGER
Logger for this class.


recognizer

private Recognizer recognizer
The speech recognizer.


engine

private final RecognitionEngine engine
The implementation of a recognition engine.


timer

private TimerThread timer
A timer to get the noinput timeout.

Constructor Detail

AudioInput

public AudioInput(Platform platform)
Constructs a new audio input.

Parameters:
platform - The platform that manages the TTSEngine.
Method Detail

open

public void open()
          throws NoresourceError
Initializes and and acquires the needed resources.

Specified by:
open in interface ExternalResource
Throws:
NoresourceError - The resource could not be opened.

close

public void close()
Closes and releases the acquired resources.

Specified by:
close in interface ExternalResource

newGrammar

public RuleGrammar newGrammar(String name)
                       throws NoresourceError
Create a new RuleGrammar for this recognizer with a specified grammar name.

Specified by:
newGrammar in interface UserInput
Parameters:
name - Name of the grammar to be created.
Returns:
Created RuleGrammar.
Throws:
NoresourceError - If the input device is not available.

loadGrammar

public RuleGrammar loadGrammar(Reader reader)
                        throws NoresourceError,
                               BadFetchError,
                               UnsupportedFormatError
Creates a RuleGrammar from Java Speech Grammar Format text provided by the Reader. If the grammar contained in the Reader already exists, it is over-written.

Specified by:
loadGrammar in interface UserInput
Parameters:
reader - The Reader from which the grammar text is loaded
Returns:
RuleGrammar Read grammar.
Throws:
NoresourceError - The input resource is not available.
BadFetchError - Error reading the grammar.
UnsupportedFormatError - Invalid grammar format.

activateGrammar

private boolean activateGrammar(String name,
                                boolean activate)
                         throws BadFetchError
Activates the given grammar.

Parameters:
name - Name of the grammar.
activate - true if the grammar should be activated.
Throws:
BadFetchError - Error creating the grammar.

activateGrammars

public void activateGrammars(Collection<RuleGrammar> grammars)
                      throws BadFetchError,
                             UnsupportedLanguageError,
                             NoresourceError
Activates the given grammar.

Specified by:
activateGrammars in interface UserInput
Parameters:
grammars - Grammars to activate.
Throws:
BadFetchError - Grammar is not know by the recognizer.
UnsupportedLanguageError - The specified language is not supported.
NoresourceError - The input resource is not available.

deactivateGrammars

public void deactivateGrammars(Collection<RuleGrammar> grammars)
                        throws BadFetchError
Dectivates the given grammar. Do nothing if the input resource is not availabale.

Specified by:
deactivateGrammars in interface UserInput
Parameters:
grammars - Grammars to deactivate.
Throws:
BadFetchError - Grammar is not know by the recognizer.

record

public void record(OutputStream out)
            throws NoresourceError
Records audio received from the user.

Specified by:
record in interface UserInput
Parameters:
out - OutputStream to write the recorded audio.
Throws:
NoresourceError - The input resource is not available.
Stuff to complete
Implement this method.

startRecognition

public void startRecognition(EventHandler handler)
                      throws NoresourceError,
                             BadFetchError
Detects and reports character and/or spoken input simultaneously.

Specified by:
startRecognition in interface UserInput
Parameters:
handler - The event handler to notify about the recognition result.
Throws:
NoresourceError - The input resource is not available.
BadFetchError - The active grammar contains some errors.

stopRecognition

public void stopRecognition()
Stops a previously started recognition.

Specified by:
stopRecognition in interface UserInput
See Also:
UserInput.startRecognition(org.jvoicexml.interpreter.EventHandler)

setInputStream

public void setInputStream(InputStream in)
                    throws NoresourceError
Sets the input stream, where the input should be obtained.

Note: Unfortunately this is not a feature of all TTS engines. If no InputStream is returned, the default input of the recognizer engine is used. This may have consequences on the usability with a calling device.

Specified by:
setInputStream in interface UserInput
Parameters:
in - The input to use.
Throws:
NoresourceError - The input resource is not available.
Stuff to complete
Implement this method.


Copyright © 2005 JVoiceXML group.