SpeechSynthesizerOptions.Builder

class SpeechSynthesizerOptions.Builder


Builder for SpeechSynthesizerOptions.

Summary

Public constructors

Builder(locale: Locale)

Public functions

SpeechSynthesizerOptions.Builder

Associates the specified earcon with the specified Uri.

SpeechSynthesizerOptions.Builder

Associates the specified speech text with the specified Uri.

SpeechSynthesizerOptions

Builds the SpeechSynthesizerOptions instance.

SpeechSynthesizerOptions.Builder
setExecutor(executor: Executor)

Sets the Executor to be used for background operations.

SpeechSynthesizerOptions.Builder
setLocale(locale: Locale)

Sets the default Locale for speech synthesis.

SpeechSynthesizerOptions.Builder

Sets whether the synthesizer may use a different voice when the requested voice is unavailable on the device.

Public constructors

Builder

Builder(locale: Locale)

Public functions

addEarcon

@CanIgnoreReturnValue
fun addEarcon(earcon: String, uri: Uri): SpeechSynthesizerOptions.Builder

Associates the specified earcon with the specified Uri.

addSpeech

@CanIgnoreReturnValue
fun addSpeech(speech: String, uri: Uri): SpeechSynthesizerOptions.Builder

Associates the specified speech text with the specified Uri.

build

fun build(): SpeechSynthesizerOptions

Builds the SpeechSynthesizerOptions instance.

setExecutor

fun setExecutor(executor: Executor): SpeechSynthesizerOptions.Builder

Sets the Executor to be used for background operations.

setLocale

fun setLocale(locale: Locale): SpeechSynthesizerOptions.Builder

Sets the default Locale for speech synthesis.

This is only a default. SpeechSynthesizer.getSupportedVoices accepts a locale of its own, and the rest of the API follows the locale carried by each VoiceInfo, so one client can serve several languages.

setVoiceFallbackEnabled

@CanIgnoreReturnValue
fun setVoiceFallbackEnabled(enabled: Boolean): SpeechSynthesizerOptions.Builder

Sets whether the synthesizer may use a different voice when the requested voice is unavailable on the device.

When true (the default), a request for a voice that is not installed still produces audio: the synthesizer defers to the speech service, which selects a substitute voice. This keeps playback working for callers that have not downloaded a voice model.

Set this to false when the exact voice matters more than producing audio at all — for example when the voice carries the app's brand, or when the wrong accent would be worse than silence. Requests that cannot use the requested voice then fail instead of substituting.

Which substitute voice is chosen is decided by the speech service, not by this SDK.