Skip to content

Commit b9d0fec

Browse files
plutolessclaude
andcommitted
refactor: collapse TTS vendor configs; add resolved_sample_rate accessor
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6e54199 commit b9d0fec

4 files changed

Lines changed: 333 additions & 484 deletions

File tree

src/agora_agent/agentkit/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def with_llm(self, vendor: BaseLLM) -> "Agent":
473473
return new_agent
474474

475475
def with_tts(self, vendor: BaseTTS) -> "Agent":
476-
sample_rate = vendor.sample_rate
476+
sample_rate = vendor.resolved_sample_rate
477477
if (
478478
self._avatar_required_sample_rate not in (None, 0)
479479
and sample_rate is not None

src/agora_agent/agentkit/vendors/base.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ def to_config(self) -> Dict[str, Any]:
2828
"""Serialize the LLM configuration to a dict for the REST API."""
2929

3030

31-
class BaseTTS(ABC):
31+
class BaseTTS(BaseModel, ABC):
3232
"""Abstract base class for all TTS vendor implementations.
3333
34-
Subclasses must implement :meth:`to_config` and :attr:`sample_rate`.
34+
Subclasses must implement :meth:`to_config`.
3535
36-
``sample_rate`` is used by :class:`~agora_agent.agentkit.AgentSession` to
37-
validate TTS/avatar compatibility at runtime (avatars require a specific
38-
sample rate). Subclasses should return ``None`` when the user has not
39-
explicitly configured a sample rate, which will cause a warning at session
40-
start time rather than a hard error.
36+
:attr:`resolved_sample_rate` is used by
37+
:class:`~agora_agent.agentkit.AgentSession` to validate TTS/avatar
38+
compatibility at runtime (avatars require a specific sample rate). It
39+
returns ``None`` when the user has not explicitly configured a sample rate,
40+
which will cause a warning at session start time rather than a hard error.
4141
"""
4242

4343
@abstractmethod
4444
def to_config(self) -> Dict[str, Any]:
4545
"""Serialize the TTS configuration to a dict for the REST API."""
4646

4747
@property
48-
@abstractmethod
49-
def sample_rate(self) -> Optional[int]:
50-
"""The configured sample rate in Hz, or ``None`` if not explicitly set."""
48+
def resolved_sample_rate(self) -> Optional[int]:
49+
"""The effective configured sample rate in Hz, or None if not set."""
50+
return getattr(self, "sample_rate", None)
5151

5252

5353
class BaseSTT(BaseModel, ABC):

0 commit comments

Comments
 (0)