Voice Commands

Voice commands

Voice commands live in Config.Actions in shared/config.lua. Each entry maps one or more spoken phrases to an action.

Anatomy of an action

{
    phrases = { 'hands up', 'put your hands up', 'surrender' },
    allowRecognitionInReverse = true,
    shouldBreak = true,
    blockInVehicle = true,
    minimumConfidence = 0.45,
    actionType = 'event',
    eventType = 'client',
    eventName = 'my-script:client:doSomething',
    arguments = {}
}

Fields

  • phrases: list of trigger phrases. Lowercase. Punctuation stripped automatically. Any phrase in the list fires the action.
  • allowRecognitionInReverse: if true, the words in the phrase can appear in any order in the recognized text. If false, they must appear as a contiguous whole-word sequence.
  • shouldBreak: if true, no further actions are checked after this one fires.
  • blockInVehicle: if true, the action does nothing while the player is in a vehicle.
  • minimumConfidence: action only fires if the transcription confidence is at least this. Range 0.0 to 1.0. Recommended: 0.4 to 0.5.
  • actionType: 'event', 'executeCommand', or 'custom'.

Action types

Event

Fires a FiveM event.

{
    phrases = { 'open menu' },
    actionType = 'event',
    eventType = 'client',
    eventName = 'my-script:client:openMenu',
    arguments = { 'someArg' }
}

For eventType = 'server', the server receives (playerSource, payload) where payload has the recognized sentence and confidence.

Console command

Runs a command as if the player typed it.

{
    phrases = { 'wave' },
    actionType = 'executeCommand',
    commandString = 'me waves'
}

Custom function

Run any client-side Lua.

{
    phrases = { 'where am i' },
    actionType = 'custom',
    actionFunction = function(sentence, confidence, action)
        local coords = GetEntityCoords(PlayerPedId())
        TriggerEvent('chat:addMessage', {
            args = { 'Coords', ('%.2f %.2f %.2f'):format(coords.x, coords.y, coords.z) }
        })
    end
}

Adding actions at runtime

Use the NewAction export from another resource:

local id = exports['stratis-voice']:NewAction({
    phrases = { 'panic' },
    actionType = 'event',
    eventType = 'client',
    eventName = 'my-script:panic'
})

-- later
exports['stratis-voice']:RemoveAction(id)

Runtime actions cannot dispatch server events for security reasons.

Tips

  • Sort by specificity in your config: long phrases like "hands up high" should appear before short ones like "hands up". The matcher already sorts by length internally but giving it good input helps.
  • Use minimumConfidence higher (0.6+) for destructive actions like ejecting from vehicles or admin commands.
  • Keep phrases lowercase. The normalizer lowercases input but keeping config consistent helps readability.

View Rivo Voice