diff --git a/src/agents/voice/model.py b/src/agents/voice/model.py index 3b4a8e85b5..c4dce67e96 100644 --- a/src/agents/voice/model.py +++ b/src/agents/voice/model.py @@ -87,6 +87,12 @@ class TTSModelSettings: speed: float | None = None """The speed with which the TTS model will read the text. Between 0.25 and 4.0.""" + def __post_init__(self) -> None: + # Configurations loaded from JSON/YAML commonly represent NumPy dtypes as strings. + # Normalize those spellings once at the settings boundary so downstream consumers can + # compare against the supported NumPy dtypes consistently. + self.dtype = np.dtype(self.dtype) + class TTSModel(abc.ABC): """A text-to-speech model that can convert text into audio output.""" @@ -228,3 +234,4 @@ def get_stt_model(self, model_name: str | None) -> STTModel: @abc.abstractmethod def get_tts_model(self, model_name: str | None) -> TTSModel: """Get a text-to-speech model by name.""" + pass diff --git a/tests/voice/test_tts_model_settings.py b/tests/voice/test_tts_model_settings.py new file mode 100644 index 0000000000..db2470c234 --- /dev/null +++ b/tests/voice/test_tts_model_settings.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +import numpy as np + +from agents.voice import TTSModelSettings + + +def test_tts_model_settings_normalizes_string_dtype() -> None: + settings = TTSModelSettings(dtype="float32") + + assert settings.dtype == np.dtype("float32") + + +def test_tts_model_settings_normalizes_int16_dtype() -> None: + settings = TTSModelSettings(dtype="int16") + + assert settings.dtype == np.dtype("int16") + + +def test_tts_model_settings_accepts_numpy_dtype() -> None: + settings = TTSModelSettings(dtype=np.float32) + + assert settings.dtype == np.dtype("float32")