index
Effects
kokoro::download
effect kokoro::download {
model: string;
sizeBytes: number;
source: string;
dir: string
}(source)
kokoro::speak
effect kokoro::speak {
textLength: number;
voice: string;
outputFile: string;
format: string
}(source)
Functions
speak
speak(
text: string,
outputFile: string = "",
voice: string = "af_heart",
model: string = "fp32",
speed: number = 1,
allowedPaths: string[] = [],
format: string = "",
modelsDir: string | null = null,
): string raises <kokoro::download, kokoro::speak>Speak text into an audio file. Returns the file path.
Text-to-speech that runs on this machine. After the model is downloaded once, no text is sent over the network. fp32 is faster. q8 is a smaller download: 92 MB instead of 326 MB.
The format comes from format when given, otherwise from the output file's extension, otherwise it is wav. An explicit format wins even when the extension says something else. mp3 and m4a are encoded by ffmpeg at 96 kbit/s, and speak refuses them before raising any interrupt when ffmpeg is missing.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| text | string | The text to speak, at most 50,000 characters | |
| outputFile | string | "" | Where to write the file. Leave empty for a new temp file. An existing file is never overwritten. |
| voice | string | "af_heart" | A voice id from voices(), such as "af_heart" |
| model | string | "fp32" | "fp32" or "q8" |
| speed | number | 1 | Speaking speed, from 0.5 to 2 |
| allowedPaths | string[] | [] | Directories that outputFile must be inside |
| format | string | "" | "wav", "mp3", or "m4a". Leave empty to use the output file's extension, or wav when it has none. |
| modelsDir | string | null | null | Where models are kept. Leave null for the default. |
Returns: string
Throws: kokoro::download, kokoro::speak
(source)
download
download(
model: string = "fp32",
modelsDir: string | null = null,
): string raises <kokoro::download>Download a Kokoro text-to-speech model. Returns the directory it is in. Does nothing when it is already there.
Fetches a model before the first speak call needs it. Calling this is optional: speak downloads a missing model itself. The directory is chosen the same way speak chooses it.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| model | string | "fp32" | "fp32" (326 MB) or "q8" (92 MB) |
| modelsDir | string | null | null | Where models are kept. Leave null for the default. |
Returns: string
Throws: kokoro::download
(source)
voices
voices(): Voice[]List the Kokoro voices. Each voice has an id, name, language, gender, and a quality grade from A (best) to F.
Returns: Voice[]
(source)