Class VuzixSpeechClient
Introduction
The Vuzix Speech Recognizer is a fully embedded, fast, phrase-matching recognition system designed to interpret and respond to voice commands. A platform base vocabulary is available to all apps; it is intended to facilitate default navigation and selection without direction from the client app. That is, a client app can benefit from navigation provided by a base vocabulary with no setup or explicit awareness of the speech recognizer. This capability is implemented by mapping phrases to Android key events (android.view.KeyEvent).
For many applications, it is desirable to implement a custom vocabulary which performs application-specific actions when an application-specific phrase is spoken (e.g. to capture a still image when “take a picture” is spoken.) The Vuzix Speech Recognition system provides two mechanisms by which this can be achieved: Android key events as previously described and Android intents.
Custom Vocabulary Architecture
The Vuzix Speech Recognizer is notified of context switches in Android when each activity's onResume() is called. In response, the recognizer checks for a custom vocabulary associated with the resumed activity. If found, the recognizer switches to this vocabulary. Any activity without a custom vocabulary will instead use the base vocabulary.
Custom Vocabulary Usage
A custom vocabulary for an activity should be specified in its onCreate() method using a constructor like:
VuzixSpeechClient sc = new VuzixSpeechClient(this);
This allows the custom vocabulary to be created when the VuzixSpeechClient class is instantiated. The new custom vocabulary initially inherits the platform base vocabulary which is documented on the developer center of www.vuzix.com. You can also view the base vocabulary on your device by saying "Hello Vuzix, speech commands".
The custom vocabulary can then have the inherited phrases removed or replaced if needed, and new phrases added
The phrases associated with navigation generate a keycode when the phrase is spoken. Phrases associated with intents cause the intent to be delivered when the phrase is spoken.
Getting Started
New users should start with the simplest command: insertPhrase(String phrase)- Since:
- SDK version 1.2
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Valid values for getSpeechTolerance() and setSpeechTolerance() -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Intent action used to notify SDK clients of certain phrases recognized by the speech engine and certain speech engine states.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with launching the Alexa application.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with launching the Google Assistant application.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with launching the currently preferred assistant, such as Google or Alexa.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with clearing all Android notifications.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with opening the help page that shows the list of all available speech commands.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with turning off the flashlight.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with turning on the flashlight.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with causing the system to go to sleep.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with opening the system-wide speech settings application.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with recording a video.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with taking a photograph.static final int
Parameter forgetBuiltInActionPhrases(int)
to request phrases associated with viewing the system Android notifications.static final String
String extra sent only to AccessibilityService to request pause/resumestatic final String
String extra used only by InputMethodService to provide a phrase.static final String
String extra used only by InputMethodService to provide a substitution.static final String
Extra sent when an internal change in the speech recognizer requires that client apps reload any custom vocabularies.static final int
This keyCode may only be a repeating action, such as "scroll left".static final int
This keyCode may be a single-press action, such as "move left" or a repeating action such as "scroll left".static final int
This keyCode may only be a single-press action, such as "move left".static final String
Intent extra used to notify clients of a recognized phrase.static final String
Intent extra used to notify clients when the speech recognizer becomes active or inactive. -
Constructor Summary
ConstructorDescriptionVuzixSpeechClient
(android.accessibilityservice.AccessibilityService service) Constructs a speech SDK client for an AccessibilityService Using this will install the custom vocabulary for your AccessibilityService.VuzixSpeechClient
(android.app.Activity activity) Constructs a speech SDK client for an Activity.VuzixSpeechClient
(android.app.Fragment fragment) Deprecated.This is only supported by M300.VuzixSpeechClient
(android.inputmethodservice.InputMethodService service) Constructs a speech SDK client for an InputMethodService. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Stops any characters that are repeating, such as those resulting from "scroll down".boolean
This method invokes a named control method without parameters.boolean
Invokes a named control method with parameters.static String
convertPhraseToReplyFormat
(String phrase) Converts a phrase to the format it will be returned if detected by the engine For certain phrases, the speech engine sends an intent of action ACTION_VOICE_COMMAND along with a PHRASE_STRING_EXTRA containing a representation of the recognized phrase.boolean
defineIntent
(String label, android.content.Intent intent) Define an arbitrary Intent that may be associated with phrases.boolean
Deletes all phrases.boolean
deleteAllPhrasesExcept
(List<String> exceptions) Deletes all phrases except the list that you wish to keep.boolean
deleteIntent
(String label) Delete an Intent previously registered bydefineIntent(java.lang.String,android.content.Intent)
.boolean
deletePhrase
(String phrase) Deletes a single phrase from the current client vocabulary.dump()
Dumps the content of the entire speech recognition phrase map to a String.static void
EnableRecognizer
(boolean enabled) Deprecated.UseEnableRecognizer(android.content.Context,boolean)
instead.static void
EnableRecognizer
(android.content.Context context, boolean enabled) Enables or disables the Speech Recognition engine programmatically.boolean
Gets the system-wide "Bluetooth input" setting.getBuiltInActionPhrases
(int builtInAction) Gets the phrase associated with a built-in action, such as illuminating the flashlight.static float
Query the device for the version of the speech engine backing the SDK calls.Lists all available intent labels as previously defined by calls todefineIntent(java.lang.String,android.content.Intent)
.getIntentPhrases
(String intentLabel) Gets the phrases associated with a specific intent label.getKeycodePhrases
(int keycode, int keyFrequency) Gets the phrases associated with a key event.getMappedKeycodes
(int keyFrequency) Get all keycodes that have an associated phrase in the vocabulary.Get the list of active phrases for this client.getPhrases
(String substitution) Get the subset of active phrases matching a specific substitution.int
Gets the configured speech recognizer timeout value.int
Gets the maximum value allowed for setRecognizerTimeoutConfig().boolean
Gets the system-wide "Listen while asleep" setting.Gets the system-wide "Pronunciation tolerance" setting.Gets all stop phrases including pre-defined and those created by callinginsertStopPhrase(java.lang.String)
.Lists all vocabularies previously saved by the current activity.getSubstitution
(String phrase) Get the optional substitution associated with a phrase.Gets all voice-off phrases including pre-defined and those created by callinginsertVoiceOffPhrase(java.lang.String)
.Gets all wake-words including pre-defined and those created by callinginsertWakeWordPhrase(java.lang.String)
.boolean
insertIntentPhrase
(String phrase, String intentLabel) Insert a phrase to generate the specified intent upon the phrase being detected.boolean
insertIntentPhrase
(String phrase, String intentLabel, String params) Insert a phrase to generate the specified intent upon the phrase being detected, with extra undocumented parameters.boolean
insertKeycodePhrase
(String phrase, int keycode) Inserts a phrase to generate a keycode that will be sent upon detection.boolean
insertKeycodePhrase
(String phrase, int keycode, int repeatIntervalMs) Inserts a phrase to generate a keycode that will be sent repeatedly upon detection.boolean
insertKeycodePhrase
(String phrase, int keycode, int repeatIntervalMs, String params) Inserts a phrase to generate a keycode that will be sent repeatedly upon detection, with extra undocumented capabilities.boolean
insertKeycodePhrase
(String phrase, int keycode, String params) Inserts a phrase to generate keycodes upon detection, with extra undocumented capabilities.boolean
insertPhrase
(String phrase) This is the most basic way to insert a phrase into the recognizer.boolean
insertPhrase
(String phrase, String substitution) Inserts a phrase and provides a substitution to make processing easier for the client.boolean
insertStopPhrase
(String phrase) Insert a phrase to stop any repeating character that may be active.boolean
insertVoiceOffPhrase
(String phrase) Insert a phrase to deactivate the recognizer, as done by "voice off" in the base vocabulary.boolean
insertWakeWordPhrase
(String phrase) Insert a phrase to wake the recognizer, as done by "Hello, Vuzix" in the base vocabulary.static boolean
isRecognizerEnabled
(android.content.Context context) Determines if the speech recognizer is currently enabled in Settings.static boolean
isRecognizerInitialized
(android.content.Context context) Determines if the speech recognizer has been initialized.static boolean
isRecognizerTriggered
(android.content.Context context) Determines if the speech recognizer is currently triggered and listening for the full vocabulary.boolean
removeVocabulary
(String name) Remove and delete the recognizer vocabulary in the vocabulary store represented by "name".boolean
retrieveVocabulary
(String name) Replace the current activity vocabulary with the vocabulary from the vocabulary store represented by "name".void
setBluetoothSetting
(boolean value) Sets the system-wide "Bluetooth input" setting.boolean
setRecognizerTimeoutConfig
(int timeoutSecs) Sets the configured speech recognizer timeout value.void
setSleepEnableSetting
(boolean value) Sets the system-wide "Listen while asleep" setting.void
Sets the system-wide "Pronunciation tolerance" setting.static void
startGlobalSpeechSettingsActivity
(android.content.Context context) Open the global system-wide settings screen for the speech commands.boolean
storeVocabulary
(String name) Save a recognizer vocabulary in the vocabulary store for later use.static void
Deprecated.UseTriggerVoiceAudio(android.content.Context,boolean)
instead with the triggered parameter set true.static void
TriggerVoiceAudio
(boolean triggered) Deprecated.UseTriggerVoiceAudio(android.content.Context,boolean)
instead.static void
TriggerVoiceAudio
(android.content.Context context) Triggers the Speech Recognition engine programmatically.static void
TriggerVoiceAudio
(android.content.Context context, boolean triggered) Triggers or deactivates the Speech Recognition engine programmatically.
-
Field Details
-
ACTION_VOICE_COMMAND
Intent action used to notify SDK clients of certain phrases recognized by the speech engine and certain speech engine states.Use this string to register for Intents coming from the Speech Client.
For example, from a class implementing BroadcastHandler: yourActivity.registerReceiver(this, new IntentFilter(VuzixSpeechClient.ACTION_VOICE_COMMAND));
- Since:
- SDK version 1.2
- See Also:
-
BUILT_IN_ACTION_ASSISTANT
public static final int BUILT_IN_ACTION_ASSISTANTParameter forgetBuiltInActionPhrases(int)
to request phrases associated with launching the currently preferred assistant, such as Google or Alexa.- See Also:
-
BUILT_IN_ACTION_ASSIST_ALEXA
public static final int BUILT_IN_ACTION_ASSIST_ALEXAParameter forgetBuiltInActionPhrases(int)
to request phrases associated with launching the Alexa application.- See Also:
-
BUILT_IN_ACTION_ASSIST_GOOGLE
public static final int BUILT_IN_ACTION_ASSIST_GOOGLEParameter forgetBuiltInActionPhrases(int)
to request phrases associated with launching the Google Assistant application.- See Also:
-
BUILT_IN_ACTION_CLEAR_NOTIFICATIONS
public static final int BUILT_IN_ACTION_CLEAR_NOTIFICATIONSParameter forgetBuiltInActionPhrases(int)
to request phrases associated with clearing all Android notifications.- See Also:
-
BUILT_IN_ACTION_COMMAND_LIST
public static final int BUILT_IN_ACTION_COMMAND_LISTParameter forgetBuiltInActionPhrases(int)
to request phrases associated with opening the help page that shows the list of all available speech commands.- See Also:
-
BUILT_IN_ACTION_FLASHLIGHT_OFF
public static final int BUILT_IN_ACTION_FLASHLIGHT_OFFParameter forgetBuiltInActionPhrases(int)
to request phrases associated with turning off the flashlight.- See Also:
-
BUILT_IN_ACTION_FLASHLIGHT_ON
public static final int BUILT_IN_ACTION_FLASHLIGHT_ONParameter forgetBuiltInActionPhrases(int)
to request phrases associated with turning on the flashlight.- See Also:
-
BUILT_IN_ACTION_SLEEP
public static final int BUILT_IN_ACTION_SLEEPParameter forgetBuiltInActionPhrases(int)
to request phrases associated with causing the system to go to sleep.- See Also:
-
BUILT_IN_ACTION_SPEECH_SETTINGS
public static final int BUILT_IN_ACTION_SPEECH_SETTINGSParameter forgetBuiltInActionPhrases(int)
to request phrases associated with opening the system-wide speech settings application.- See Also:
-
BUILT_IN_ACTION_START_RECORDING
public static final int BUILT_IN_ACTION_START_RECORDINGParameter forgetBuiltInActionPhrases(int)
to request phrases associated with recording a video.- See Also:
-
BUILT_IN_ACTION_TAKE_PHOTO
public static final int BUILT_IN_ACTION_TAKE_PHOTOParameter forgetBuiltInActionPhrases(int)
to request phrases associated with taking a photograph.- See Also:
-
BUILT_IN_ACTION_VIEW_NOTIFICATIONS
public static final int BUILT_IN_ACTION_VIEW_NOTIFICATIONSParameter forgetBuiltInActionPhrases(int)
to request phrases associated with viewing the system Android notifications.- See Also:
-
EXTRA_PAUSE_ACCESSIBILITY
String extra sent only to AccessibilityService to request pause/resume- Since:
- SDK version 1.94
- See Also:
-
EXTRA_VOCAB_KB_PHRASES
String extra used only by InputMethodService to provide a phrase.- Since:
- SDK version 1.8
- See Also:
-
EXTRA_VOCAB_KB_SUBSTITUTION
String extra used only by InputMethodService to provide a substitution.- Since:
- SDK version 1.8
- See Also:
-
EXTRA_VOCAB_RELOAD_REQUIRED
Extra sent when an internal change in the speech recognizer requires that client apps reload any custom vocabularies.- Since:
- SDK version 1.96
- See Also:
-
KEY_FREQ_REPEATING
public static final int KEY_FREQ_REPEATINGThis keyCode may only be a repeating action, such as "scroll left". Used bygetKeycodePhrases(int,int)
andgetMappedKeycodes(int)
- See Also:
-
KEY_FREQ_SINGLE_OR_REPEAT
public static final int KEY_FREQ_SINGLE_OR_REPEATThis keyCode may be a single-press action, such as "move left" or a repeating action such as "scroll left". Used bygetKeycodePhrases(int,int)
andgetMappedKeycodes(int)
- See Also:
-
KEY_FREQ_SINGLE_PRESS
public static final int KEY_FREQ_SINGLE_PRESSThis keyCode may only be a single-press action, such as "move left". Used bygetKeycodePhrases(int,int)
andgetMappedKeycodes(int)
- See Also:
-
PHRASE_STRING_EXTRA
Intent extra used to notify clients of a recognized phrase.Clients will receive an intent with this String extra and an action ACTION_VOICE_COMMAND whenever a custom phrase they have inserted is recognized.
- Since:
- SDK version 1.2
- See Also:
-
RECOGNIZER_ACTIVE_BOOL_EXTRA
Intent extra used to notify clients when the speech recognizer becomes active or inactive.Clients will receive an intent with this boolean extra and an action ACTION_VOICE_COMMAND whenever the recognizer is triggered (ie: "Hello Vuzix") and becomes active, or times-out and returns its inactive idle state listening for the wake-up phrase.
When the recognizer begins to listen, the boolean is set true. When the recognizer ceases to listen, the boolean is set false
- Since:
- SDK version 1.4
- See Also:
-
-
Constructor Details
-
VuzixSpeechClient
public VuzixSpeechClient(android.app.Activity activity) throws android.os.RemoteException Constructs a speech SDK client for an Activity.Using this will install the custom vocabulary for your entire Activity. Initially your custom vocabulary will be an exact copy of the system default vocabulary.
- Parameters:
activity
- The Activity in which this custom vocabulary will operate.- Throws:
android.os.RemoteException
- if the Vuzix speech engine is not running on this device.- Since:
- SDK version 1.2
-
VuzixSpeechClient
@Deprecated public VuzixSpeechClient(android.app.Fragment fragment) throws IllegalArgumentException, android.os.RemoteException Deprecated.This is only supported by M300. Newer products do not support this. UseVuzixSpeechClient(android.app.Activity)
instead.Constructor from a Fragment. Using this will install the custom vocabulary for a single Fragment within your Activity.WARNING Not supported by Blade and M400 and not recommended for new development.
- Parameters:
fragment
- The Fragment in which this custom vocabulary will operate.- Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.IllegalArgumentException
- if the device does not support this interface.- Since:
- SDK version 1.2
-
VuzixSpeechClient
public VuzixSpeechClient(android.inputmethodservice.InputMethodService service) throws android.os.RemoteException Constructs a speech SDK client for an InputMethodService. Using this will install the custom vocabulary for your InputMethodService.- Parameters:
service
- The InputMethodService in which this custom vocabulary will operate.- Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.8
-
VuzixSpeechClient
public VuzixSpeechClient(android.accessibilityservice.AccessibilityService service) throws android.os.RemoteException Constructs a speech SDK client for an AccessibilityService Using this will install the custom vocabulary for your AccessibilityService.- Parameters:
service
- The AccessibilityService in which this custom vocabulary will operate.- Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.92
-
-
Method Details
-
dump
Dumps the content of the entire speech recognition phrase map to a String.The client is responsible for logging or printing this information
This is used for debugging. It includes inherited entries and custom entries. See
getPhrases()
for a more user-friendly method to query the vocabulary.- Returns:
- A single String with a phrase pair per row, separated by carriage returns.
- Since:
- SDK version 1.2
- See Also:
-
getPhrases
Get the list of active phrases for this client.Returns the current list of phrases. This may include both built-in and user-added phrases. Note, the capitalization may have been modified since the phrase was inserted, so please use case insensitive comparisons if parsing this, and conversions to title case or sentence case may be preferred for displaying the phrases to users.
- Returns:
- The complete list of phrase strings currently being recognized for this activity.
- Since:
- SDK version 1.6
-
getBuiltInActionPhrases
Gets the phrase associated with a built-in action, such as illuminating the flashlight.This is useful for creating help messages to instruct users of available voice commands. It may also be used to find unwanted phrases to delete. The advantage of querying the SDK for these phrases is the device may change the phrases in the various supported language when the system is updated. This ensures your application knows the current active phrases.
Note: Not all built-in actions apply to all devices. Unsupported actions will simply return an empty list, so all actions are valid parameters on all devices.
- Parameters:
builtInAction
- - May be one of:BUILT_IN_ACTION_SLEEP
BUILT_IN_ACTION_COMMAND_LIST
BUILT_IN_ACTION_SPEECH_SETTINGS
BUILT_IN_ACTION_FLASHLIGHT_ON
BUILT_IN_ACTION_FLASHLIGHT_OFF
BUILT_IN_ACTION_VIEW_NOTIFICATIONS
BUILT_IN_ACTION_CLEAR_NOTIFICATIONS
BUILT_IN_ACTION_START_RECORDING
BUILT_IN_ACTION_TAKE_PHOTO
BUILT_IN_ACTION_ASSISTANT
BUILT_IN_ACTION_ASSIST_ALEXA
BUILT_IN_ACTION_ASSIST_GOOGLE
- Returns:
- List of phrase strings that match the specified built-in action.
- Since:
- SDK version 1.8
-
getPhrases
Get the subset of active phrases matching a specific substitution.Since multiple phrases may have the same substitution, this provides a way to see what is currently active.
- Parameters:
substitution
- The substitution as passed toinsertPhrase(java.lang.String,java.lang.String)
or null to get all phrases that have no explicit substitution.- Returns:
- List of phrase strings that map to the provided substitution.
- Since:
- SDK version 1.8
-
insertPhrase
This is the most basic way to insert a phrase into the recognizer.For Example: sc.insertPhrase("take photo"));
The phrase will be provided unchanged (note: spaces are replaced by underscores) in a "phrase" string extra in the intent as demonstrated below:
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(VuzixSpeechClient.ACTION_VOICE_COMMAND)) { String phrase = intent.getStringExtra("phrase"); if (phrase != null && phrase.equals("take_photo")) { // Do something } } }
This method is useful fur developers learning to use the Speech Client. For commercialized apps, it is recommended that the optional substitution is provided using the method
insertPhrase(java.lang.String,java.lang.String)
instead of this method- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.- Returns:
- True if the phrase is added. False otherwise.
- Throws:
IllegalArgumentException
- if the phrase is not valid.- Since:
- SDK version 1.2
- See Also:
-
insertPhrase
Inserts a phrase and provides a substitution to make processing easier for the client.Similar to
insertPhrase(java.lang.String)
This inserts a phrase to recognize and defines a substitution. The substitution will be returned when the phrase is recognized. This is useful when dealing with localize recognition phrases. Regardless of the active language, the substitution string will always be identified to your code.
For Example, instead of: sc.insertPhrase("take photo")); use: sc.insertPhrase(mContext.getString(R.string.voice_cmd_take_photo), "take_photo");
Regardless of the active language, your code will always receive "take_photo". Your source code then does not need to be modified for localization. The strings.xml resource will take care of this. For example it might have:
English: <string name="voice_cmd_take_photo">take photo</string> French: <string name="voice_cmd_take_photo">prendre une photo</string> German: <string name="voice_cmd_take_photo">machen Sie ein Foto</string> Spanish: <string name="voice_cmd_take_photo">toma una foto</string> Chinese: <string name="voice_cmd_take_photo">拍照</string> etc.
The recognized phrase will be correctly selected based on localization (note that the recognizer itself must have the correct language recognition files loaded.)
- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.substitution
- The substitution that will be returned upon detecting the phrase. This should likely be a constant value not a localized resource.- Returns:
- True if the phrase is added. False otherwise.
- Throws:
IllegalArgumentException
- if the arguments are not valid.- Since:
- SDK version 1.2
- See Also:
-
getSubstitution
Get the optional substitution associated with a phrase.Any phrase added with the
insertPhrase(java.lang.String,java.lang.String)
method will have an optional substitution associated with it. This method allows retrieval of the substitution associated with a given phrase.- Parameters:
phrase
- The phrase as passed toinsertPhrase(java.lang.String,java.lang.String)
.- Returns:
- substitution as passed to
insertPhrase(java.lang.String,java.lang.String)
or null if the phrase is not found. - Since:
- SDK version 1.9
-
insertKeycodePhrase
public boolean insertKeycodePhrase(String phrase, int keycode, int repeatIntervalMs, String params) throws IllegalArgumentException Inserts a phrase to generate a keycode that will be sent repeatedly upon detection, with extra undocumented capabilities.Sending repeating keycodes provides the ability to make scrolling behavior.
Similar to
insertKeycodePhrase(java.lang.String,int)
. This adds optional repeat interval and optional internal speech recognizer parameters.- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.keycode
- The key code as defined in android.view.KeyEvent (ie: KEYCODE_ENTER)repeatIntervalMs
- The interval in milliseconds at which the keycode event will be generated.params
- Additional parameters (undocumented - use only under the direction of Vuzix technical support).- Returns:
- True if the phrase is added. False otherwise.
- Throws:
IllegalArgumentException
- if the phrase is not valid.- Since:
- SDK version 1.2
- See Also:
-
insertKeycodePhrase
Inserts a phrase to generate keycodes upon detection, with extra undocumented capabilities.Similar to
insertKeycodePhrase(java.lang.String,int)
. This adds optional internal speech recognizer parameters to be used at the direction of Vuzix technical support.- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.keycode
- The key code as defined in android.view.KeyEvent (ie: KEYCODE_ENTER).params
- Additional parameters (undocumented - use only under direction of Vuzix technical support).- Returns:
- True if the phrase is added. False otherwise.
- Since:
- SDK version 1.2
- See Also:
-
insertKeycodePhrase
Inserts a phrase to generate a keycode that will be sent repeatedly upon detection.Similar to
insertKeycodePhrase(java.lang.String,int keycode)
This repeats the key at the specified interval until a new phrase (e.g. "stop") is recognized
- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.keycode
- The key code as defined in android.view.KeyEvent (ie: KEYCODE_ENTER)repeatIntervalMs
- The interval in milliseconds at which the keycode event will be generated.- Returns:
- True if the phrase is added. False otherwise.
- Since:
- SDK version 1.2
- See Also:
-
insertKeycodePhrase
Inserts a phrase to generate a keycode that will be sent upon detection.This is the most basic way to insert a phrase that will generate a keycode.
Upon recognition of a phrase, the recognizer may be configured to generate an Android key event, just as if a key had been pressed on a physical keypad.
Example: sc.insertKeycodePhrase("zero", KeyEvent.KEYCODE_0); or better: sc.insertKeycodePhrase(mContext.getString(R.string.voice_cmd_zero), KeyEvent.KEYCODE_0);
- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.keycode
- The key code as defined in android.view.KeyEvent (ie: KEYCODE_ENTER).- Returns:
- True if the phrase is added. False otherwise.
- Since:
- SDK version 1.2
-
getKeycodePhrases
Gets the phrases associated with a key event.These phrases can be filtered to exclude repeating keys, to only return repeating keys, or to include all.
This is useful for creating help messages to instruct users of possible voice commands and may be used for finding unwanted phrases to delete. The advantage of querying the SDK for these phrases is the device may change the phrases in the various supported language when the system is updated. This ensures your application knows the current active phrases.
For example, to get the "scroll left" phrase, you could use:
phrases = getKeycodePhrase(KEYCODE_DPAD_LEFT, KEY_FREQ_REPEATING);
- Parameters:
keycode
- The key code as defined in android.view.KeyEvent (ie: KEYCODE_ENTER)keyFrequency
- May be one of- Returns:
- List of phrase strings matching the criteria.
- Since:
- SDK version 1.8
-
getMappedKeycodes
Get all keycodes that have an associated phrase in the vocabulary.- Parameters:
keyFrequency
- May be one of- Returns:
- List of key code values (as defined in android.view.KeyEvent) with which there is currently a speech phrase associated.
- Since:
- SDK version 1.8
-
convertPhraseToReplyFormat
Converts a phrase to the format it will be returned if detected by the engine For certain phrases, the speech engine sends an intent of action ACTION_VOICE_COMMAND along with a PHRASE_STRING_EXTRA containing a representation of the recognized phrase. That representation matches the original phrase with whitespace replaced by underscores. This utility converts requested phrases into the same format. You can compare the output of this method against phrases from the PHRASE_STRING_EXTRA to determine if it was the detected phrase.- Parameters:
phrase
- The phrase for which the Speech recognizer will listen- Returns:
- String modified to match what is returned by the speech engine
- Since:
- SDK version 1.93
-
insertIntentPhrase
public boolean insertIntentPhrase(String phrase, String intentLabel, String params) throws IllegalArgumentException, android.os.RemoteException Insert a phrase to generate the specified intent upon the phrase being detected, with extra undocumented parameters.Similar to
insertIntentPhrase(java.lang.String,java.lang.String)
. This should only be used when directed by Vuzix Technical Support.- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.intentLabel
- The label matching one previously registered usingdefineIntent(java.lang.String,android.content.Intent)
.params
- String parameters (undocumented - use only under the direction of Vuzix technical support).- Returns:
- True if the phrase is added. False otherwise.
- Throws:
IllegalArgumentException
- if the phrase, intentLabel, or params are not valid.android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.2
- See Also:
-
insertIntentPhrase
public boolean insertIntentPhrase(String phrase, String intentLabel) throws android.os.RemoteException Insert a phrase to generate the specified intent upon the phrase being detected.If the preformed intent is not sufficient for the app use case, an arbitrarily defined intent may be used. In this case, the intent must be defined for the vocabulary as well as be registered in the app's intent filter and parsed in the app's intent receiver.
A free-form intent may have an arbitrarily specified Action, Data, Type, and Component, and may contain extras. The extras are limited to Boolean, Integer, and String types. Probably the most useful free-form intent case is use of a custom Action; this will target the broadcast intent from the recognizer to this application.
The Intent to be broadcast must be specified to the vocabulary using
defineIntent(java.lang.String,android.content.Intent)
before the associated intentLabel can be used here.Note: Intents are sent with sendBroadcastAsUser() from the service. They will not start new activities as would happen from startActivityForResult().
Note that the same intent (as identified by this label) may be associated with many phrases:
sc.insertIntentPhrase("focus image", “cam_focus”); sc.insertIntentPhrase("do focus", “cam_focus”); sc.insertIntentPhrase("sharpen image", “cam_focus”);
(While these examples use fixed strings for the sake of clarity, the use of string resources to facilitate localization is highly recommended.)
- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.intentLabel
- The label matching one previously registered usingdefineIntent(java.lang.String,android.content.Intent)
.- Returns:
- True if the phrase is added. False otherwise.
- Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.2
- See Also:
-
getIntentPhrases
Gets the phrases associated with a specific intent label.- Parameters:
intentLabel
- The label matching one previously registered usingdefineIntent(java.lang.String,android.content.Intent)
.- Returns:
- List of phrase strings matching the criteria.
- Since:
- SDK version 1.8
-
insertWakeWordPhrase
Insert a phrase to wake the recognizer, as done by "Hello, Vuzix" in the base vocabulary.This function allows for developers to use custom wake phrase, such as "welcome to my app". The default wake phrases may be deleted if desired so that only the custom wake phrase is present.
- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.- Returns:
- True if the phrase is added. False otherwise.
- Throws:
IllegalArgumentException
- Since:
- SDK version 1.5
-
getWakeWordPhrases
Gets all wake-words including pre-defined and those created by callinginsertWakeWordPhrase(java.lang.String)
.- Returns:
- List of phrase strings that wake the device.
- Since:
- SDK version 1.8
- See Also:
-
insertStopPhrase
Insert a phrase to stop any repeating character that may be active.The engine always stops repeating characters upon recognizing any other phrase. The stop phrase allows us to recognize a valid phrase that has no other action.
- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.- Returns:
- True if the phrase is added. False otherwise.
- Throws:
IllegalArgumentException
- Since:
- SDK version 1.8
-
getStopPhrases
Gets all stop phrases including pre-defined and those created by callinginsertStopPhrase(java.lang.String)
.- Returns:
- List of phrase strings that stop previous scrolling behavior.
- Since:
- SDK version 1.8
- See Also:
-
insertVoiceOffPhrase
Insert a phrase to deactivate the recognizer, as done by "voice off" in the base vocabulary.- Parameters:
phrase
- The phrase for which the Speech recognizer will listen. This should likely be a localized string from a resource file.- Returns:
- True if the phrase is added. False otherwise.
- Throws:
IllegalArgumentException
- Since:
- SDK version 1.3
-
getVoiceOffPhrases
Gets all voice-off phrases including pre-defined and those created by callinginsertVoiceOffPhrase(java.lang.String)
.- Returns:
- List of phrase strings that disable speech input.
- Since:
- SDK version 1.8
- See Also:
-
deleteAllPhrasesExcept
Deletes all phrases except the list that you wish to keep.- Parameters:
exceptions
- The list of phrases to keep. All other phrases will be deleted.- Returns:
- True if all phrases other than the exception list are deleted successfully.
- Since:
- SDK version 1.8
-
deleteAllPhrases
public boolean deleteAllPhrases()Deletes all phrases.Note: this is primarily used when re-defining a vocabulary. To stop the recognizer from functioning you may use EnableRecognizer(false) instead of deleting the phrases.
- Returns:
- True if all phrases are deleted successfully.
- Since:
- SDK version 1.8
-
deletePhrase
Deletes a single phrase from the current client vocabulary.You may delete phrases inherited from the base vocabulary as well as those you have added yourself.
Note that the deletion is in effect only when this activity is running; the base vocabulary which is used outside the context of this activity is not affected.
For Example: sc.deletePhrase("take photo"); or better: sc.deletePhrase( mContext.getString(R.string.voice_cmd_take_photo) );
- Parameters:
phrase
- The phrase to be deleted from the speech recognition map.- Returns:
- True if the phrase is found and deleted. False if the string is not present in the map.
- Throws:
IllegalArgumentException
- if the phrase is not valid.- Since:
- SDK version 1.2
-
defineIntent
public boolean defineIntent(String label, android.content.Intent intent) throws android.os.RemoteException Define an arbitrary Intent that may be associated with phrases.Note: Intents are sent with sendBroadcastAsUser() from the service. They will not start new activities as would happen from startActivityForResult().
This method must be called prior to calling
insertIntentPhrase(java.lang.String,java.lang.String)
For example: Intent focus_intent = new Intent(“com.mycompany.camera.speechrecog”).putExtra("focus", true); sc.defineIntent("cam_focus", focus_intent); sc.insertIntentPhrase("focus image", “cam_focus”);
Here, defineIntent() defines the intent for the vocabulary's later use, assigning it a label (“cam_focus”) by which it will be identified in insertIntentPhrase()
- Parameters:
label
- An arbitrary label by which this new Intent will be identified duringinsertIntentPhrase(java.lang.String,java.lang.String)
intent
- The Intent your Activity wishes to receive.- Returns:
- True if the Intent can be defined. False otherwise.
- Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.2
- See Also:
-
deleteIntent
Delete an Intent previously registered bydefineIntent(java.lang.String,android.content.Intent)
.This method also deletes any phrases that were added with
insertIntentPhrase(java.lang.String,java.lang.String)
and are associated with the Intent being removed.- Parameters:
label
- - the unique string label provided previously todefineIntent(java.lang.String,android.content.Intent)
- Returns:
- True if the intent is deleted. False otherwise.
- Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.91
- See Also:
-
getIntentLabels
Lists all available intent labels as previously defined by calls todefineIntent(java.lang.String,android.content.Intent)
.- Returns:
- All labels provided to
defineIntent(java.lang.String,android.content.Intent)
. - Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.91
- See Also:
-
storeVocabulary
Save a recognizer vocabulary in the vocabulary store for later use.At launch, an application inherits the base speech recognition vocabulary. It will typically modify this vocabulary, adding and deleting phrases to create a vocabulary suited to its use. For a static activity, this is all that is needed, but some activities may dynamically modify the content affected by speech commands, and hence need to modify the vocabulary.
The {store, retrieve, remove} mechanism allows vocabulary "snapshots" to be saved and later retrieved. The snapshot includes phrases, substitutions, and defined intents.
For example, the base vocabulary may be replaced with a vocabulary which supports basic navigation, selection, and processing. This "activity base" vocabulary is then saved, and to it is added the names of several icons being displayed. On "next page", this set of icons is replaced by a new set of icons. The activity retrieves the saved "activity base" vocabulary (which will not contain the names of the previous set of icons) and adds the names of the new set of icons being displayed.
Example: sc.storeVocabulary("SortActivityBase");
- Parameters:
name
- The arbitrary name representing an activity-unique label for this vocabulary snapshot. This label need not be localized.- Returns:
- True if the vocabulary is stored. False otherwise.
- Since:
- SDK version 1.4
-
removeVocabulary
Remove and delete the recognizer vocabulary in the vocabulary store represented by "name".- Parameters:
name
- The arbitrary name previously passed tostoreVocabulary(java.lang.String)
- Returns:
- True if the vocabulary is deleted. False otherwise.
- Since:
- SDK version 1.4
-
retrieveVocabulary
Replace the current activity vocabulary with the vocabulary from the vocabulary store represented by "name".This method replaces the current vocabulary for an activity with the saved snapshot of the activity's vocabulary in the vocabulary store represented by "name". The restored vocabulary includes phrases, substitutions, and defined intents.
- Parameters:
name
- The arbitrary name previously passed tostoreVocabulary(java.lang.String)
- Returns:
- True if the vocabulary replacement is successful. False otherwise.
- Since:
- SDK version 1.4
-
getStoredVocabularyNames
Lists all vocabularies previously saved by the current activity.Vocabularies may have previously been saved by calling
storeVocabulary(java.lang.String)
. This retrieves the list of all such vocabularies. The names are valid for calls toretrieveVocabulary(java.lang.String)
andremoveVocabulary(java.lang.String)
- Returns:
- List of names provided to
storeVocabulary(java.lang.String)
- Throws:
android.os.RemoteException
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.91
-
control
Invokes a named control method with parameters.This interface is not normally required. All expected 3rd party interfaces have explicit methods to be used in place of this. In limited circumstances Vuzix Technical Support may recommend explicit recommendations for using this. It should not be used otherwise.
- Parameters:
type
- The text type of the control. Provided by Vuzix technical support in limited applications.params
- The text value to set to the control. Provided by Vuzix technical support in limited applications.- Returns:
- True if the control is set. False otherwise.
- Since:
- SDK version 1.4
-
control
This method invokes a named control method without parameters.This interface is not normally required. All expected 3rd party interfaces have explicit methods to be used in place of this. In limited circumstances Vuzix Technical Support may recommend explicit recommendations for using this. It should not be used otherwise.
- Parameters:
type
- The text type of the control. Provided by Vuzix technical support in limited applications.- Returns:
- True if the control is set. False otherwise.
- Since:
- SDK version 1.4
-
CancelRepeatingCharacters
public boolean CancelRepeatingCharacters()Stops any characters that are repeating, such as those resulting from "scroll down".Invoking this is similar to the user saying "stop".
- Returns:
- True if the no characters are now repeating. False otherwise.
- Since:
- SDK version 1.6
-
TriggerVoiceAudio
Deprecated.UseTriggerVoiceAudio(android.content.Context,boolean)
instead.Triggers or deactivates the Speech Recognition engine programmatically.It is the equivalent of recognizing the trigger phrase (e.g. "Hello Vuzix") in an audio stream.
- Parameters:
triggered
- True to trigger the recognizer. False to put it to sleep.- Since:
- SDK version 1.4
-
TriggerVoiceAudio
Deprecated.UseTriggerVoiceAudio(android.content.Context,boolean)
instead with the triggered parameter set true.Triggers the Speech Recognition engine programmatically by attempting to determine the context.Note: Use the method with the Context parameter if possible; this method is less reliable.
- Since:
- SDK version 1.3
-
TriggerVoiceAudio
public static void TriggerVoiceAudio(android.content.Context context, boolean triggered) Triggers or deactivates the Speech Recognition engine programmatically.It is the equivalent of recognizing the trigger phrase (e.g. "Hello Vuzix") in an audio stream.
Note: This is the preferred method invocation, explicitly specifying a valid Context.
- Parameters:
context
- The context from which the trigger is being invokedtriggered
- True to trigger the recognizer. False to put it to sleep.- Since:
- SDK version 1.4
-
TriggerVoiceAudio
public static void TriggerVoiceAudio(android.content.Context context) Triggers the Speech Recognition engine programmatically. It is the equivalent ofTriggerVoiceAudio(android.content.Context,boolean)
with the "triggered" parameter set to true.- Parameters:
context
- The context from which the trigger is being invoked- Since:
- SDK version 1.3
- See Also:
-
EnableRecognizer
Deprecated.UseEnableRecognizer(android.content.Context,boolean)
instead.Enables or disables the Speech Recognition engine programmatically by attempting to determine the Context.It is the equivalent of turning on or off the "Enable Vuzix Speech Recognition" switch in the global Settings application.
Use the method with the Context parameter if possible; this method is less reliable.
- Parameters:
enabled
- True to enable the recognizer. False to disable it.- Since:
- SDK version 1.3
- See Also:
-
EnableRecognizer
public static void EnableRecognizer(android.content.Context context, boolean enabled) Enables or disables the Speech Recognition engine programmatically.This is the equivalent of turning on or off the "Enable Vuzix Speech Recognition" switch in the global Settings application.
Note: This is the preferred method invocation, explicitly specifying a valid Context.
- Parameters:
context
- The context from which the trigger is being invoked.enabled
- True to enable voice recognition. False to disable.- Since:
- SDK version 1.3
-
isRecognizerEnabled
public static boolean isRecognizerEnabled(android.content.Context context) Determines if the speech recognizer is currently enabled in Settings.- Parameters:
context
- The context from which the query is being invoked.- Returns:
- True if the engine is enabled.
- Since:
- SDK version 1.7
-
isRecognizerTriggered
public static boolean isRecognizerTriggered(android.content.Context context) Determines if the speech recognizer is currently triggered and listening for the full vocabulary.Note: this is intended to be used for an initial query of the state, and not to be continually re-queried. If you need to display an indication to the user whether the recognizer is triggered or idle, register a broadcast receiver for the intent VuzixSpeechClient.ACTION_VOICE_COMMAND
- Parameters:
context
- The context from which the query is being invoked- Returns:
- True if the engine is actively listening for the full vocabulary. False if the engine is disabled entirely, or idle listening for the trigger phrase.
- Since:
- SDK version 1.7
-
getRecognizerTimeoutConfig
public int getRecognizerTimeoutConfig()Gets the configured speech recognizer timeout value.The speech recognizer will return to idle and listen for wake words after a configured timeout period. This allows you to query that value.
- Returns:
- The timeout value in seconds. Zero indicates infinite timeout. Negative indicates an error.
- Since:
- SDK version 1.91
-
getRecognizerTimeoutMax
public int getRecognizerTimeoutMax()Gets the maximum value allowed for setRecognizerTimeoutConfig().- Returns:
- The maximum allowed timeout value in seconds.
- Since:
- SDK version 1.91
- See Also:
-
setRecognizerTimeoutConfig
public boolean setRecognizerTimeoutConfig(int timeoutSecs) Sets the configured speech recognizer timeout value.The speech recognizer will return to idle and listen for wake words after a configured timeout period. This allows you to configure that value.
NOTE: This configuration is global to the system and shared by all applications.
- Parameters:
timeoutSecs
- int value in seconds. Zero for infinite timeout. Range zero to getRecognizerTimeoutMax()- Returns:
- True if the recognizer configuration is updated. False otherwise.
- Since:
- SDK version 1.91
- See Also:
-
isRecognizerInitialized
public static boolean isRecognizerInitialized(android.content.Context context) Determines if the speech recognizer has been initialized.Note: the speech engine is initialized immediately after the system starts. Normal applications need not check this condition. But certain auto-start applications may be initialized before the speech engine. They must check this before interacting with the speech engine.
- Parameters:
context
- The context from which the query is being invoked.- Returns:
- True if the engine is initialized and speech commands are possible. False if the engine is not yet initialized.
- Since:
- SDK version 1.7
-
startGlobalSpeechSettingsActivity
public static void startGlobalSpeechSettingsActivity(android.content.Context context) Open the global system-wide settings screen for the speech commands. This is the same as if the user had opened Settings and navigated to the speech commands page.- Parameters:
context
- The context from which the activity is to be started- Since:
- SDK version 1.95
-
getEngineVersion
public static float getEngineVersion()Query the device for the version of the speech engine backing the SDK calls.The SDK used at compile-time is often different than the one running on the device.
If the device has a newer SDK than the one against which you compiled, the device has additional capabilities that are inaccessible to your application. You should update your project to pull the latest SDK.
If the device has an older SDK than the one against which you compiled, certain features may be unavailable. You should guard against calling these and handle exceptions properly.
Failure to resolve this method indicates the device is running SDK 1.7 or lower
- Returns:
- The speech engine version number running on the current hardware.
- Since:
- SDK version 1.8
-
getSpeechTolerance
Gets the system-wide "Pronunciation tolerance" setting.This value determines how correctly the user must speak each phrase.
- Returns:
- The speech Tolerance value as a SpeechTolerance enum.
- Throws:
Exception
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.97
- See Also:
-
setSpeechTolerance
Sets the system-wide "Pronunciation tolerance" setting.This value determines how correctly the user must speak each phrase. This method should only be used if it is exposed so each wearer can adjust the value to meet their needs.
- Parameters:
value
- SpeechTolerance enum value to set.- Throws:
Exception
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.97
- See Also:
-
getBluetoothSetting
Gets the system-wide "Bluetooth input" setting.This allows the system to listen to Bluetooth headset audio for speech commands whenever one is connected.
- Returns:
- The value of the headset settings as a boolean
- Throws:
Exception
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.97
-
setBluetoothSetting
Sets the system-wide "Bluetooth input" setting.This allows the system to listen to Bluetooth headset audio for speech commands whenever one is connected.
- Parameters:
value
- boolean value to set.- Throws:
Exception
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.97
-
getSleepEnableSetting
Gets the system-wide "Listen while asleep" setting.This allows speech recognition to wake the device while the screen is off when it hears the wake word: ("Hello Vuzix")
- Returns:
- The value of the sleep enable settings as a boolean
- Throws:
Exception
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.97
-
setSleepEnableSetting
Sets the system-wide "Listen while asleep" setting. This allows speech recognition to wake the device while the screen is off when it hears the wake word: ("Hello Vuzix")- Parameters:
value
- booleanm value to set.- Throws:
Exception
- if the Vuzix speech engine service is not running on this device.- Since:
- SDK version 1.97
-