speaker_helper.voices module

Curated preset voices, keyed by language and gender.

Module summary

Auto-picking a voice from the engine’s presets (see resolution by language) is convenient but blind to gender: it takes the first voice whose language matches. When an application needs a specific male or female voice per language — a two-speaker dialogue, a role-played call — it should not have to hard-code raw engine ids.

This module names that choice. PRESET_VOICES is a small, curated set of real kokoro voices (the ids the kokoro backend actually serves), and voice_for() resolves a (language, gender) pair to one of them.

Notes on coverage

kokoro ships several English voices of each gender and one French voice, ff_siwis (female). It has no native French male voice, so the French male slot maps to a real male voice id (bm_george) that renders French text with a male timbre. Every id here is a genuine kokoro preset; none is a placeholder.

Usage example

>>> from speaker_helper.voices import voice_for
>>> voice_for("fr", "female")
'ff_siwis'
>>> voice_for("en", "male")
'am_michael'

Author

Warith HARCHAOUI — https://linkedin.com/in/warith-harchaoui

speaker_helper.voices.voice_for(language, gender='', *, index=0)[source]

Resolve a (language, gender) pair to a concrete kokoro voice id.

Parameters:
  • language (str) – ISO-639-1 language code.

  • gender (str, optional) – "male" or "female"; empty picks the first voice of the language.

  • index (int, optional) – Which matching voice to take when several exist, cycled modulo the count (so callers can hand out distinct voices to distinct speakers).

Returns:

A real kokoro voice_id. Falls back to the first voice of the language (ignoring gender), then to ff_siwis/am_michael-style defaults, so the result is always a usable id.

Return type:

str

speaker_helper.voices.voices_for(language, gender='')[source]

Return the curated voices matching language and, if given, gender.

Parameters:
  • language (str) – ISO-639-1 language code (e.g. "fr", "en").

  • gender (str, optional) – "male" or "female" to filter; empty returns both genders.

Returns:

Matching voices, in catalogue order (may be empty).

Return type:

list of Voice