Skip to content

Commit 7e0ca11

Browse files
committed
CambTTSService: initialize client during StartFrame
1 parent 13c52e0 commit 7e0ca11

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

changelog/3511.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed a `CambTTSService` issue where client was being initialized in the constructor which wouldn't allow for proper Pipeline error handling.

src/pipecat/services/camb/tts.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ def __init__(
199199
"""
200200
super().__init__(sample_rate=sample_rate, **kwargs)
201201

202-
params = params or CambTTSService.InputParams()
202+
self._api_key = api_key
203+
self._timeout = timeout
203204

204-
self._client = AsyncCambAI(api_key=api_key, timeout=timeout)
205+
params = params or CambTTSService.InputParams()
205206

206207
# Warn if sample rate doesn't match model's supported rate
207208
if sample_rate and sample_rate != MODEL_SAMPLE_RATES.get(model):
@@ -222,6 +223,8 @@ def __init__(
222223
self.set_voice(str(voice_id))
223224
self._voice_id = voice_id
224225

226+
self._client = None
227+
225228
def can_generate_metrics(self) -> bool:
226229
"""Check if this service can generate processing metrics.
227230
@@ -249,6 +252,8 @@ async def start(self, frame: StartFrame):
249252
"""
250253
await super().start(frame)
251254

255+
self._client = AsyncCambAI(api_key=self._api_key, timeout=self._timeout)
256+
252257
# Use model-specific sample rate if not explicitly specified
253258
if not self._init_sample_rate:
254259
self._sample_rate = MODEL_SAMPLE_RATES.get(self.model_name, 22050)
@@ -289,6 +294,8 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
289294
await self.start_tts_usage_metrics(text)
290295
yield TTSStartedFrame()
291296

297+
assert self._client is not None, "Camb.ai TTS service not initialized"
298+
292299
# Buffer for aligning chunks to 2-byte boundaries (16-bit PCM)
293300
audio_buffer = b""
294301

0 commit comments

Comments
 (0)