AndroidSpeechSynthesisSession

A SpeechSynthesizing backed by Android's TextToSpeech.

The engine is created lazily on first use and kept until close. Each speak interrupts whatever is being spoken (the previous request's flow ends with SpeechSynthesisEvent.Cancelled). Call close when finished to release the engine; a closed session creates a fresh engine on the next use.

The logger receives lengths, language tags, and error codes only, never the spoken text.

Parameters

context

Any context; the application context is retained.

logger

Receives diagnostic messages. Defaults to NoOpLogger.

Constructors

Link copied to clipboard
constructor(context: Context, logger: KommonLogger = NoOpLogger)

Creates a session. The engine itself is not created until the first speak or voices.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open override fun speak(request: SpeechSynthesisRequest): Flow<SpeechSynthesisEvent>

Speaks request, interrupting anything already being spoken.

Link copied to clipboard
open override fun stop()

Stops speaking. No-op when idle.

Link copied to clipboard
open suspend override fun voices(): List<SpeechVoice>

Every voice the engine offers.