How can I play an audio immediate if I face a wake...
# ask-ai
a
How can I play an audio immediate if I face a wake up word in between my LLM streaming?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can play an audio file immediately when a wake word is detected during LLM streaming by using the WakeWordHandler with a notification sound path. This handler is designed to work seamlessly with ongoing LLM streaming sessions and will play the specified audio as soon as the wake word is detected, before the LLM callback is executed.
Copy code
from agent_extensions.handlers import WakeWordHandler

wake_word_handler = WakeWordHandler(
    wake_word="sam",
    notification_sound_path="path/to/your/notification.wav"
)

agent = VoicePipelineAgent(
    # ... other configuration ...
    before_llm_cb=wake_word_handler.before_llm_callback
)
When the wake word is detected, the handler automatically plays the notification sound, ensuring immediate feedback even during streaming. For more advanced control, you can also use BackgroundAudioPlayer or send audio frames directly, but the WakeWordHandler approach is the most straightforward for your scenario. Sources: agent_extensions/agent_extensions/rag/handler.py | examples/voice_agents/background_audio.py | home_assistant/homeautomation.py
a
What is before_llm_cb?
t
Hey there! Let me break down
before_llm_cb
in a way that makes total sense. Think of it like a friendly backstage helper for the VoicePipelineAgent that gets things ready right before the big performance with the Large Language Model (LLM). Cool, right? 😊 • It helps you trim down conversation history so everything runs smoothly • You can sneak in extra cool info or context right at the last second The awesome part is how flexible this callback is! Check out this example where we keep things tidy by making sure the chat context doesn't get too long:
Copy code
async def truncate_context(assistant: VoicePipelineAgent, chat_ctx: llm.ChatContext):
    if len(chat_ctx.messages) > 15:
        chat_ctx.messages = chat_ctx.messages[-15:]

agent = VoicePipelineAgent(
    ...
    before_llm_cb=truncate_context,
)
Pro tip: In LiveKit Agents 1.0, they've upgraded this with
llm_node
to give you even more awesome customization options. Sources: VoicePipelineAgent | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | Vision Agent Quickstart | LiveKit Docs | Agents 0.x migration guide | LiveKit Docs
a
what is agent_extension and how to install it?
t
agent_extensions is like a super helpful toolkit for LiveKit agents that I think you'll find really useful! It's packed with some cool features that make working with agents smoother. Let me break down what it offers: • Inactivity Handler: Think of this as a friendly nudge when things get a bit too quiet • Wake Word Handler: Perfect for those voice assistant moments when you want to get things started • WAV Player: Easily play audio files in your LiveKit rooms It's a community-created package that lives in the
livekit-examples/agent-demos
repository - not an official plugin, but definitely worth checking out! Setting it up is super easy. Just run this command:
Copy code
pip install -e agent_extensions
Pro tip: Make sure you're in the right directory when you do this. The best part? It'll automatically handle all the dependencies like
livekit
,
python-dotenv
,
simpleaudio
, and
livekit-agents
for you. How convenient is that? Sources: LiveKit Agents integrations | LiveKit Docs | Infrastructure & Deployment | livekit/livekit_composite | DeepWiki | agent_extensions/agent_extensions/handlers/wake_word_handler.py | README.md