Class VoiceAssist
To enable VoiceAssist, call enable(), optionally passing the keyName you want to use for activation and recording - the default is Control. Once initialized, VoiceAssist can be activated or deactivated with three quick taps of the voiceKey.
When recognition is active, a user may double-tap the voiceKey to begin dictating a value for a focused input control. Text appears in the input control as the user speaks and the transcription is completed by a subsequent double-tap of the voiceKey, or by remaining silent for a number of seconds.
In addition to value-dictation, a user may dictate a command to be issued to the focused component, which may deal with the text itself or forward to an AI for action. If the focused component doesn't support voice-commands but one of its parents does, that parent will be the focus of your dictated command. To begin dictating a command, press and hold the voiceKey - while the key remains pressed, the recordingProgress() method is fired with interim text-results as the user speaks.
If the user speaks one of the cancelPhrases, the interim text is discarded and recording is canceled.
When the user releases the speech-key, recording is stopped and the final text of the recording is passed to the target component for action.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCancels any ongoing recording session (value or command) and discards the transcription.static voiddisable()Disables VoiceAssist completely, removing keyboard listeners, deactivating if currentlyactive, and canceling any in-progress recording.static voidenable()Enables the VoiceAssist module by initializing the speech-recognition engine and, on non-mobile browsers, installing keyboard listeners for thespeech-key.static voidEnables the VoiceAssist module by initializing the speech-recognition engine and, on non-mobile browsers, installing keyboard listeners for thespeech-key.static intVoiceAssist will stop recording automatically if the user stops speaking for this length of time.static booleanWhether VoiceAssist allows command-dictation, where the user's speech is transcribed and forwarded to a target component (or AI) for execution.static booleanWhether VoiceAssist allows value-dictation, where the user's speech is transcribed into a focused text field.static StringThe BCP 47 language-tag for the language that VoiceAssist expects to interpret.static intVoiceAssist will stop recording automatically if the user doesn't speak at all for this length of time.static ImgReturns anImgwidget pre-configured to start and stop VoiceAssist recording.static FormItemIconReturns aFormItemIconproperties object configured for VoiceAssist value-dictation.static FormItemIcongetVoiceAssistIcon(FormItemIcon properties) Returns aFormItemIconproperties object configured for VoiceAssist value-dictation.static StringThe key that activates and performs VoiceAssist features like value and command dictation.static voidrecordingProgress(String text) Event fired with interim text-results as the user speaks.static voidsetActive(boolean active) Sets whether VoiceAssist is active.static voidsetAutoStopDelay(int autoStopDelay) VoiceAssist will stop recording automatically if the user stops speaking for this length of time.static voidsetCanDictateCommands(boolean canDictateCommands) Whether VoiceAssist allows command-dictation, where the user's speech is transcribed and forwarded to a target component (or AI) for execution.static voidsetCanDictateValues(boolean canDictateValues) Whether VoiceAssist allows value-dictation, where the user's speech is transcribed into a focused text field.static voidsetLanguage(String language) The BCP 47 language-tag for the language that VoiceAssist expects to interpret.static voidsetNoSpeechDelay(int noSpeechDelay) VoiceAssist will stop recording automatically if the user doesn't speak at all for this length of time.static voidsetVoiceKey(String voiceKey) The key that activates and performs VoiceAssist features like value and command dictation.static voidBegins command-dictation.static voidBegins value-dictation for the currently focusedFormItem.static voidStops an ongoing command-dictation session normally, forwarding the transcribed text to the target component for execution.static voidStops an ongoing value-dictation session normally, applying the transcribed text to the targetFormItem.static booleanStops any ongoing recording session (value or command) normally, applying the transcribed text.
-
Constructor Details
-
VoiceAssist
public VoiceAssist()
-
-
Method Details
-
setAutoStopDelay
public static void setAutoStopDelay(int autoStopDelay) VoiceAssist will stop recording automatically if the user stops speaking for this length of time. The default is 2 seconds.- Parameters:
autoStopDelay- new autoStopDelay. Default value is 2000.
-
getAutoStopDelay
public static int getAutoStopDelay()VoiceAssist will stop recording automatically if the user stops speaking for this length of time. The default is 2 seconds.- Returns:
- current value of autoStopDelay
-
setCanDictateCommands
public static void setCanDictateCommands(boolean canDictateCommands) Whether VoiceAssist allows command-dictation, where the user's speech is transcribed and forwarded to a target component (or AI) for execution. When false, the long-press gesture is ignored andstartDictatingCommand()is a no-op.- Parameters:
canDictateCommands- new canDictateCommands. Default value is true.
-
getCanDictateCommands
public static boolean getCanDictateCommands()Whether VoiceAssist allows command-dictation, where the user's speech is transcribed and forwarded to a target component (or AI) for execution. When false, the long-press gesture is ignored andstartDictatingCommand()is a no-op.- Returns:
- current value of canDictateCommands
-
setCanDictateValues
public static void setCanDictateValues(boolean canDictateValues) Whether VoiceAssist allows value-dictation, where the user's speech is transcribed into a focused text field. When false, the voice-assist inline icon is not shown on form items, the double-tap gesture is ignored, andstartDictatingValue()is a no-op.- Parameters:
canDictateValues- new canDictateValues. Default value is true.
-
getCanDictateValues
public static boolean getCanDictateValues()Whether VoiceAssist allows value-dictation, where the user's speech is transcribed into a focused text field. When false, the voice-assist inline icon is not shown on form items, the double-tap gesture is ignored, andstartDictatingValue()is a no-op.- Returns:
- current value of canDictateValues
-
setLanguage
The BCP 47 language-tag for the language that VoiceAssist expects to interpret. These are in the format "language-REGION", like "en-US" or "fr-FR". If unset, VoiceAssist uses the language provided by your browser or OS.- Parameters:
language- new language. Default value is null.
-
getLanguage
The BCP 47 language-tag for the language that VoiceAssist expects to interpret. These are in the format "language-REGION", like "en-US" or "fr-FR". If unset, VoiceAssist uses the language provided by your browser or OS.- Returns:
- current value of language
-
setNoSpeechDelay
public static void setNoSpeechDelay(int noSpeechDelay) VoiceAssist will stop recording automatically if the user doesn't speak at all for this length of time. The default is 3 seconds.- Parameters:
noSpeechDelay- new noSpeechDelay. Default value is 3000.
-
getNoSpeechDelay
public static int getNoSpeechDelay()VoiceAssist will stop recording automatically if the user doesn't speak at all for this length of time. The default is 3 seconds.- Returns:
- current value of noSpeechDelay
-
setVoiceKey
The key that activates and performs VoiceAssist features like value and command dictation.- Parameters:
voiceKey- new voiceKey. Default value is "Control".
-
getVoiceKey
The key that activates and performs VoiceAssist features like value and command dictation.- Returns:
- current value of voiceKey
-
cancelRecording
public static boolean cancelRecording()Cancels any ongoing recording session (value or command) and discards the transcription. If value-dictation was in progress, the target item's value is restored to its pre-recording state.- Returns:
- true if a recording was canceled, false if no recording was in progress
-
disable
public static void disable()Disables VoiceAssist completely, removing keyboard listeners, deactivating if currentlyactive, and canceling any in-progress recording. After calling this method,enable()must be called again before VoiceAssist can be reactivated.- See Also:
-
enable
public static void enable()Enables the VoiceAssist module by initializing the speech-recognition engine and, on non-mobile browsers, installing keyboard listeners for thespeech-key. Once enabled, a user may triple-tap the speech-key toactivateVoiceAssist. Onhandsetandtabletdevices, keyboard listeners are skipped (virtual keyboards do not fire physical key events); callsetActive()directly from a button or other UI element instead.No intrusive mic/speech probe is performed at enable time. The probe runs on the first call to
setActive(). -
enable
Enables the VoiceAssist module by initializing the speech-recognition engine and, on non-mobile browsers, installing keyboard listeners for thespeech-key. Once enabled, a user may triple-tap the speech-key toactivateVoiceAssist. Onhandsetandtabletdevices, keyboard listeners are skipped (virtual keyboards do not fire physical key events); callsetActive()directly from a button or other UI element instead.No intrusive mic/speech probe is performed at enable time. The probe runs on the first call to
setActive().- Parameters:
key- optional different key to use for VoiceAssist - use with care- See Also:
-
getVoiceAssistButton
Returns anImgwidget pre-configured to start and stop VoiceAssist recording. The button can be placed anywhere in the UI (toolbars, tab-bar controls, etc.) to give users a clickable entry point for voice interaction.When clicked, the button determines the recording mode based on the currently focused component. If a
FormItemthat supports value-dictation is focused, value-dictation begins; otherwise, command-dictation begins. Recording stops on a second click, or automatically after a period of silence (seeautoStopDelay).If VoiceAssist has not yet been
activewhen clicked, the button callssetActive()automatically.The button is created with
canFocus: falseso that clicking it does not steal focus from the component whose value or commands are being dictated.- Returns:
- a live widget wired for VoiceAssist recording
-
getVoiceAssistIcon
Returns aFormItemIconproperties object configured for VoiceAssist value-dictation. The icon appears inline on the right side of a text field when focused, and clicking it toggles voice recording on and off.This is the same icon configuration used internally when
FormItem.showVoiceAssistIconis enabled. Use this method to retrieve the config for manual inclusion in a custom item'sFormItem.iconsarray.The returned object is a copy of
voiceAssistIconDefaults, so customizations made to the defaults are reflected in all subsequently created icons.- Returns:
- icon properties for VoiceAssist
-
getVoiceAssistIcon
Returns aFormItemIconproperties object configured for VoiceAssist value-dictation. The icon appears inline on the right side of a text field when focused, and clicking it toggles voice recording on and off.This is the same icon configuration used internally when
FormItem.showVoiceAssistIconis enabled. Use this method to retrieve the config for manual inclusion in a custom item'sFormItem.iconsarray.The returned object is a copy of
voiceAssistIconDefaults, so customizations made to the defaults are reflected in all subsequently created icons.- Parameters:
properties- additional properties to apply to the icon, overriding defaults- Returns:
- icon properties for VoiceAssist
-
recordingProgress
Event fired with interim text-results as the user speaks.- Parameters:
text- the latest text-results for an on-going recording
-
setActive
public static void setActive(boolean active) Sets whether VoiceAssist is active. When active, the dictation methods (startDictatingValue(),startDictatingCommand()) become operational, subject tocanDictateValuesandcanDictateCommands. Voice-assist icons appear on applicableFormItemsifcanDictateValuesis true. When set to false, any in-progress recording is stopped and icons are hidden.On the first call with
true,Browser.checkSpeechRecognition()runs a brief probe to verify mic access and speech-service connectivity. If the probe fails, VoiceAssist shows an explanatory message and does not become active. Subsequent calls skip the probe and use the cached result.If
enable()has not yet been called, this method calls it automatically.On non-mobile devices, this method is called internally when the user triple-taps the
speech-key(toggling the active state). Onhandsetandtabletdevices, call it directly from a button or other UI element.- Parameters:
active- true to activate, false to deactivate- See Also:
-
startDictatingCommand
public static void startDictatingCommand()Begins command-dictation. VoiceAssist locates a target component by walking up the parent chain from the currently focused widget, looking for one that supports voice commands (seesupportsVoiceCommands()). The user's speech is transcribed and forwarded to the target for execution.Recording stops automatically after a period of silence (see
autoStopDelay), or can be stopped explicitly viastopDictatingCommand(). The user can also say acancel phraseto discard the transcription.Has no effect if VoiceAssist is not
active, ifcanDictateCommandsis false, or if a recording is already in progress.- See Also:
-
stopDictatingCommand()com.smartgwt.client.util.VoiceAssist#canDictateCommandscancelRecording()
-
startDictatingValue
public static void startDictatingValue()Begins value-dictation for the currently focusedFormItem. VoiceAssist locates the focused item viaEventHandler; if the focused item supports value-dictation (currentlyTextItemandTextAreaItem), the user's speech is transcribed and applied as the item's value.Recording stops automatically after a period of silence (see
autoStopDelay), or can be stopped explicitly viastopDictatingValue(). The user can also say acancel phraseto discard the transcription.Has no effect if VoiceAssist is not
active, ifcanDictateValuesis false, if no focused item supports value-dictation, or if a recording is already in progress.- See Also:
-
stopDictatingValue()com.smartgwt.client.util.VoiceAssist#canDictateValuescancelRecording()
-
stopDictatingCommand
public static void stopDictatingCommand()Stops an ongoing command-dictation session normally, forwarding the transcribed text to the target component for execution. Has no effect if command-dictation is not currently in progress.- See Also:
-
stopDictatingValue
public static void stopDictatingValue()Stops an ongoing value-dictation session normally, applying the transcribed text to the targetFormItem. Has no effect if value-dictation is not currently in progress.- See Also:
-
stopRecording
public static boolean stopRecording()Stops any ongoing recording session (value or command) normally, applying the transcribed text. For value-dictation, the text is set as the item's value; for command-dictation, the text is forwarded to the target component for execution.- Returns:
- true if a recording was stopped, false if no recording was in progress
-