triagesim.audio

Optional speech synthesis via XTTS-v2. Requires the audio extra:

pip install "triagesim[audio]"

Documented by hand

This page is written manually rather than generated, because importing the module requires torch and TTS, heavy dependencies that the documentation build does not install.

See Audio rendering for worked examples.

SpeechRenderer

from triagesim.audio.renderer import SpeechRenderer

Local neural TTS renderer using XTTS-v2. Supports voice cloning from a reference WAV, and selects CUDA, MPS or CPU automatically.

Warning

triagesim/audio/__init__.py is empty, so from triagesim.audio import SpeechRenderer raises ImportError. Import from triagesim.audio.renderer as shown above.

__init__

SpeechRenderer(model_name: str = "tts_models/multilingual/multi-dataset/xtts_v2")
ParameterTypeDefaultDescription
model_namestr"tts_models/multilingual/multi-dataset/xtts_v2"Coqui TTS model identifier.

Selects a device and loads the model. On Apple Silicon it also sets torch.set_float32_matmul_precision("high"). GPU acceleration is passed to the underlying TTS object only when the device is CUDA.

Model loading is expensive; construct one renderer and reuse it.

Attributes

AttributeTypeDescription
devicestrThe selected device: "cuda", "mps" or "cpu".
ttsTTSThe underlying Coqui TTS model.

render

render(
    *,
    text: str,
    speaker_wav: str | Path,
    out_path: str | Path,
    language: str = "en",
) -> Path

Synthesise text in the voice of speaker_wav and write it to out_path. All arguments are keyword-only.

ParameterTypeDefaultDescription
textstr-Text to synthesise.
speaker_wavstr \| Path-Reference recording to clone.
out_pathstr \| Path-Destination WAV path. Parent directories are created.
languagestr"en"Language code for XTTS-v2.

Returns the Path that was written.

renderer = SpeechRenderer()

renderer.render(
    text="Can you tell me what happened this morning?",
    speaker_wav="voices/nurse.wav",
    out_path="audio/000_nurse.wav",
)

Licence and consent

XTTS-v2 carries its own model licence, separate from TriageSim's. Review its terms before publishing synthesised output, and only clone voices with the speaker's consent. See Audio rendering.