Merge pull request #3511 from pipecat-ai/aleix/camb-tts-client-on-start

CambTTSService: initialize client during StartFrame
This commit is contained in:
Aleix Conchillo Flaqué
2026-01-20 19:17:45 -08:00
committed by GitHub
2 changed files with 10 additions and 2 deletions

1
changelog/3511.fixed.md Normal file
View File

@@ -0,0 +1 @@
- Fixed a `CambTTSService` issue where client was being initialized in the constructor which wouldn't allow for proper Pipeline error handling.

View File

@@ -199,9 +199,10 @@ class CambTTSService(TTSService):
"""
super().__init__(sample_rate=sample_rate, **kwargs)
params = params or CambTTSService.InputParams()
self._api_key = api_key
self._timeout = timeout
self._client = AsyncCambAI(api_key=api_key, timeout=timeout)
params = params or CambTTSService.InputParams()
# Warn if sample rate doesn't match model's supported rate
if sample_rate and sample_rate != MODEL_SAMPLE_RATES.get(model):
@@ -222,6 +223,8 @@ class CambTTSService(TTSService):
self.set_voice(str(voice_id))
self._voice_id = voice_id
self._client = None
def can_generate_metrics(self) -> bool:
"""Check if this service can generate processing metrics.
@@ -249,6 +252,8 @@ class CambTTSService(TTSService):
"""
await super().start(frame)
self._client = AsyncCambAI(api_key=self._api_key, timeout=self._timeout)
# Use model-specific sample rate if not explicitly specified
if not self._init_sample_rate:
self._sample_rate = MODEL_SAMPLE_RATES.get(self.model_name, 22050)
@@ -289,6 +294,8 @@ class CambTTSService(TTSService):
await self.start_tts_usage_metrics(text)
yield TTSStartedFrame()
assert self._client is not None, "Camb.ai TTS service not initialized"
# Buffer for aligning chunks to 2-byte boundaries (16-bit PCM)
audio_buffer = b""