Events provide passive listening and alternative registration paths for the voice system. Use exports for active control (register, enable, query). Use events for observing what is happening — lifecycle notifications, transcript monitoring, and cross-resource coordination.
| Use case | Recommended |
|---|---|
| Register an action with a callback | RegisterAction global or registerAction export |
| Register an action from a UI resource that has no client script | TriggerEvent('onex-voiceInteraction:action:register', ...) |
| React to any command execution (logging, analytics) | AddEventHandler('onex-voiceInteraction:command:executed', ...) |
| Monitor raw speech before matching | AddEventHandler('voicesdk:onTranscript', ...) |
| Detect when no command matched | AddEventHandler('onex-voiceInteraction:noMatch', ...) |
Fires when any action is successfully registered.
Your ScriptAddEventHandler('onex-voiceInteraction:action:registered', function(name, sourceResource) print("Action registered:", name, "by", sourceResource) end)
| Argument | Type | Description |
|---|---|---|
name | string | Action name |
sourceResource | string | Resource that registered it |
Fires when an action is unregistered.
Your ScriptAddEventHandler('onex-voiceInteraction:action:unregistered', function(target) print("Action unregistered:", target) end)
| Argument | Type | Description |
|---|---|---|
target | string | Action name or @resource_name pattern that was unregistered |
Fires when a single action's enabled state changes.
Your ScriptAddEventHandler('onex-voiceInteraction:action:enabled-changed', function(actionName, enabled) print("Action", actionName, enabled and "enabled" or "disabled") end)
| Argument | Type | Description |
|---|---|---|
actionName | string | Action name |
enabled | boolean | New enabled state |
Fires when a group is enabled or disabled via setActionEnabled("#group_name", ...).
Your ScriptAddEventHandler('onex-voiceInteraction:action:group-changed', function(groupName, enabled) print("Group", groupName, enabled and "enabled" or "disabled") end)
| Argument | Type | Description |
|---|---|---|
groupName | string | Group name |
enabled | boolean | New enabled state |
Fires when setActionEnabled("*", true) clears all disabled states, restoring all actions.
Your ScriptAddEventHandler('onex-voiceInteraction:action:all-enabled', function() print("All actions restored") end)
No arguments.
Fires every time a voice command matches and executes. Useful for logging, analytics, or triggering secondary side-effects.
Your ScriptAddEventHandler('onex-voiceInteraction:command:executed', function(name, def, score, tier, transcript, confidence, extractedVars) print(string.format( "Executed: %s | Score: %.2f | Tier: %d | Transcript: %s", name, score, tier, transcript )) end)
| Argument | Type | Description |
|---|---|---|
name | string | Action name |
def | table | Full action definition |
score | number | Match score (0.0–1.0) |
tier | number | Matching tier used (1–4) |
transcript | string | Recognized speech text |
confidence | number | STT confidence (0.0–1.0) |
extractedVars | table | Variables extracted from {placeholder} phrases |
Fires when speech was recognized but no action matched.
Your ScriptAddEventHandler('onex-voiceInteraction:noMatch', function(data) print("No match for:", data.transcript, "confidence:", data.confidence) end)
| Field | Type | Description |
|---|---|---|
data.transcript | string | The unmatched speech text |
data.confidence | number | STT confidence of the transcript |
data.enabledGroups | table | List of currently enabled group names at time of no-match |
Fires when the microphone begins recording. Useful for UI feedback such as showing a recording indicator.
Your ScriptAddEventHandler('onex-voiceInteraction:recordingStarted', function() -- show recording indicator end)
No arguments.
Fires when an internal system error occurs.
Your ScriptAddEventHandler('onex-voiceInteraction:error', function(errorType, errorMessage) print("Voice system error:", errorType, errorMessage) end)
| Argument | Type | Description |
|---|---|---|
errorType | string | Error category identifier |
errorMessage | string | Human-readable error description |
Fires before command matching — every time the STT engine produces a transcript. Useful for debugging, building custom matching logic, or displaying live captions.
Your ScriptAddEventHandler('voicesdk:onTranscript', function(transcript, confidence) -- Fires before matching — no action has been selected yet print("Heard:", transcript, string.format("(%.0f%%)", confidence * 100)) end)
| Argument | Type | Description |
|---|---|---|
transcript | string | Raw recognized speech text |
confidence | number | STT confidence (0.0–1.0) |
Fires when TTS playback begins.
Your ScriptAddEventHandler('onex-voiceInteraction:tts:start', function(text) print("TTS started:", text) end)
| Argument | Type | Description |
|---|---|---|
text | string | Text being spoken |
Fires when TTS playback finishes naturally.
Your ScriptAddEventHandler('onex-voiceInteraction:tts:end', function(text) print("TTS finished:", text) end)
| Argument | Type | Description |
|---|---|---|
text | string | Text that was spoken |
Fires when TTS playback is stopped early via stopSpeech().
Your ScriptAddEventHandler('onex-voiceInteraction:tts:stop', function() print("TTS stopped") end)
No arguments.
Fires when TTS synthesis or playback fails.
Your ScriptAddEventHandler('onex-voiceInteraction:tts:error', function(errorType, text) print("TTS error:", errorType, "for text:", text) end)
| Argument | Type | Description |
|---|---|---|
errorType | string | Error category |
text | string | Text that failed to play |
Fires when a 3D positional audio sound begins playing.
Your ScriptAddEventHandler('onex-voiceInteraction:audio3d:start', function(soundId) print("3D audio started:", soundId) end)
| Argument | Type | Description |
|---|---|---|
soundId | string | Sound identifier |
Fires when a 3D positional audio sound finishes.
Your ScriptAddEventHandler('onex-voiceInteraction:audio3d:end', function(soundId) print("3D audio ended:", soundId) end)
| Argument | Type | Description |
|---|---|---|
soundId | string | Sound identifier |
Fires when a 3D positional audio sound fails.
Your ScriptAddEventHandler('onex-voiceInteraction:audio3d:error', function(soundId, error) print("3D audio error:", soundId, error) end)
| Argument | Type | Description |
|---|---|---|
soundId | string | Sound identifier |
error | string | Error description |
All three action management exports have event equivalents. Use these when calling from a resource that does not have a persistent client script context (e.g. a UI frame resource).
Your ScriptTriggerEvent('onex-voiceInteraction:action:register', { name = "buy_water", phrases = { "buy water", "give me water" }, trigger = { event = { name = "myres:buyItem", type = "server", params = { item = "water" } } }, group = "voice_shop_1" })
If registration fails, onex-voiceInteraction:action:register-failed fires with the action name and error message.
Your ScriptAddEventHandler('onex-voiceInteraction:action:register-failed', function(name, errorMessage) print("Failed to register action:", name, errorMessage) end)
Your ScriptTriggerEvent('onex-voiceInteraction:action:unregister', "buy_water")
Your ScriptTriggerEvent('onex-voiceInteraction:action:setEnabled', "#voice_shop_1", false) TriggerEvent('onex-voiceInteraction:action:setEnabled', "buy_water", true)
RegisterAction is a global function available within the same resource as the voice system scripts. It is functionally identical to the registerAction export but is required when the action's callback must reference Lua closures in the current scope.
Lua callbacks do not survive export boundaries. If your trigger uses callback = function(data) ... end, and that function references upvalues in the same file, use RegisterAction — not the export.
Your Script-- This works: callback references a local variable local shopId = "liquor_1" RegisterAction({ name = "buy_item", phrases = { "buy {item}" }, trigger = { callback = function(data) -- shopId is accessible here because RegisterAction stays in-scope TriggerServerEvent('shop:buy', shopId, data.extractedVariables.item) end }, group = "voice_shop_liquor_1", layer = "shop" })
Your Script-- This would break the closure: export crosses resource boundary -- exports['onex-voiceInteraction']:registerAction({ -- trigger = { callback = function(data) -- print(shopId) -- shopId is NOT accessible across export boundary -- end } -- })
RegisterAction is only available in the same resource. Use the export or event form from other resources.
Last updated 14 days ago