session.transcription turns what the user says into text. Register a handler and
you start getting results; the SDK handles the subscription for you.
MICROPHONE permission in your
manifest. Without it, the phone
rejects the subscription with PERMISSION_NOT_DECLARED and no events arrive.
Results
Each event is aTranscriptionData:
Interim results stream as the user speaks and get replaced; wait for
isFinal if
you only want settled text.
Targeting languages
on() auto-detects the language. To listen for specific ones, use
forLanguage() with BCP-47 tags:
Cloud or on-device
Each listener chooses where its speech is transcribed with theprocessing
option, the final argument of on() and forLanguage():
preferLocal is the choice for a miniapp that listens all day: it keeps the
quality of the cloud as a fallback and costs nothing while the phone can do the
work. When no listener on a stream needs the cloud, the phone doesn’t send that
audio to the cloud at all.
The phone runs one on-device speech model at a time, the one the user picked
on its Speech page, and every miniapp’s on-device transcription uses it. If it
isn’t downloaded yet, the phone downloads it when a preferLocal or
localOnly listener in its language arrives, and loads it while any of them
stays subscribed.
forLanguage()gets on-device text only when the model is in that language. ApreferLocallistener in another language stays on the cloud; alocalOnlyone gets no text.on()(auto-detect) follows the model’s language, so it gets on-device text in whatever language the user picked. ApreferLocallistener whose miniapp setconfigure({languageHints})to a language the model can’t transcribe stays on the cloud, which can tell those languages apart.
data.source to see
where each result came from.
Routing is per listener. Other listeners on the same stream, and other
miniapps, keep their own choice.
processing replaces {forceLocal: true}, which still works as
processing: "localOnly" until SDK 4.0. When both are set, processing
wins. Mentra App versions before 3.4.0 don’t know processing: there,
"preferLocal" behaves like "preferCloud", and "localOnly" keeps
working.Model status
onModelStatus tells you what the on-device model behind your subscriptions
is doing. You get the current state right away, then every change:
Your on-device listeners are the
preferLocal and localOnly ones, and every
listener while the cloud is unreachable. The state is unavailable when you
have none, when the download or load failed (the phone retries on its own), or
when every one of them asks for a language other than the picked model’s
(reason names the picked language).
Ending an utterance early
A recognizer ends a line after its own end-of-speech pause. When your own rule decides the user is done, for example after voice activity reports enough silence, end the line now:"" when nothing was pending, or null when no on-device
recognizer is running or the picked model can’t end a line early (models that
transcribe in fixed chunks deliver their final text on their own).
Configuring
configure() tunes the recognizer. It’s fire-and-forget and applies to
subsequent results:
Cleaning up
Every subscription returns an unsubscribe function.stop() tears down every
subscription this module owns at once:
session.transcription.hasPermission tells you whether MICROPHONE is declared
in your manifest. It does not tell you whether the user granted the OS prompt: if
they denied it, your handler simply never fires. See
Permissions.
Transcription is for text. For raw audio frames or voice-activity detection, use
session.mic. For translated
text, use session.translation. Subscribing
to one does not subscribe you to the others.
