Skip to content

Commit 67dd9ef

Browse files
committed
Validate Kokoro voice metadata names
1 parent b1b2417 commit 67dd9ef

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

agent_cli/server/tts/wyoming_handler.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import logging
66
from functools import partial
7-
from pathlib import Path
87
from typing import TYPE_CHECKING
98

109
from wyoming.audio import AudioChunk, AudioStart, AudioStop
@@ -38,11 +37,18 @@
3837
def _tts_voice(name: str, backend_type: str) -> TtsVoice:
3938
"""Build Wyoming voice metadata for a registered TTS model."""
4039
if backend_type == "kokoro":
41-
from agent_cli.server.tts.backends.kokoro import DEFAULT_VOICE # noqa: PLC0415
40+
prefix, separator, voice_name = name.partition("_")
41+
is_voice = (
42+
separator == "_"
43+
and prefix[:1] in _KOKORO_LANGUAGE_TAGS
44+
and prefix[1:] in {"f", "m"}
45+
and bool(voice_name)
46+
)
47+
if not is_voice:
48+
from agent_cli.server.tts.backends.kokoro import DEFAULT_VOICE # noqa: PLC0415
4249

43-
if name == "kokoro" or Path(name).suffix.lower() == ".pth":
4450
name = DEFAULT_VOICE
45-
language = _KOKORO_LANGUAGE_TAGS.get(Path(name).stem[:1].lower(), "en")
51+
language = _KOKORO_LANGUAGE_TAGS[name[0]]
4652
return TtsVoice(
4753
name=name,
4854
description=f"Kokoro TTS {name}",

tests/test_server_tts_wyoming.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def test_kokoro_voice_language_tags(name: str, language: str) -> None:
3333
assert _tts_voice(name, "kokoro").languages == [language]
3434

3535

36-
@pytest.mark.parametrize("model_name", ["kokoro", "/models/kokoro-v1_0.pth"])
36+
@pytest.mark.parametrize(
37+
"model_name",
38+
["kokoro", "/models/kokoro-v1_0.pth", "kokoro-v1_0", "custom-model"],
39+
)
3740
def test_kokoro_model_name_advertises_default_voice(model_name: str) -> None:
3841
"""Kokoro model identifiers should not be advertised as voice names."""
3942
voice = _tts_voice(model_name, "kokoro")

0 commit comments

Comments
 (0)