Skip to main content
Version: 20 Mar 2024

MLVoice

NameSpace: MagicLeap

APIs for the voice service system. More...

Inherits from:
MLAutoAPISingleton< MLVoice >,
MLLazySingleton< T >

Detailed Description

public class MLVoice : MLAutoAPISingleton< MLVoice > 

Details*

APIs for the voice service system.

To use the voice feature (with a specific application's intent list), the application should send a Scriptable Object called MLVoiceIntentsConfiguration, Located under Assets/Magic Leap/Voice Intents Configuration, with the application's voice intents data to MLVoice.SetupVoiceIntents().

Name, id, and value should be unique. Value is the phrase needed to be spoken out loud after "Hey Magic Leap" " | " may be used in the configuration file's value field to indicate multiple values tied to the same name and id.


Public Fields

OnVoiceEvent

Event invoked for when a data channel opens.


public static OnVoiceEventDelegate OnVoiceEvent { get; set; }

TypeDescription
OnVoiceEventDelegateThis callback will be invoked whenever a voice intent event is detected.

Public Methods

delegate void OnVoiceEventDelegate

This callback will be invoked whenever a voice intent event is detected.

public delegate void OnVoiceEventDelegate(
in bool wasSuccessful,
in IntentEvent voiceEvent
)

Parameters

TypeNameDescription
in boolwasSuccessfulVoice event handling result. In case of false, voiceEvent member variables should be ignored. (voiceEvent.EventName will be NULL)
in IntentEventvoiceEventVoice intent event.

Details*

///


MLResult SetupVoiceIntents

Configures Settings sent, Sets the callbacks for voice intent events, and starts processing.

public static MLResult SetupVoiceIntents(
MLVoiceIntentsConfiguration voiceConfiguration
)

Parameters

TypeNameDescription
MLVoiceIntentsConfigurationvoiceConfigurationMLVoiceIntentsConfiguration scriptable object that contains the App Intents data. Memory of this variable is managed by user.

Returns: MLResult.Result will be MLResult.Code.InvalidParam if failed due to an invalid param. MLResult.Result will be MLResult.Code.Ok if Successfully set settings, callbacks, and starts processing. MLResult.Result will be MLResult.Code.MLVoiceResult_IntentDisabled if failed to set the callbacks or settings because required voice intent feature is disabled in system settings. MLResult.Result will be MLResult.Code.UnspecifiedFailure if the operation failed with an unspecified error.


MLResult SetupVoiceIntents

Configures Settings sent, Sets the callbacks for voice intent events, and starts processing.

public static MLResult SetupVoiceIntents(
string JSONString
)

Parameters

TypeNameDescription
stringJSONStringThe JSON file with the voice intents data in the proper format.

Details*

When providing a string instead of the MLVoiceIntentsConfiguration Scriptable Object no validation is done to confirm proper format.

Returns: MLResult.Result will be MLResult.Code.InvalidParam if failed due to an invalid param. MLResult.Result will be MLResult.Code.Ok if Successfully set settings, callbacks, and starts processing. MLResult.Result will be MLResult.Code.MLVoiceResult_IntentDisabled if failed to set the callbacks or settings because required voice intent feature is disabled in system settings. MLResult.Result will be MLResult.Code.UnspecifiedFailure if the operation failed with an unspecified error.


MLResult Stop

Stop unsets callbacks and stops processing. This is not necessary for shutdown. This is only needed if a user wants to stop processing at runtime after call MLVoice.SetupVoiceIntents. MLVoice can be restarted by calling MLVoice.SetupVoiceIntents.

public static MLResult Stop()

Returns: MLResult.Result will be MLResult.Code.InvalidParam if failed due to an invalid param. MLResult.Result will be MLResult.Code.Ok if Successfully unset callbacks and stops processing. MLResult.Result will be MLResult.Code.MLVoiceResult_IntentDisabled if failed because required voice intent feature is disabled in system settings. MLResult.Result will be MLResult.Code.UnspecifiedFailure if the operation failed with an unspecified error.


Protected Methods

OnApplicationPause

Callback sent to all MagicLeap APIs on application pause.

protected virtual override void OnApplicationPause(
bool pauseStatus
)

Parameters

TypeNameDescription
boolpauseStatusTrue if the application is paused, else False.

Reimplements: OnApplicationPause


StartAPI

Do API-specific creation/initialization of ML resources for this API, such as creating trackers, etc. Called automatically the first time Instance is accessed. Error checking on the return value is performed in the base class.

protected virtual override MLResult.Code StartAPI()

Reimplements: StartAPI


StopAPI

API-specific cleanup. Will be called whenever MLDevice is destroyed (at the latest, when the application is shutting down). Error checking on the return value is performed in the base class.

protected virtual override MLResult.Code StopAPI()

Reimplements: StopAPI


Public Attributes

VoiceEnabled

Checks voice intent feature is enabled in the system.


public static bool VoiceEnabled => Instance.isEnabled();


Public Enums

NoIntentReason

No intent reason code in voice event.

EnumeratorValueDescription
NoReasonIn case of success
SilenceWhen the State in IntentEvent is either MLVoice.State.SessionEndedTimeout or MLVoice.State.SessionEndedError.
NoMatchWhen the State in IntentEvent is MLVoice.State.SessionEndedNoIntent.

State

Voice state in voice event.

EnumeratorValueDescription
HotwordDetectedIntent hotword detected, Automatic Speech Recognition (ASR) session is going to start.
SessionEndedVoice UI is stopped, ASR session is going to stop.
ISessionEndedAbortedASR session is stopped due to abort.
SessionEndedNoIntentASR session is stopped without detecting an intent.
SessionEndedTimeoutASR session is stopped due to timeout.
SessionEndedErrorASR session is stopped due to error.
ReadyIntent mode is started and ready.
NotAvailableIntent mode is stopped and not available.