Learn how to build a MentraOS app that listens to live speech transcriptions, detects a custom activation phrase (e.g., “computer”), and triggers UI actions like showing a text overlay. Includes prerequisites, full sample code, and best practices.
Looking for a broader introduction? Start with the Quickstart guide. This page focuses specifically on the app code that handles transcriptions.
0.13.0
installed in your project.src/index.ts
.
# | Code | Purpose |
---|---|---|
1️⃣ | session.events.onTranscription | Subscribes to real-time speech data. The callback fires many times per utterance—both interim and final chunks. |
2️⃣ | if (!data.isFinal) return; | Filters out interim chunks so we only process complete sentences. |
3️⃣ | spokenText.toLowerCase().trim() | Normalizes the text to improve keyword matching. |
4️⃣ | if (spokenText.includes(...)) | Simple string containment check for the activation phrase. |
5️⃣ | session.layouts.showTextWall(...) | Shows a full-screen text overlay on the glasses. Replace with your own logic. |
6️⃣ | this.addCleanupHandler(unsubscribe) | Ensures the transcription listener is removed when the session disconnects, preventing memory leaks. |
.env
: