# SpeechSynthesizerOptions.Builder


```
public final class SpeechSynthesizerOptions.Builder
```

<br />

*** ** * ** ***

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

## Summary

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

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

### setExecutor

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

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

### setLocale

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

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/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/com/google/mlkit/genai/texttospeech/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.