Address PR review feedback: remove debug logs, fix hasattr logic, add VADAnalyzer

This commit is contained in:
zack
2026-03-02 17:54:31 -05:00
parent 5c2ca0ce64
commit b449515410
2 changed files with 40 additions and 52 deletions

View File

@@ -10,6 +10,7 @@ import os
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.frames.frames import LLMRunFrame from pipecat.frames.frames import LLMRunFrame
from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.runner import PipelineRunner
@@ -122,7 +123,10 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
context = LLMContext(messages) context = LLMContext(messages)
user_aggregator, assistant_aggregator = LLMContextAggregatorPair( user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
context, context,
user_params=LLMUserAggregatorParams(user_turn_strategies=ExternalUserTurnStrategies()), user_params=LLMUserAggregatorParams(
user_turn_strategies=ExternalUserTurnStrategies(),
vad_analyzer=SileroVADAnalyzer(),
),
) )
pipeline = Pipeline( pipeline = Pipeline(

View File

@@ -212,7 +212,6 @@ class AssemblyAISTTService(WebsocketSTTService):
self._chunk_size_bytes = 0 self._chunk_size_bytes = 0
self._user_speaking = False self._user_speaking = False
self._vad_speaking = False
def _configure_pipecat_turn_mode( def _configure_pipecat_turn_mode(
self, connection_params: AssemblyAIConnectionParams, is_u3_pro: bool self, connection_params: AssemblyAIConnectionParams, is_u3_pro: bool
@@ -320,48 +319,44 @@ class AssemblyAISTTService(WebsocketSTTService):
old_conn_params = changed.get("connection_params") old_conn_params = changed.get("connection_params")
# Check each potentially changed parameter # Check each potentially changed parameter
if hasattr(conn_params, "keyterms_prompt"): if (
if ( old_conn_params is None
old_conn_params is None or conn_params.keyterms_prompt != old_conn_params.keyterms_prompt
or conn_params.keyterms_prompt != old_conn_params.keyterms_prompt ):
): if conn_params.keyterms_prompt is not None:
if conn_params.keyterms_prompt is not None: update_config["keyterms_prompt"] = conn_params.keyterms_prompt
update_config["keyterms_prompt"] = conn_params.keyterms_prompt logger.info(f"Updating keyterms_prompt to: {conn_params.keyterms_prompt}")
logger.info(f"Updating keyterms_prompt to: {conn_params.keyterms_prompt}")
if hasattr(conn_params, "prompt"): if old_conn_params is None or conn_params.prompt != old_conn_params.prompt:
if old_conn_params is None or conn_params.prompt != old_conn_params.prompt: if conn_params.prompt is not None:
if conn_params.prompt is not None: if conn_params.speech_model != "u3-rt-pro":
if conn_params.speech_model != "u3-rt-pro": logger.warning(
logger.warning( f"prompt parameter is only supported with u3-rt-pro model, "
f"prompt parameter is only supported with u3-rt-pro model, " f"current model is {conn_params.speech_model}"
f"current model is {conn_params.speech_model}"
)
else:
update_config["prompt"] = conn_params.prompt
logger.info(f"Updating prompt")
if hasattr(conn_params, "max_turn_silence"):
if (
old_conn_params is None
or conn_params.max_turn_silence != old_conn_params.max_turn_silence
):
if conn_params.max_turn_silence is not None:
update_config["max_turn_silence"] = conn_params.max_turn_silence
logger.info(
f"Updating max_turn_silence to: {conn_params.max_turn_silence}ms"
) )
else:
update_config["prompt"] = conn_params.prompt
logger.info(f"Updating prompt")
if hasattr(conn_params, "min_turn_silence"): if (
if ( old_conn_params is None
old_conn_params is None or conn_params.max_turn_silence != old_conn_params.max_turn_silence
or conn_params.min_turn_silence != old_conn_params.min_turn_silence ):
): if conn_params.max_turn_silence is not None:
if conn_params.min_turn_silence is not None: update_config["max_turn_silence"] = conn_params.max_turn_silence
update_config["min_turn_silence"] = conn_params.min_turn_silence logger.info(
logger.info( f"Updating max_turn_silence to: {conn_params.max_turn_silence}ms"
f"Updating min_turn_silence to: {conn_params.min_turn_silence}ms" )
)
if (
old_conn_params is None
or conn_params.min_turn_silence != old_conn_params.min_turn_silence
):
if conn_params.min_turn_silence is not None:
update_config["min_turn_silence"] = conn_params.min_turn_silence
logger.info(
f"Updating min_turn_silence to: {conn_params.min_turn_silence}ms"
)
# Send update if we have parameters to update # Send update if we have parameters to update
if len(update_config) > 1: # More than just "type" if len(update_config) > 1: # More than just "type"
@@ -639,20 +634,14 @@ class AssemblyAISTTService(WebsocketSTTService):
Only applies to Mode 2 (STT turn detection). In Mode 1, VAD + Only applies to Mode 2 (STT turn detection). In Mode 1, VAD +
smart turn analyzer handle interruptions via the aggregator. smart turn analyzer handle interruptions via the aggregator.
""" """
logger.debug(
f"{self} SpeechStarted received (vad_force_turn_endpoint={self._vad_force_turn_endpoint})"
)
if self._vad_force_turn_endpoint: if self._vad_force_turn_endpoint:
logger.debug(f"{self} SpeechStarted ignored in Pipecat mode")
return # Mode 1: handled by aggregator return # Mode 1: handled by aggregator
logger.debug(f"{self} Processing SpeechStarted in STT mode")
await self.start_processing_metrics() await self.start_processing_metrics()
await self.broadcast_frame(UserStartedSpeakingFrame) await self.broadcast_frame(UserStartedSpeakingFrame)
if self._should_interrupt: if self._should_interrupt:
await self.push_interruption_task_frame_and_wait() await self.push_interruption_task_frame_and_wait()
self._user_speaking = True self._user_speaking = True
logger.debug(f"{self} _user_speaking set to True")
async def _handle_termination(self, message: TerminationMessage): async def _handle_termination(self, message: TerminationMessage):
"""Handle termination message.""" """Handle termination message."""
@@ -730,7 +719,6 @@ class AssemblyAISTTService(WebsocketSTTService):
await self._trace_transcription(transcript_text, True, language) await self._trace_transcription(transcript_text, True, language)
await self.stop_processing_metrics() await self.stop_processing_metrics()
else: else:
logger.debug(f'{self} Interim transcript: "{transcript_text}"')
await self.push_frame( await self.push_frame(
InterimTranscriptionFrame( InterimTranscriptionFrame(
transcript_text, transcript_text,
@@ -744,10 +732,6 @@ class AssemblyAISTTService(WebsocketSTTService):
# --- Mode 2: STT turn detection --- # --- Mode 2: STT turn detection ---
# SpeechStarted always arrives before transcripts with u3-rt-pro, # SpeechStarted always arrives before transcripts with u3-rt-pro,
# so UserStartedSpeakingFrame is guaranteed to be broadcast first. # so UserStartedSpeakingFrame is guaranteed to be broadcast first.
logger.debug(
f"{self} Transcript received in STT mode (_user_speaking={self._user_speaking})"
)
if is_final_turn: if is_final_turn:
# STT mode: AssemblyAI controls finalization, just mark as finalized # STT mode: AssemblyAI controls finalization, just mark as finalized
await self.push_frame( await self.push_frame(