On the phone
Voice commands and dictation
Let people control your app by voice and dictate text into it.
Your phone companion can let people talk to your app: short commands for what’s on screen, and dictation for free-form text. Both run while your app captures the glasses microphone, so call startCapture() first (see Microphone audio). They don’t need a MIRA listening session.
Voice commands
Register the commands your visible screen offers with setVoiceCommands(labels). When the wearer says one, your companion receives {type: "voiceCommand", command} through onFromApp:
const stop = miraCompanion.onFromApp((message) => {
if (message.type !== "voiceCommand") return;
if (message.command === "New note") startNote();
if (message.command === "Save") saveNote();
});
await miraCompanion.setVoiceCommands(["New note", "Save"]);
await miraCompanion.startCapture();- Register up to 16 labels, and update them whenever the visible screen changes. Don’t register commands for screens that aren’t showing.
- Use named actions. Left, Right, Up, Down, Select, Approve and Cancel aren’t available to apps. Taps, swipes and the ring still navigate as usual.
- Pass a second argument naming the screen or record the commands belong to, so a command recognized just before the wearer moves on can’t act on the wrong one.
- For labels you make up as you go, like a saved note’s title, pass a third argument that describes what each one does:
await miraCompanion.setVoiceCommands(
["Open Groceries"],
"notes-page-1",
{ "Open Groceries": "Open the saved note titled Groceries." }
);Commands reach your app only while it’s in front, and they pause while MIRA shows its own overlays. MIRA’s own navigation commands keep working, and a pending approval comes first. MIRA clears your commands when the app closes.
When a command picks something on screen, move your highlight to it before you act, the same way a tap would, and don’t run the action a second time when the focus updates.
Dictation
For free-form text, start capture, then call startDictation(). Text arrives through onFromApp as {type: "dictation", text, confirmedText, final, status}, where confirmedText is the start of the text that won’t change anymore.
const stop = miraCompanion.onFromApp((message) => {
if (message.type === "dictation" && message.captureID === "title") {
titleField.value = message.text;
}
});
await miraCompanion.startCapture();
await miraCompanion.startDictation({ captureID: "title" });
// When the wearer is done:
const { text } = await miraCompanion.stopDictation();| Option | Does |
|---|---|
captureID | Comes back on every dictation event, so you can ignore late text after switching fields. |
includeRecentAudio: true | Starts with the last two seconds of audio, which can include the command that opened the field. Without it, dictation starts with fresh audio. |
endpointDetection: false | Keeps transcribing across pauses. By default, MIRA detects where speech ends. |
startDictation()fails unless your app’s capture is running. A MIRA listening session doesn’t count.stopDictation()resolves with{text}and keeps capture running, so your voice commands keep working. They also work during dictation.stopCapture()ends both capture and dictation. Closing the app or losing capture also ends dictation.