speaker_helper.profiles module
Per-language operating profiles: hyperparameters plus a measured operating point.
Module summary
A single engine speaks many languages, but the best settings differ per
language — which voice, and how to run the streaming producer/consumer (how
small to make the first chunk for low time-to-first-audio, how many chunks to
synthesise in parallel). A LanguageProfile bundles those knobs for one
language, together with the quality and RTF measured for it, so the
operating point is chosen from data rather than guessed.
Streaming in speaker-helper is a producer/consumer pipeline: a producer splits
the text into sentence-sized chunks and consumers synthesise them under a
bounded concurrency while emission stays in order (see
stream()). first_chunk_sentences
(producer granularity) and stream_concurrency (consumer parallelism) are the
two hyperparameters that trade time-to-first-audio against throughput; they live
here, per language.
run_multilang_eval() measures each language;
LanguageProfile.with_measurement() records that result back onto the
profile, and tune_profiles() builds measured profiles for a set of
languages in one call.
Usage example
>>> from speaker_helper.profiles import profile_for
>>> profile_for("en").engine
'kokoro'
>>> profile_for("en").first_chunk_sentences
1
- class speaker_helper.profiles.LanguageProfile(language, engine='kokoro', voice_id='', normalize=True, first_chunk_sentences=1, stream_concurrency=1, measured_rtf=None, measured_quality=None)[source]
Bases:
objectHyperparameters and a measured operating point for one language.
- Parameters:
language (str) – ISO-639-1 code this profile targets.
engine (str) – Engine/model id to use for this language.
voice_id (str) – Preset voice id; empty means “auto-pick a voice for the language”.
normalize (bool) – Ask the engine to loudness-normalise the output.
first_chunk_sentences (int) – Streaming producer granularity — sentences in the first emitted chunk.
1minimises time-to-first-audio.stream_concurrency (int) – Streaming consumer parallelism — chunks synthesised at once.
1is a strict pipeline (lowest first-audio latency).measured_rtf (float or None) – Mean real-time factor measured for this language, or
Noneif untuned.measured_quality (float or None) – Quality score in
[0, 1]measured for this language, orNone.
- apply(settings=None)[source]
Return
settings(or fresh defaults) with this profile applied.- Parameters:
settings (Settings or None) – Base configuration to derive from;
Noneuses defaults.- Returns:
A copy carrying this profile’s language, engine, voice, and producer granularity.
stream_concurrencyis aSpeakerargument, not aSettingsfield, so pass it separately (seefrom_profile()).- Return type:
- with_measurement(report)[source]
Return a copy with
measured_rtf/measured_qualityfrom a report.- Parameters:
report (EvalReport) – A report for this language (duck-typed: needs
mean_rtfandquality).- Returns:
A copy carrying the measured operating point.
- Return type:
- speaker_helper.profiles.profile_for(language)[source]
Return the profile for
language(a default profile if none is defined).- Parameters:
language (str)
- Return type:
- async speaker_helper.profiles.tune_profiles(base_settings, languages, **eval_kwargs)[source]
Measure a set of languages and return profiles carrying the results.
A thin convenience over
run_multilang_eval(): it runs the evaluation per language and folds each report’s RTF/quality into the correspondingLanguageProfile.- Parameters:
- Returns:
Mapping
language -> LanguageProfilewith measured RTF/quality.- Return type: