com.iSpeech
Class SpeechRecognizer

java.lang.Object
  extended by com.iSpeech.SpeechRecognizer

public class SpeechRecognizer
extends java.lang.Object

Contains methods to recognize spoken audio and convert free form speech into text.


Nested Class Summary
static interface SpeechRecognizer.SpeechRecognizerEvent
          Used to notify when the recording state changes
 class SpeechRecognizer.SpeechResult
          Contains the text and the confidence rating for the conversion, which is a float 0.0 to 1.0
 
Field Summary
static int FREEFORM_DICTATION
          Free form dictation, such as a written document
static int FREEFORM_DISABLED
          Disable free form speech recognition.
static int FREEFORM_INSTANT_MESSAGE
          A message for an instant message client
static int FREEFORM_MEMO
          A memo or a list of items
static int FREEFORM_MESSAGE
          A message addressed to another person.
static int FREEFORM_SMS
          A SMS or TXT message.
static int FREEFORM_TRANSCRIPT
          General transcription
static int FREEFORM_VOICEMAIL
          A voice mail transcription
 
Method Summary
 void addAlias(java.lang.String aliasName, java.lang.String[] phrases)
           Adds an alias to use inside of a command.
 void addCommand(java.lang.String commandPhrase)
          Adds a new command phrase.
 void addCommand(java.lang.String[] commandPhrases)
          Adds a new command phrase.
 void cancelRecord()
          Cancels a recording in progress and dismisses the current prompt if one is visible.
 void clear()
          Clears all commands and aliases from this SpeechRecognizer object.
 void clearMetaAndOptionalCommands()
          Clears any associated meta and optional parameters.
 void copyMeta(MetaData metadata)
          Copies meta data information over to the speech recognizer object.
static SpeechRecognizer getInstance(java.lang.String ApiKey, boolean production)
          Gets an instance of the iSpeech SpeechRecognizer class.
 void setFreeForm(int freeFormType)
          Set to free form recognition.
 void setLanguage(java.lang.String localeCode)
          Set the speech recognition language.
 void setOptionalCommand(java.lang.String command, java.lang.String parameter)
          Specify additional parameters to send to the server.
 boolean startRecordAndNotify(boolean recordBluetooth, long notifyInMillisec, SpeechRecognizer.SpeechRecognizerEvent speechRecognizerEvent)
          Start recording.
 SpeechRecognizer.SpeechResult stopRecord()
          Stops the recording process and returns a SpeechRecognizer.SpeechResult.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FREEFORM_DISABLED

public static final int FREEFORM_DISABLED
Disable free form speech recognition.

See Also:
Constant Field Values

FREEFORM_SMS

public static final int FREEFORM_SMS
A SMS or TXT message.

See Also:
Constant Field Values

FREEFORM_VOICEMAIL

public static final int FREEFORM_VOICEMAIL
A voice mail transcription

See Also:
Constant Field Values

FREEFORM_DICTATION

public static final int FREEFORM_DICTATION
Free form dictation, such as a written document

See Also:
Constant Field Values

FREEFORM_MESSAGE

public static final int FREEFORM_MESSAGE
A message addressed to another person.

See Also:
Constant Field Values

FREEFORM_INSTANT_MESSAGE

public static final int FREEFORM_INSTANT_MESSAGE
A message for an instant message client

See Also:
Constant Field Values

FREEFORM_TRANSCRIPT

public static final int FREEFORM_TRANSCRIPT
General transcription

See Also:
Constant Field Values

FREEFORM_MEMO

public static final int FREEFORM_MEMO
A memo or a list of items

See Also:
Constant Field Values
Method Detail

setFreeForm

public void setFreeForm(int freeFormType)
Set to free form recognition. Will not use any command or alias list. Your API key must be provisioned to use this feature. One of the SpeechRecognizer.FREEFORM_ values. Most developer accounts can use FREEFORM_DICTATION as a parameter.


setOptionalCommand

public void setOptionalCommand(java.lang.String command,
                               java.lang.String parameter)
Specify additional parameters to send to the server.


clearMetaAndOptionalCommands

public void clearMetaAndOptionalCommands()
Clears any associated meta and optional parameters.


copyMeta

public void copyMeta(MetaData metadata)
              throws java.lang.Exception
Copies meta data information over to the speech recognizer object. This only copies, it does not maintain or use the class reference.

Parameters:
metadata -
Throws:
java.lang.Exception

addAlias

public void addAlias(java.lang.String aliasName,
                     java.lang.String[] phrases)

Adds an alias to use inside of a command. You can reference the added alias using %ALIASNAME% from within a command. Alias names are automatically capitalized. Note: You can only a maximum of two aliases per command.

Example:

 SpeechRecognizer rec = SpeechRecognizer.getInstance("APIKEY");
 String[] names = new String[] { "jane", "bob", "john" };
 rec.addAlias("NAMES", names);
 rec.addCommand("call %NAMES%");
 

The user can now speak "call john" and it will be recognized correctly.

Parameters:
aliasName - The name of your alias for referencing inside of your commands.
phrases - The list of phrases for this alias.

clear

public void clear()
Clears all commands and aliases from this SpeechRecognizer object.


addCommand

public void addCommand(java.lang.String[] commandPhrases)
Adds a new command phrase. Note: You can only use two aliases per command.

Example:

 SpeechRecognizer rec = SpeechRecognizer.getInstance("APIKEY");
 String commands = new String(){"yes","no"};
 rec.addCommand(commands);
 

The user can now speak "Yes" or "No" and it will be recognized correctly.

Parameters:
commandPhrases - An array containing your command phrases

addCommand

public void addCommand(java.lang.String commandPhrase)
Adds a new command phrase. Note: You can only use two aliases per command.

Example:

 SpeechRecognizer rec = SpeechRecognizer.getInstance("APIKEY");
 rec.addCommand("yes");
 rec.addCommand("no");
 

The user can now speak "Yes" or "No" and it will be recognized correctly.

Parameters:
commandPhrase - A command phrase

cancelRecord

public void cancelRecord()
Cancels a recording in progress and dismisses the current prompt if one is visible.


stopRecord

public SpeechRecognizer.SpeechResult stopRecord()
                                         throws java.lang.IllegalArgumentException,
                                                ApiException,
                                                InvalidApiKeyException
Stops the recording process and returns a SpeechRecognizer.SpeechResult.

Returns:
SpeechRecognizer.SpeechResult with the text string of the audio and a float containing the estimated confidence.
Throws:
ApiException - The server could not process your command and an API exception occurred.
java.lang.IllegalArgumentException - if your command list is invalid or your commands are too complex. Note: You can only a maximum of two aliases per command.
InvalidApiKeyException - if your API key is invalid.

startRecordAndNotify

public boolean startRecordAndNotify(boolean recordBluetooth,
                                    long notifyInMillisec,
                                    SpeechRecognizer.SpeechRecognizerEvent speechRecognizerEvent)
                             throws java.lang.Exception
Start recording. This method does not block, a RECORDING_COMPLETE event will be triggered when notifyInMillisec time elapses.

Parameters:
recordBluetooth - Record from a connected bluetooth headset instead of the device
notifyInMillisec - The amount of time in milliseconds to record audio. After this time expires, a RECORDING_COMPLETE event will be triggered.
speechRecognizerEvent - A SpeechRecognizerEvent to receive status updates and messages.
Returns:
true if setup was successful
Throws:
java.lang.Exception

getInstance

public static SpeechRecognizer getInstance(java.lang.String ApiKey,
                                           boolean production)
                                    throws InvalidApiKeyException
Gets an instance of the iSpeech SpeechRecognizer class. The ApiKey parameter is only required on initial call to this method.

Parameters:
ApiKey - Your API key provided by iSpeech.
production - Set to true if you are deploying your application. Set to false if you are using the sandbox environment.
Throws:
InvalidApiKeyException

setLanguage

public void setLanguage(java.lang.String localeCode)
Set the speech recognition language.

Parameters:
localeCode - Visit the iSpeech Developers center at http://www.ispeech.org or contact sales@ispeech.org to obtain a list of valid locale codes enabled for your account.