Skip to main content
Version: 12 Dec 2024

ml_voice.h

Classes

Name
structMLInputVoiceAppIntentSlot
A structure containing voice app-intent slot in voice event.
structMLVoiceIntentEvent
A structure containing voice intent event.
structMLVoiceIntentCallbacks
A structure containing callbacks for voice intent events.
structMLVoiceIntentSettings
A structure containing settings for voice app intent.

Types

Name
typedef struct MLInputVoiceAppIntentSlotMLInputVoiceAppIntentSlot
A structure containing voice app-intent slot in voice event.
typedef struct MLVoiceIntentEventMLVoiceIntentEvent
A structure containing voice intent event.
typedef struct MLVoiceIntentCallbacksMLVoiceIntentCallbacks
A structure containing callbacks for voice intent events.
typedef struct MLVoiceIntentSettingsMLVoiceIntentSettings
A structure containing settings for voice app intent.

Enums

Name
enumAnonymous Enum 30
{
MLResultAPIPrefix_Voice = ( 0xbe7a << 16)
}
enumMLVoiceResult
{
MLVoiceResult_IntentDisabled = MLResultAPIPrefix_Voice,
MLVoiceResult_Ensure32Bits = 0x7FFFFFFF
}
Return values for Voice API calls.
enumMLVoiceState
{
MLVoiceState_IntentHotwordDetected = 0,
MLVoiceState_IntentSessionEnded = 1,
MLVoiceState_IntentSessionEndedAborted = 2,
MLVoiceState_IntentSessionEndedNoIntent = 3,
MLVoiceState_IntentSessionEndedTimeout = 4,
MLVoiceState_IntentSessionEndedError = 5,
MLVoiceState_IntentReady = 6,
MLVoiceState_IntentNotAvailable = 7,
MLVoiceState_IntentInvalidAppIntent = 8,
MLVoiceState_Ensure32Bits = 0x7FFFFFFF
}
Voice state in voice event.
enumMLVoiceIntentNoIntentReason
{
MLVoiceIntentNoIntentReason_NoReason = 0,
MLVoiceIntentNoIntentReason_Silence = 1,
MLVoiceIntentNoIntentReason_NoMatch = 2,
MLVoiceIntentNoIntentReason_Ensure32Bits = 0x7FFFFFFF
}
No intent reason code in voice event.

Functions

Name
voidMLVoiceIntentCallbacksInit(MLVoiceIntentCallbacks * inout_callbacks)
Initializes default values for MLVoiceIntentCallbacks.
voidMLVoiceIntentSettingsInit(MLVoiceIntentSettings * inout_settings)
Initializes default values for MLVoiceIntentSettings.
MLResultMLVoiceIntentCreate(MLHandle * out_handle)
Creates a voice intent client.
MLResultMLVoiceIntentDestroy(MLHandle handle)
Destroys a voice intent client.
MLResultMLVoiceIntentConfigureSettings(MLHandle handle, const MLVoiceIntentSettings * voice_settings)
Sets the settings for voice intent events.
MLResultMLVoiceIntentSetCallbacks(MLHandle handle, const MLVoiceIntentCallbacks voice_callbacks, void user_data)
Sets the callbacks for voice intent events.
MLResultMLVoiceIntentStartProcessing(MLHandle handle)
Starts voice intent processing.
MLResultMLVoiceIntentStopProcessing(MLHandle handle)
Stops voice intent processing.
MLResultMLVoiceIntentIsEnabled(MLHandle handle, bool * out_is_enabled)
Checks voice intent feature is enabled in the system.
const char *MLVoiceGetResultString(MLResult result)
Returns an ASCII string for MLVoiceResult and MLResult codes.

Enums Documentation

Anonymous Enum 30

EnumeratorValueDescription
MLResultAPIPrefix_Voice( 0xbe7a << 16)Defines the prefix for MLVoiceResult codes.

MLVoiceResult

EnumeratorValueDescription
MLVoiceResult_IntentDisabledMLResultAPIPrefix_VoiceOperation failed because a required voice intent feature is disabled in system settings.
MLVoiceResult_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Return values for Voice API calls.

API Level:

  • 20

MLVoiceState

EnumeratorValueDescription
MLVoiceState_IntentHotwordDetected0Intent hotword detected, Automatic Speech Recognition (ASR) session is going to start.
MLVoiceState_IntentSessionEnded1Voice UI is stopped, ASR session is going to stop.
MLVoiceState_IntentSessionEndedAborted2ASR session is stopped due to abort.
MLVoiceState_IntentSessionEndedNoIntent3ASR session is stopped without detecting an intent.
MLVoiceState_IntentSessionEndedTimeout4ASR session is stopped due to timeout.
MLVoiceState_IntentSessionEndedError5ASR session is stopped due to error.
MLVoiceState_IntentReady6Intent mode is started and ready.
MLVoiceState_IntentNotAvailable7Intent mode is stopped and not available.
MLVoiceState_IntentInvalidAppIntent8Invalid app intent, double check content of JSON submitted with MLVoiceIntentConfigureSettings(). Please refer to Voice Intent Development Toolkit from Magic Leap Hub to generate app intent content.
MLVoiceState_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Voice state in voice event.

API Level:

  • 31

MLVoiceIntentNoIntentReason

EnumeratorValueDescription
MLVoiceIntentNoIntentReason_NoReason0In case of success.
MLVoiceIntentNoIntentReason_Silence1When the MLVoiceState in MLVoiceIntentEvent is either MLVoiceState_IntentSessionEndedTimeout or MLVoiceState_IntentSessionEndedError.
MLVoiceIntentNoIntentReason_NoMatch2When the MLVoiceState in MLVoiceIntentEvent is MLVoiceState_IntentSessionEndedNoIntent.
MLVoiceIntentNoIntentReason_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

No intent reason code in voice event.

API Level:

  • 20

Types Documentation

MLInputVoiceAppIntentSlot

typedef struct MLInputVoiceAppIntentSlot MLInputVoiceAppIntentSlot;

A structure containing voice app-intent slot in voice event.

More Info

API Level:

  • 24

MLVoiceIntentEvent

typedef struct MLVoiceIntentEvent MLVoiceIntentEvent;

A structure containing voice intent event.

More Info

API Level:

  • 24

MLVoiceIntentCallbacks

typedef struct MLVoiceIntentCallbacks MLVoiceIntentCallbacks;

A structure containing callbacks for voice intent events.

The final parameter to all the callbacks is a void *, which will point to whatever payload data the user provides in MLVoiceIntentSetCallbacks. Individual callbacks which are not required by the client can be NULL.

This structure must be initialized by calling MLVoiceIntentCallbacksInit() before use.

More Info

API Level:

  • 24

MLVoiceIntentSettings

typedef struct MLVoiceIntentSettings MLVoiceIntentSettings;

A structure containing settings for voice app intent.

This structure must be initialized by calling MLVoiceIntentSettingsInit() before use.

More Info

API Level:

  • 20

Functions Documentation

MLVoiceIntentCallbacksInit

static inline void MLVoiceIntentCallbacksInit(
MLVoiceIntentCallbacks * inout_callbacks
)

Initializes default values for MLVoiceIntentCallbacks.

Parameters

MLVoiceIntentCallbacks *inout_callbacksThe object to initialize with default settings.

Required Permissions:

  • None

API Level:

  • 24

MLVoiceIntentSettingsInit

static inline void MLVoiceIntentSettingsInit(
MLVoiceIntentSettings * inout_settings
)

Initializes default values for MLVoiceIntentSettings.

Parameters

MLVoiceIntentSettings *inout_settingsThe object to initialize with default settings.

Required Permissions:

  • None

API Level:

  • 20

MLVoiceIntentCreate

MLResult MLVoiceIntentCreate(
MLHandle * out_handle
)

Creates a voice intent client.

Parameters

MLHandle *out_handleA handle to the created voice intent client. Only valid if the return value is MLResult_Ok.

Returns

MLResultMLResult_InvalidParamFailed to create the voice intent client due to an invalid input parameter.
MLResultMLResult_OkSuccessfully created the voice intent client.
MLResultMLResult_PermissionDeniedFailed to create client due to missing permission.

Required Permissions:

  • com.magicleap.permission.VOICE_INPUT (protection level: dangerous)

API Level:

  • 20

MLVoiceIntentDestroy

MLResult MLVoiceIntentDestroy(
MLHandle handle
)

Destroys a voice intent client.

Parameters

MLHandlehandleMLHandle to the voice intent client to destroy.

Returns

MLResultMLResult_InvalidParamFailed to destroy the voice intent client due to an invalid input parameter.
MLResultMLResult_OkSuccessfully destroyed the voice intent client.

Required Permissions:

  • None

MLVoiceIntentConfigureSettings

MLResult MLVoiceIntentConfigureSettings(
MLHandle handle,
const MLVoiceIntentSettings * voice_settings
)

Sets the settings for voice intent events.

Parameters

MLHandlehandleHandle to the voice intent client.
const MLVoiceIntentSettings *voice_settingsPointer to MLVoiceIntentSettings structure.

Returns

MLResultMLResult_InvalidParamFailed to set settings for voice intent events due to an invalid param.
MLResultMLResult_OkSuccessfully set settings for voice intent events.
MLResultMLVoiceResult_IntentDisabledFailed to set the settings because required voice intent feature is disabled.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

App needs to call MLVoiceIntentConfigureSettings at least once before it calls MLVoiceIntentStartProcessing. App can call MLVoiceIntentConfigureSettings anytime it needs to update the voice intents. But such call will trigger updating intent grammar inside speech engine, which may result in a short delay (could be a few seconds depending on the device's workload). So it is not recommended to call the function frequently.

API Level:

  • 20

MLVoiceIntentSetCallbacks

MLResult MLVoiceIntentSetCallbacks(
MLHandle handle,
const MLVoiceIntentCallbacks * voice_callbacks,
void * user_data
)

Sets the callbacks for voice intent events.

Parameters

MLHandlehandleHandle to the voice intent client.
const MLVoiceIntentCallbacks *voice_callbacksPointer to MLVoiceIntentCallbacks structure. Set this to NULL to unregister callbacks.
void *user_dataPointer to user payload data (can be NULL).

Returns

MLResultMLResult_InvalidParamFailed to set callbacks for voice intent events due to an invalid param.
MLResultMLResult_OkSuccessfully set callbacks for voice intent events.
MLResultMLVoiceResult_IntentDisabledFailed to set the callbacks because required voice intent feature is disabled in system settings.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

API Level:

  • 20

MLVoiceIntentStartProcessing

MLResult MLVoiceIntentStartProcessing(
MLHandle handle
)

Starts voice intent processing.

Parameters

MLHandlehandleHandle to the voice intent client.

Returns

MLResultMLResult_InvalidParamFailed to start processing due to an invalid parameter.
MLResultMLResult_OkSuccessfully start intent processing.
MLResultMLVoiceResult_IntentDisabledFailed to start intent processing because required voice intent feature is disabled in system settings.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

This API call affects the system voice service.

NOTE: If your application is processing voice intents make sure to call MLVoiceIntentStopProcessing when application loses focus and MLVoiceIntentStartProcessing when application gains focus to allow for uninterrupted processing of the voice intents.

API Level:

  • 20

MLVoiceIntentStopProcessing

MLResult MLVoiceIntentStopProcessing(
MLHandle handle
)

Stops voice intent processing.

Parameters

MLHandlehandleHandle to the voice intent client.

Returns

MLResultMLResult_InvalidParamFailed to stop processing due to an invalid parameter.
MLResultMLResult_OkSuccessfully stop intent processing.
MLResultMLVoiceResult_IntentDisabledFailed to stop intent processing because required voice intent feature is disabled in system settings.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

This API call affects the system voice service.

NOTE: If your application is processing voice intents make sure to call MLVoiceIntentStopProcessing when application loses focus and MLVoiceIntentStartProcessing when application gains focus to allow for uninterrupted processing of the voice intents.

API Level:

  • 20

MLVoiceIntentIsEnabled

MLResult MLVoiceIntentIsEnabled(
MLHandle handle,
bool * out_is_enabled
)

Checks voice intent feature is enabled in the system.

Parameters

MLHandlehandleHandle to the voice intent client.
bool *out_is_enabledReturns status whether voice intent feature is enabled in system settings.

Returns

MLResultMLResult_InvalidParamFailed to check due to an invalid parameter.
MLResultMLResult_OkThe API call completed successfuly.

Required Permissions:

  • None

API Level:

  • 20

MLVoiceGetResultString

const char * MLVoiceGetResultString(
MLResult result
)

Returns an ASCII string for MLVoiceResult and MLResult codes.

Parameters

MLResultresultThe input MLResult enum from MLVoice functions.

Required Permissions:

  • None

Return: ASCII string containing readable version of result code.

API Level:

  • 31

Source code

// %BANNER_BEGIN%
// ---------------------------------------------------------------------
// %COPYRIGHT_BEGIN%
// Copyright (c) 2022 Magic Leap, Inc. All Rights Reserved.
// Use of this file is governed by the Software License Agreement,
// located here: https://www.magicleap.com/software-license-agreement-ml2
// Terms and conditions applicable to third-party materials accompanying
// this distribution may also be found in the top-level NOTICE file
// appearing herein.
// %COPYRIGHT_END%
// ---------------------------------------------------------------------
// %BANNER_END%
#pragma once
#include <ml_api.h>

ML_EXTERN_C_BEGIN

enum {
MLResultAPIPrefix_Voice = MLRESULT_PREFIX(0xbe7a)
};

typedef enum MLVoiceResult {
MLVoiceResult_IntentDisabled = MLResultAPIPrefix_Voice,
MLVoiceResult_Ensure32Bits = 0x7FFFFFFF
} MLVoiceResult;

typedef enum MLVoiceState {
MLVoiceState_IntentHotwordDetected = 0,
MLVoiceState_IntentSessionEnded = 1,
MLVoiceState_IntentSessionEndedAborted = 2,
MLVoiceState_IntentSessionEndedNoIntent = 3,
MLVoiceState_IntentSessionEndedTimeout = 4,
MLVoiceState_IntentSessionEndedError = 5,
MLVoiceState_IntentReady = 6,
MLVoiceState_IntentNotAvailable = 7,
MLVoiceState_IntentInvalidAppIntent = 8,

MLVoiceState_Ensure32Bits = 0x7FFFFFFF
} MLVoiceState;


typedef enum MLVoiceIntentNoIntentReason {
MLVoiceIntentNoIntentReason_NoReason = 0,
MLVoiceIntentNoIntentReason_Silence = 1,
MLVoiceIntentNoIntentReason_NoMatch = 2,

MLVoiceIntentNoIntentReason_Ensure32Bits = 0x7FFFFFFF
} MLVoiceIntentNoIntentReason;

typedef struct MLInputVoiceAppIntentSlot {
const char* slot_name;
const char* slot_value;
} MLInputVoiceAppIntentSlot;

typedef struct MLVoiceIntentEvent {
bool is_success;
MLVoiceState state;
MLVoiceIntentNoIntentReason no_intent_reason;
const char* text;
uint32_t intent_id;
MLInputVoiceAppIntentSlot* app_intent_slots;
uint32_t app_intent_slot_count;
} MLVoiceIntentEvent;

typedef struct MLVoiceIntentCallbacks {
uint32_t version;
void (*on_voice_event)(const MLVoiceIntentEvent* event, void* data);
} MLVoiceIntentCallbacks;

ML_STATIC_INLINE void MLVoiceIntentCallbacksInit(MLVoiceIntentCallbacks* inout_callbacks) {
if (inout_callbacks) {
inout_callbacks->version = 2u;
inout_callbacks->on_voice_event = NULL;
}
}

typedef struct MLVoiceIntentSettings {
uint32_t version;
const char* app_intent;
} MLVoiceIntentSettings;

ML_STATIC_INLINE void MLVoiceIntentSettingsInit(MLVoiceIntentSettings* inout_settings) {
if (inout_settings) {
inout_settings->version = 1u;
inout_settings->app_intent = NULL;
}
}

ML_API MLResult ML_CALL MLVoiceIntentCreate(MLHandle *out_handle);

ML_API MLResult ML_CALL MLVoiceIntentDestroy(MLHandle handle);

ML_API MLResult ML_CALL MLVoiceIntentConfigureSettings(MLHandle handle, const MLVoiceIntentSettings* voice_settings);

ML_API MLResult ML_CALL MLVoiceIntentSetCallbacks(MLHandle handle, const MLVoiceIntentCallbacks* voice_callbacks, void* user_data);

ML_API MLResult ML_CALL MLVoiceIntentStartProcessing(MLHandle handle);

ML_API MLResult ML_CALL MLVoiceIntentStopProcessing(MLHandle handle);

ML_API MLResult ML_CALL MLVoiceIntentIsEnabled(MLHandle handle, bool* out_is_enabled);

ML_API const char *ML_CALL MLVoiceGetResultString(MLResult result);
ML_EXTERN_C_END