Skip to content

index ​

Effects ​

kokoro::download ​

ts
effect kokoro::download {
  model: string;
  sizeBytes: number;
  source: string;
  dir: string
}

(source)

kokoro::speak ​

ts
effect kokoro::speak {
  textLength: number;
  voice: string;
  outputFile: string;
  format: string
}

(source)

Functions ​

speak ​

ts
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:

NameTypeDefaultDescription
textstringThe text to speak, at most 50,000 characters
outputFilestring""Where to write the file. Leave empty for a new temp file. An existing file is never overwritten.
voicestring"af_heart"A voice id from voices(), such as "af_heart"
modelstring"fp32""fp32" or "q8"
speednumber1Speaking speed, from 0.5 to 2
allowedPathsstring[][]Directories that outputFile must be inside
formatstring"""wav", "mp3", or "m4a". Leave empty to use the output file's extension, or wav when it has none.
modelsDirstring | nullnullWhere models are kept. Leave null for the default.

Returns: string

Throws: kokoro::download, kokoro::speak

(source)

download ​

ts
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:

NameTypeDefaultDescription
modelstring"fp32""fp32" (326 MB) or "q8" (92 MB)
modelsDirstring | nullnullWhere models are kept. Leave null for the default.

Returns: string

Throws: kokoro::download

(source)

voices ​

ts
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)