@@ -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