Command

The headless primitive: attach a spoken command to anything and run your own code when it's heard.

Every trigger control — label button, toggle, toggle button — is this primitive plus rendering. Use it directly to make your existing components speech-aware: give it a command and a callback; it handles matching, claims, and the interim-result cooldown.

Wiring a command to your own UI

Loading the React Native kit…

Hold anywhere and say:“undock”

React Native
import { useListensCommand } from "@listenssoft/speechui-react-native";import { View, Text, Pressable } from "react-native";import { useState } from "react";
function Demo() {  const [status, setStatus] = useState("docked");  useListensCommand({    command: "undock",    onTriggered: () => setStatus("undocked"),  });  return (    <View style={{ gap: 8, alignItems: "flex-start" }}>      <Pressable onPress={() => setStatus("undocked")}>        <Text>Undock</Text>      </Pressable>      <Text>Status: {status}</Text>    </View>  );}

Page-level commands (React only)

useListensGlobalCommand registers a command tied to no element — navigation, mode switches, anything page-wide.

Loading the React Native kit…

Hold anywhere and say:“go to settings”“go home”

React Native
// React Native ships useListensCommand only; a global command is the// same hook without a visible control attached:import { useListensCommand } from "@listenssoft/speechui-react-native";
function Demo() {  useListensCommand({    command: "go home",    onTriggered: () => {      /* navigate("/") */    },  });  return null;}

What you can say

SayEffect
“undock”Runs onTriggered once (contains match, claims respected, ~1s cooldown per command).
“…prepare to undock now…”Also fires — the command may appear anywhere in the phrase.

API reference

React Native props for @listenssoft/speechui-react-native.

useListensCommand options

OptionTypeDefaultDescription
command*string—The phrase to listen for.
onTriggered*() => void—Runs when the command is detected.

Returns { isListening }.

Was this page helpful?