bulky-wall-61623
11/09/2025, 2:06 PMasync def stt_node(self, text: AsyncIterable[str], model_settings: Optional[dict] = None) -> Optional[AsyncIterable[rtc.AudioFrame]]:
keywords = ["Shane", "hello", "thanks", "bye"]
parent_stream = super().stt_node(text, model_settings)
if parent_stream is None:
return None
async def process_stream():
async for event in parent_stream:
if hasattr(event, 'type') and str(event.type) == "SpeechEventType.FINAL_TRANSCRIPT" and event.alternatives:
transcript = event.alternatives[0].text
for keyword in keywords:
if keyword.lower() in transcript.lower():
logger.info(f"Keyword detected: '{keyword}'")
yield event
return process_stream()tall-airline-16756
11/09/2025, 2:06 PMtall-airline-16756
11/09/2025, 2:06 PMasync def stt_node(self, text: AsyncIterable[str], model_settings: Optional[dict] = None) -> Optional[AsyncIterable[rtc.AudioFrame]]:
keywords = ["Shane", "hello", "thanks", "bye"]
parent_stream = super().stt_node(text, model_settings)
if parent_stream is None:
return None
async def process_stream():
async for event in parent_stream:
if hasattr(event, 'type') and str(event.type) == "SpeechEventType.FINAL_TRANSCRIPT" and event.alternatives:
transcript = event.alternatives[0].text
for keyword in keywords:
if keyword.lower() in transcript.lower():
logger.info(f"Keyword detected: '{keyword}'")
return # Stop the stream early
yield event
return process_stream()
With this approach, the generator will stop yielding events and exit as soon as it spots a keyword, which means the data flow to the next pipeline stage will pause right away.
If anything’s unclear or you’d like me to walk you through it further, just let me know—I’m here to help!
Sources: pipeline-llm/llm_powered_content_filter.py | Pipeline nodes and hooks | LiveKit docs | Camera & microphone | LiveKit Docsbulky-wall-61623
11/09/2025, 2:51 PMtall-airline-16756
11/09/2025, 2:52 PMasync def stt_node(self, text: AsyncIterable[str], model_settings: Optional[dict] = None) -> Optional[AsyncIterable[rtc.AudioFrame]]:
keywords = ["Shane", "hello", "thanks", "bye"]
parent_stream = super().stt_node(text, model_settings)
if parent_stream is None:
return None
async def process_stream():
async for event in parent_stream:
if hasattr(event, 'type') and str(event.type) == "SpeechEventType.FINAL_TRANSCRIPT" and event.alternatives:
transcript = event.alternatives[0].text
for keyword in keywords:
if keyword.lower() in transcript.lower():
logger.info(f"Keyword detected: '{keyword}'")
break # Skip processing this event but continue with the next
else:
yield event # Only yield if no keyword is detected
else:
yield event # Pass through non-transcript events
return process_stream()
This way, when a keyword pops up, the current event is gently skipped, but the stream keeps flowing smoothly with the next speech events. If anything feels unclear or you want me to walk you through more tweaks, just let me know—I’m here to help!
Sources: Pipeline nodes and hooks | LiveKit docs | Camera & microphone | LiveKit Docs | livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/s... | home_assistant/homeautomation.pybulky-wall-61623
11/09/2025, 4:42 PMtall-airline-16756
11/09/2025, 4:43 PMbreak statement isn’t working quite as you expected, no worries! You can try a different approach to skip processing specific events in the async generator. Here’s an updated example that might help:
async def stt_node(self, text: AsyncIterable[str], model_settings: Optional[dict] = None) -> Optional[AsyncIterable[rtc.AudioFrame]]:
keywords = ["Shane", "hello", "thanks", "bye"]
parent_stream = super().stt_node(text, model_settings)
if parent_stream is None:
return None
async def process_stream():
async for event in parent_stream:
if hasattr(event, 'type') and str(event.type) == "SpeechEventType.FINAL_TRANSCRIPT" and event.alternatives:
transcript = event.alternatives[0].text
# Check for keywords
if any(keyword.lower() in transcript.lower() for keyword in keywords):
logger.info(f"Keyword detected: '{transcript}'")
continue # Skip this event and move to the next
yield event # Pass through all other events
return process_stream()
In this version, the continue statement helps us skip the current event and smoothly move on to the next one. This way, the stream keeps processing all the following events without any hiccups.
Please feel free to let me know if this helps or if you’d like me to walk you through any other adjustments. I’m here to help!
Sources: Testing and evaluation | LiveKit Docs | Pipeline nodes and hooks | LiveKit docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...