Skip to main content
Mentra Miniapp SDK betaThe SDK is in beta, so its APIs may change before general availability.There is currently no way to distribute a miniapp built with the Miniapp SDK. In a future release, developers will upload miniapps through the Mentra Developer Console, and users will download them from the Mentra Miniapp Store. Neither service supports Miniapp SDK distribution in MentraOS 3.0.Only use the Miniapp SDK if you are comfortable with these limitations.Developing on Mentra Live? We recommend using the Mentra Bluetooth SDK.To enable miniapp development, open Settings in the Mentra App and tap the version number at the bottom ten times. Then open Debug Settings, turn on Miniapp Developer Settings, return to Settings, and open Miniapp Developer Settings.Share feedback with an in-app bug report, on Discord, or by email at help@mentra.glass.
session.speaker is audio output: play a URL, speak text, or stream live PCM. Playback follows the phone’s media route, including connected Bluetooth audio glasses. For audio input (mic frames, voice activity), use session.mic instead.
src/background/index.ts

Methods

Playing a URL

play streams an audio URL through the phone’s playback service and resolves when it finishes.
PlayAudioOptions:

Text-to-speech

speak sends the text to the phone, which streams cloud TTS when connected and falls back to local offline TTS when the cloud is unavailable. It resolves when playback completes. Offline playback may segment longer text internally to reduce latency; callers use the same speak() API and receive the same interruption behavior in either mode. By default, the Mentra App converts display-oriented markup and symbols into natural spoken words before either TTS path runs. For example, 68°F (20°C) becomes “68 degrees Fahrenheit or 20 degrees Celsius.” Set enableSanitization: false when the TTS engine must receive the exact input, such as code, equations, or character-by-character content.
SpeakOptions: SpeakResult has one field, completed: true if playback finished, false if it was interrupted.

Live PCM streaming

Use createStream() when audio arrives incrementally and cannot be exposed as a complete file or URL—for example, live meeting audio received over a WebSocket. The stream accepts signed 16-bit little-endian mono PCM on Android and iOS.
Live PCM requires Mentra App 2.13.0 or newer. Set minHostVersion: "2.13.0" in a miniapp that depends on createStream() so older hosts reject installation instead of failing during a call.
src/background/index.ts
SpeakerStreamOptions: The returned SpeakerStreamWriter has:
Always await writes and call either close() or abort(). The host also aborts the stream when the miniapp disconnects, but explicit teardown gives the best call-end latency. Compressed MP3, AAC, and Opus frames are not accepted; decode them to PCM before writing.

Errors

speak rejects with an object carrying a code field on cloud-side TTS failure. Catch it and branch on code:

State

Five states, read synchronously via state or isPlaying, or observed as transitions via onStateChange: A request moves idleloadingplayingstopped. On failure the speaker fires error once with errorCode set, then settles to stopped so isPlaying reads false.
SpeakerStateEvent:
onStateChange does not fire immediately with the current value. Read state separately if you want the starting value. Audio input (mic frames and voice-activity detection) lives on session.mic.