Text to Speech
Generate natural-sounding speech from text, ready to save as a WAV file or play back in your app.
import 'dart:io';
import 'package:nobodywho/nobodywho.dart' as nobodywho;
// ... after NobodyWho.init().
final tts = await nobodywho.Tts.load(
source: 'hf://NobodyWho/Kokoro-82M', // Hugging Face repo (hf://owner/repo) or local folder with the model files.
voice: 'bf_emma', // Voice to use from the model.
language: 'en-gb', // Language code for the input text.
);
// Generate WAV bytes for this sentence.
final wav = await tts.synthesize(text: 'Hello from NobodyWho!');
// Save the audio to a file.
await File('out.wav').writeAsBytes(wav);
Models and sources
NobodyWho supports two speech synthesis architectures, both in ONNX format:
- Kokoro, a lightweight 24 kHz speech synthesis model. Model page:
NobodyWho/Kokoro-82M. - Supertonic, a multi-stage speech synthesis model with voice styles. Model page:
Supertone/supertonic-3.
source can be a Hugging Face repo (hf://owner/repo) as shown above, or a local directory laid out the same way as that repo. See Local model folder format and Architecture for setup details.
Kokoro
For Kokoro, set voice and language together. They must agree with the model's available voices.
// ... after NobodyWho.init().
final tts = await nobodywho.Tts.load(
source: 'hf://NobodyWho/Kokoro-82M',
voice: 'bf_emma',
language: 'en-gb',
);
Optional settings include:
voice: voice to use from the model, e.g.bf_emma. See the Kokoro voices folder for the full list. Defaults tobf_emma.language: input language code. Supported values are listed on the Kokoro model page. Defaults toen-gb.speed: speech speed multiplier.1.0is normal speed, lower values are slower, higher values are faster. Defaults to1.0.
Supertonic
For Supertonic, you can start with the default voice and language, or set them explicitly.
// ... after NobodyWho.init().
final tts = await nobodywho.Tts.load(
source: 'hf://Supertone/supertonic-3',
language: 'en',
);
Optional settings include:
voice: voice style. Supported values areM1toM5andF1toF5. Defaults toM1.language: input language code. See the Supertonic model page for the full list. Defaults toen.speed: speech speed multiplier.1.0is normal speed, lower values are slower, higher values are faster. Defaults to1.05.steps: denoising steps. Higher values can improve quality but are slower. Lower values are faster but can sound rougher. Must be greater than0; defaults to8.silenceDuration: seconds of silence between long text chunks. Higher values add longer pauses. Must be0or higher; defaults to0.3.
Architecture
architecture is the TTS model family behind a source. In most cases, you do not need to set it because NobodyWho can infer it by looking for "kokoro" or "supertonic" in the source string.
Set architecture when you use a local directory or a custom source that NobodyWho cannot recognize:
// ... after NobodyWho.init().
final tts = await nobodywho.Tts.load(
source: '/path/to/local/kokoro-folder',
architecture: .kokoro',
);
Supported architecture values are kokoro and supertonic.
GPU
TTS uses GPU acceleration by default when available. Disable it with useGpu: false:
// ... after NobodyWho.init().
final tts = await nobodywho.Tts.load(
source: 'hf://Supertone/supertonic-3',
useGpu: false,
);
Local model folder format
When source is a local directory, point it at the top-level model folder and pass the matching architecture.
Use the Hugging Face file browsers as the reference layouts:
- Kokoro:
NobodyWho/Kokoro-82M - Supertonic:
Supertone/supertonic-3
For Supertonic, that top-level folder must include both the onnx/ and voice_styles/ directories. Download the model files with the same relative paths, then pass that folder as source.