# SpeechSynthesizerOptions.Builder


```
class SpeechSynthesizerOptions.Builder
```

<br />

*** ** * ** ***

Builder for `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions`.

## Summary

| ### Public constructors |
|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder#Builder(java.util.Locale)(locale: https://developer.android.com/reference/java/util/Locale.html)` |

| ### Public functions |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder#addEarcon(kotlin.String,android.net.Uri)(earcon: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, uri: https://developer.android.com/reference/android/net/Uri.html)` Associates the specified earcon with the specified Uri. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder#addSpeech(kotlin.String,android.net.Uri)(speech: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, uri: https://developer.android.com/reference/android/net/Uri.html)` Associates the specified speech text with the specified Uri. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder#build()()` Builds the `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions` instance. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder#setExecutor(java.util.concurrent.Executor)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` to be used for background operations. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder#setLocale(java.util.Locale)(locale: https://developer.android.com/reference/java/util/Locale.html)` Sets the default `https://developer.android.com/reference/java/util/Locale.html` for speech synthesis. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions.Builder#setVoiceFallbackEnabled(kotlin.Boolean)(enabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` 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 `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizerOptions` instance.

### setExecutor

```
fun setExecutor(executor: Executor): SpeechSynthesizerOptions.Builder
```

Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` to be used for background operations.

### setLocale

```
fun setLocale(locale: Locale): SpeechSynthesizerOptions.Builder
```

Sets the default `https://developer.android.com/reference/java/util/Locale.html` for speech synthesis.

This is only a default. `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/SpeechSynthesizer#getSupportedVoices(java.util.Locale)` accepts a locale of its own, and the rest of the API follows the locale carried by each `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/texttospeech/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.