triagesim.audio¶
Optional speech synthesis via XTTS-v2. Requires the audio extra:
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¶
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__¶
| Parameter | Type | Default | Description |
|---|---|---|---|
model_name | str | "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
| Attribute | Type | Description |
|---|---|---|
device | str | The selected device: "cuda", "mps" or "cpu". |
tts | TTS | The 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | — | Text to synthesise. |
speaker_wav | str \| Path | — | Reference recording to clone. |
out_path | str \| Path | — | Destination WAV path. Parent directories are created. |
language | str | "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.