SpeechSynthesizerOptions.Builder

public final class SpeechSynthesizerOptions.Builder


Builder for SpeechSynthesizerOptions.

Summary

Public constructors

Public methods

final @NonNull SpeechSynthesizerOptions.Builder

Associates the specified earcon with the specified Uri.

final @NonNull SpeechSynthesizerOptions.Builder

Associates the specified speech text with the specified Uri.

final @NonNull SpeechSynthesizerOptions

Builds the SpeechSynthesizerOptions instance.

final @NonNull SpeechSynthesizerOptions.Builder

Sets the Executor to be used for background operations.

final @NonNull SpeechSynthesizerOptions.Builder

Sets the default Locale for speech synthesis.

final @NonNull SpeechSynthesizerOptions.Builder

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

Public constructors

Builder

public Builder(@NonNull Locale locale)

Public methods

addEarcon

@CanIgnoreReturnValue
public final @NonNull SpeechSynthesizerOptions.Builder addEarcon(@NonNull String earcon, @NonNull Uri uri)

Associates the specified earcon with the specified Uri.

addSpeech

@CanIgnoreReturnValue
public final @NonNull SpeechSynthesizerOptions.Builder addSpeech(@NonNull String speech, @NonNull Uri uri)

Associates the specified speech text with the specified Uri.

build

public final @NonNull SpeechSynthesizerOptions build()

Builds the SpeechSynthesizerOptions instance.

setExecutor

public final @NonNull SpeechSynthesizerOptions.Builder setExecutor(@NonNull Executor executor)

Sets the Executor to be used for background operations.

setLocale

public final @NonNull SpeechSynthesizerOptions.Builder setLocale(@NonNull Locale locale)

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
public final @NonNull SpeechSynthesizerOptions.Builder setVoiceFallbackEnabled(boolean enabled)

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.