org.jvoicexml.implementation.jsapi10
Class AudioInput

java.lang.Object
  extended by org.jvoicexml.implementation.jsapi10.AudioInput
All Implemented Interfaces:
ExternalResource, ObservableUserInput, InputDevice, RemoteConnectable, SpokenInput

public final class AudioInput
extends Object
implements SpokenInput, ObservableUserInput

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: 216 $

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

Author:
Dirk Schnelle

Constructor Summary
AudioInput(RecognizerModeDesc defaultDescriptor)
          Constructs a new audio input.
 
Method Summary
 void activate()
          Activates this resource, when it is retrieved from the pool.
 void activateGrammars(Collection<GrammarImplementation<? extends Object>> grammars)
          Activates the given grammars.
 void close()
          Closes and releases the acquired resources.
 void connect(RemoteClient remoteclient)
          Establishes a connection from the given RemoteClient to this object.
 void deactivateGrammars(Collection<GrammarImplementation<? extends Object>> grammars)
          Deactivates the given grammar.
 Collection<BargeInType> getSupportedBargeInTypes()
          Retrieves the barge-in types supported by this UserInput.
 Collection<GrammarType> getSupportedGrammarTypes()
          Retrieves the grammar types that are supported by this implementation.
 String getType()
          Retrieves a unique identifier for this external resource.
 GrammarImplementation<RuleGrammar> loadGrammar(Reader reader, GrammarType type)
          Creates a GrammarImplementation from the contents provided by the Reader.
 GrammarImplementation<RuleGrammar> newGrammar(String name, GrammarType type)
          Creates a new grammar of the given type for this recognizer with a specified grammar name.
 void open()
          Initializes and and acquires the needed resources.
 void passivate()
          Passivates this resource, when it is returned to the pool.
 void record(OutputStream out)
          Records audio received from the user.
 void setUserInputListener(UserInputListener inputListener)
          Sets the listener for user input events.
 void startRecognition()
          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
 

Constructor Detail

AudioInput

public AudioInput(RecognizerModeDesc defaultDescriptor)
Constructs a new audio input.

Parameters:
defaultDescriptor - the default recognizer mode descriptor.
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

setUserInputListener

public void setUserInputListener(UserInputListener inputListener)
Sets the listener for user input events.

The implementation of this interface must notify the listener about all events.

Note: This method might not be called, e.g. if there is no UserInput.

Specified by:
setUserInputListener in interface ObservableUserInput
Parameters:
inputListener - The listener.

getSupportedBargeInTypes

public Collection<BargeInType> getSupportedBargeInTypes()
Retrieves the barge-in types supported by this UserInput.

Specified by:
getSupportedBargeInTypes in interface SpokenInput
Returns:
Collection of supported barge-in types, an empty collection, if no types are supported.

newGrammar

public GrammarImplementation<RuleGrammar> newGrammar(String name,
                                                     GrammarType type)
                                              throws NoresourceError
Creates a new grammar of the given type for this recognizer with a specified grammar name.

Specified by:
newGrammar in interface SpokenInput
Parameters:
name - Name of the grammar to be created.
type - type of the grammar to read. The type is one of the supported types of the implementation, that has been requested via SpokenInput.getSupportedGrammarTypes().
Returns:
Created grammar.
Throws:
NoresourceError - If the input device is not available.

loadGrammar

public GrammarImplementation<RuleGrammar> loadGrammar(Reader reader,
                                                      GrammarType type)
                                               throws NoresourceError,
                                                      BadFetchError,
                                                      UnsupportedFormatError
Creates a GrammarImplementation from the contents provided by the Reader. If the grammar contained in the Reader already exists, it is over-written.

Specified by:
loadGrammar in interface SpokenInput
Parameters:
reader - The Reader from which the grammar text is loaded
type - type of the grammar to read. The type is one of the supported types of the implementation, that has been requested via SpokenInput.getSupportedGrammarTypes().
Returns:
Read grammar.
Throws:
NoresourceError - The input resource is not available.
BadFetchError - Error reading the grammar.
UnsupportedFormatError - Invalid grammar format.

activateGrammars

public void activateGrammars(Collection<GrammarImplementation<? extends Object>> grammars)
                      throws BadFetchError,
                             UnsupportedLanguageError,
                             NoresourceError
Activates the given grammars.

Specified by:
activateGrammars in interface SpokenInput
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<GrammarImplementation<? extends Object>> grammars)
                        throws BadFetchError
Deactivates the given grammar. Do nothing if the input resource is not available.

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

record

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

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

startRecognition

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

Specified by:
startRecognition in interface InputDevice
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 InputDevice
See Also:
InputDevice.startRecognition()

activate

public void activate()
Activates this resource, when it is retrieved from the pool.

Specified by:
activate in interface ExternalResource
Specified by:
activate in interface SpokenInput

passivate

public void passivate()
Passivates this resource, when it is returned to the pool.

Specified by:
passivate in interface ExternalResource
Specified by:
passivate in interface SpokenInput

connect

public void connect(RemoteClient remoteclient)
             throws IOException
Establishes a connection from the given RemoteClient to this object.

Specified by:
connect in interface RemoteConnectable
Parameters:
remoteclient - data container with connection relevant data.
Throws:
IOException - error establishing the connection.
Stuff to complete
implement this method.

getType

public String getType()
Retrieves a unique identifier for this external resource.

Specified by:
getType in interface ExternalResource
Returns:
unique identifier.

getSupportedGrammarTypes

public Collection<GrammarType> getSupportedGrammarTypes()
Retrieves the grammar types that are supported by this implementation.

Specified by:
getSupportedGrammarTypes in interface SpokenInput
Returns:
supported grammars.


Copyright © 2005-2007 JVoiceXML group.