From 671dc8cd9bbe305c31f82d6891ff4a03cef0d6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Mon, 19 Jan 2026 20:32:28 -0800 Subject: [PATCH] NvidiaSTTService: initialize client on StartFrame Initialize client on StartFrame so errrors are reported within the pipeline. --- src/pipecat/services/nvidia/stt.py | 91 ++++++++++++++++-------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/src/pipecat/services/nvidia/stt.py b/src/pipecat/services/nvidia/stt.py index 0d671571f..639e76535 100644 --- a/src/pipecat/services/nvidia/stt.py +++ b/src/pipecat/services/nvidia/stt.py @@ -134,6 +134,7 @@ class NvidiaSTTService(STTService): params = params or NvidiaSTTService.InputParams() + self._server = server self._api_key = api_key self._use_ssl = use_ssl self._profanity_filter = False @@ -162,19 +163,55 @@ class NvidiaSTTService(STTService): self.set_model_name(model_function_map.get("model_name")) - metadata = [ - ["function-id", self._function_id], - ["authorization", f"Bearer {api_key}"], - ] - auth = riva.client.Auth(None, self._use_ssl, server, metadata) - - self._asr_service = riva.client.ASRService(auth) - + self._asr_service = None self._queue = None self._config = None self._thread_task = None self._response_task = None + def _initialize_client(self): + metadata = [ + ["function-id", self._function_id], + ["authorization", f"Bearer {self._api_key}"], + ] + auth = riva.client.Auth(None, self._use_ssl, self._server, metadata) + + self._asr_service = riva.client.ASRService(auth) + + def _create_recognition_config(self): + """Create the NVIDIA Riva ASR recognition configuration.""" + config = riva.client.StreamingRecognitionConfig( + config=riva.client.RecognitionConfig( + encoding=riva.client.AudioEncoding.LINEAR_PCM, + language_code=self._language_code, + model="", + max_alternatives=1, + profanity_filter=self._profanity_filter, + enable_automatic_punctuation=self._automatic_punctuation, + verbatim_transcripts=not self._no_verbatim_transcripts, + sample_rate_hertz=self.sample_rate, + audio_channel_count=1, + ), + interim_results=True, + ) + + riva.client.add_word_boosting_to_config( + config, self._boosted_lm_words, self._boosted_lm_score + ) + + riva.client.add_endpoint_parameters_to_config( + config, + self._start_history, + self._start_threshold, + self._stop_history, + self._stop_history_eou, + self._stop_threshold, + self._stop_threshold_eou, + ) + riva.client.add_custom_configuration_to_config(config, self._custom_configuration) + + return config + def can_generate_metrics(self) -> bool: """Check if this service can generate processing metrics. @@ -206,41 +243,9 @@ class NvidiaSTTService(STTService): frame: StartFrame indicating pipeline start. """ await super().start(frame) + self._initialize_client() + self._config = self._create_recognition_config() - if self._config: - return - - config = riva.client.StreamingRecognitionConfig( - config=riva.client.RecognitionConfig( - encoding=riva.client.AudioEncoding.LINEAR_PCM, - language_code=self._language_code, - model="", - max_alternatives=1, - profanity_filter=self._profanity_filter, - enable_automatic_punctuation=self._automatic_punctuation, - verbatim_transcripts=not self._no_verbatim_transcripts, - sample_rate_hertz=self.sample_rate, - audio_channel_count=1, - ), - interim_results=True, - ) - - riva.client.add_word_boosting_to_config( - config, self._boosted_lm_words, self._boosted_lm_score - ) - - riva.client.add_endpoint_parameters_to_config( - config, - self._start_history, - self._start_threshold, - self._stop_history, - self._stop_history_eou, - self._stop_threshold, - self._stop_threshold_eou, - ) - riva.client.add_custom_configuration_to_config(config, self._custom_configuration) - - self._config = config self._queue = asyncio.Queue() if not self._thread_task: @@ -250,6 +255,8 @@ class NvidiaSTTService(STTService): self._response_queue = asyncio.Queue() self._response_task = self.create_task(self._response_task_handler()) + logger.debug(f"Initialized NvidiaSTTService with model: {self.model_name}") + async def stop(self, frame: EndFrame): """Stop the NVIDIA Riva STT service and clean up resources.