session.translation turns spoken speech into translated text. Register a handler
for the language pair you care about and results start arriving; the SDK handles
the subscription for you.
MICROPHONE permission in your
manifest. Without it the phone drops
the subscription and no events arrive. The rejection is silent: there is no error
event, your handler just never fires.
Results
Each event is aTranslationData:
Interim results stream as the user speaks and get replaced; wait for
isFinal if
you only want settled text. Use utteranceId to match an interim result to the
final one that supersedes it.
Choosing what to listen for
Three methods select which translations reach your handler. They differ only in how they pin the source and target language.
Each returns an unsubscribe function.
source and target are language tags
(for example "en", "es").
on() is the broad case. It registers cheaply on your side but asks the cloud to
fan every active pair out to you, so reach for to or fromTo once you know the
language(s) you want.
When the provider supplies originalText, you can show the source and the
translation together:
forLanguagePair(fromLang, toLang, handler) is a deprecated alias for
fromTo(source, target, handler). Use fromTo in new code; the alias will be
removed in a future release.Cleaning up
Every subscription returns an unsubscribe function.stop() tears down every
subscription this module owns at once:
session.translation.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.
Translation gives you translated text. For the untranslated transcript in the
spoken language, use
session.transcription.
Subscribing to one does not subscribe you to the other.
