You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/03-hooks/01-natural-language-processing/useTextToSpeech.md
+77-54Lines changed: 77 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ keywords: [
6
6
voice synthesizer,
7
7
transcription,
8
8
kokoro,
9
+
supertonic,
9
10
react native,
10
11
executorch,
11
12
ai,
@@ -19,7 +20,10 @@ description: "Learn how to use text-to-speech models in your React Native applic
19
20
Text to speech is a task that allows to transform written text into spoken language. It is commonly used to implement features such as voice assistants, accessibility tools, or audiobooks.
20
21
21
22
:::info
22
-
It is recommended to use models provided by us, which are available at our [Hugging Face repository](https://huggingface.co/software-mansion/react-native-executorch-kokoro). You can also use [constants](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/constants/modelUrls.ts) shipped with our library.
23
+
It is recommended to use models provided by us, which are available at our Hugging Face repositories:
24
+
[Kokoro](https://huggingface.co/software-mansion/react-native-executorch-kokoro) and
You can also use [constants](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/constants/modelUrls.ts) shipped with our library.
23
27
:::
24
28
25
29
## API Reference
@@ -32,6 +36,35 @@ It is recommended to use models provided by us, which are available at our [Hugg
32
36
33
37
You can play the generated waveform in any way most suitable to you; however, in the snippet below we utilize the react-native-audio-api library to play synthesized speech.
`useTextToSpeech` takes [`TextToSpeechModelConfig`](../../06-api-reference/interfaces/TextToSpeechModelConfig.md) that consists of:
60
93
61
-
-`model` of type [`TextToSpeechModelSources`](../../06-api-reference/type-aliases/TextToSpeechModelSources.md) containing the [`durationPredictorSource`](../../06-api-reference/type-aliases/TextToSpeechModelSources.md#durationpredictorsource), [`synthesizerSource`](../../06-api-reference/type-aliases/TextToSpeechModelSources.md#synthesizersource), and [`modelName`](../../06-api-reference/type-aliases/TextToSpeechModelSources.md#modelname).
62
-
-[`voiceSource`](../../06-api-reference/interfaces/TextToSpeechModelConfig.md#voicesource) of type [`ResourceSource`](../../06-api-reference/type-aliases/ResourceSource.md) - configuration of specific voice used in TTS.
63
-
-[`phonemizerConfig`](../../06-api-reference/interfaces/TextToSpeechModelConfig.md#phonemizerconfig) of type [`TextToSpeechPhonemizerConfig`](../../06-api-reference/interfaces/TextToSpeechPhonemizerConfig.md) - configuration of the phonemizer.
94
+
-`model` of type [`TextToSpeechModelSources`](../../06-api-reference/type-aliases/TextToSpeechModelSources.md) — model configuration.
95
+
-[`voiceSource`](../../06-api-reference/interfaces/TextToSpeechModelConfig.md#voicesource) of type [`ResourceSource`](../../06-api-reference/type-aliases/ResourceSource.md) — the voice tensor used for synthesis.
96
+
-[`phonemizerConfig`](../../06-api-reference/interfaces/TextToSpeechModelConfig.md#phonemizerconfig) of type [`TextToSpeechPhonemizerConfig`](../../06-api-reference/interfaces/TextToSpeechPhonemizerConfig.md) — Kokoro only: phonemizer configuration. Unused by Supertonic.
97
+
-[`lang`](../../06-api-reference/interfaces/TextToSpeechModelConfig.md#lang) of type [`TextToSpeechSupertonicLanguage`](../../06-api-reference/type-aliases/TextToSpeechSupertonicLanguage.md) — Supertonic only: default language token (e.g. `'en'`, `'na'`). Unused by Kokoro.
64
98
65
99
`useTextToSpeech`'s second optional argument is an object with:
66
100
@@ -79,21 +113,28 @@ You need more details? Check the following resources:
79
113
80
114
## Running the model
81
115
82
-
The module provides two ways to generate speech using either raw text or pre-generated phonemes:
116
+
The module provides two ways to generate speech. The available parameters differ by model family:
117
+
118
+
| Parameter | Kokoro | Supertonic |
119
+
| ------------ | ------ | ---------- |
120
+
|`speed`| ✓ ||
121
+
|`phonemize`| ✓ ||
122
+
|`totalSteps`|| ✓ |
123
+
|`lang`|| ✓ |
83
124
84
125
### Using Text
85
126
86
-
1.[**`forward({ text, speed, phonemize })`**](../../06-api-reference/interfaces/TextToSpeechType.md#forward): Generates the complete audio waveform at once. Returns a promise resolving to a `Float32Array`.
87
-
2.[**`stream({ speed, phonemize, stopAutomatically, onNext, ... })`**](../../06-api-reference/interfaces/TextToSpeechType.md#stream): An async generator-like functionality (managed via callbacks like `onNext`) that yields chunks of audio as they are computed.
127
+
1.[**`forward({ text, speed, phonemize, totalSteps, lang })`**](../../06-api-reference/interfaces/TextToSpeechType.md#forward): Generates the complete audio waveform at once. Returns a promise resolving to a `Float32Array`.
128
+
2.[**`stream({ speed, phonemize, totalSteps, lang, stopAutomatically, onNext, ... })`**](../../06-api-reference/interfaces/TextToSpeechType.md#stream): An async generator-like functionality (managed via callbacks like `onNext`) that yields chunks of audio as they are computed.
88
129
This is ideal for reducing the "time to first audio" for long sentences. You can also dynamically insert text during the generation process using `streamInsert(text)`, force-partition trailing content without an end-of-sentence character via `streamFlush()`, and stop the stream with `streamStop(instant)`.
89
130
90
131
:::tip Recommendation
91
132
In most cases, the **`stream()`** method is recommended over `forward()`. It significantly reduces latency by allowing audio playback to begin as soon as the first chunk is synthesized, rather than waiting for the entire text to be processed.
92
133
:::
93
134
94
-
Both methods accept a `phonemize` parameter (defaults to `true`). When set to `true`, the input `text` is treated as raw text and converted to phonemes internally. When set to `false`, the input is expected to be a string of IPA phonemes.
135
+
Both methods accept a `phonemize` parameter (defaults to `true`). This applies to **Kokoro only** — Supertonic maps text directly through a unicode indexer and does not use phonemization. When set to `true`, the input `text` is treated as raw text and converted to phonemes internally. When set to `false`, the input is expected to be a string of IPA phonemes.
95
136
96
-
### Using Phonemes
137
+
### Using Phonemes (Kokoro only)
97
138
98
139
If you have pre-computed phonemes (e.g., from an external dictionary or a custom G2P model), you can skip the internal phoneme generation step:
99
140
@@ -106,7 +147,7 @@ Since `forward` and `stream` process the input, they might take a significant am
@@ -182,42 +238,9 @@ export default function App() {
182
238
}
183
239
```
184
240
185
-
### Synthesis from Phonemes
186
-
187
-
If you already have a phoneme string obtained from an external source (e.g. the Python `phonemizer` library,
188
-
`espeak-ng`, or any custom phonemizer), you can use `forward` or `stream` with the `phonemize: false` flag to synthesize audio directly, skipping the phoneme generation stage.
0 commit comments