polite-dog-12152
10/31/2025, 7:16 AMtall-airline-16756
10/31/2025, 7:16 AMpolite-dog-12152
10/31/2025, 7:17 AMtall-airline-16756
10/31/2025, 7:17 AMstt_node() method in a custom Agent class. This lets you gently intercept and work with the audio stream before it’s sent off for transcription.
Here’s a simple overview to guide you through:
1. Start by creating your own custom Agent class and override the stt_node() method.
2. Inside this method, you can set up a generator function that processes each rtc.AudioFrame from the incoming audio stream.
3. Feel free to add any processing you need, like buffering, voice activity detection (VAD), or other audio tweaks.
4. Then, yield the processed frames back to the base stt_node() method so transcription can proceed smoothly.
Here’s a little example to illustrate how you might wrap the original audio stream in a generator function to analyze or adjust the frames:
async def stt_node(self, audio: AsyncIterable[rtc.AudioFrame], model_settings: Optional[dict] = None) -> Optional[AsyncIterable[str]]:
async def audio_with_buffer():
async for frame in audio:
# Perform custom processing here (e.g., VAD, buffering)
yield frame
return super().stt_node(audio_with_buffer(), model_settings)
This way, you have full control over the audio preprocessing step, which opens up possibilities like real-time VAD, buffering audio, or applying filters before the transcription happens. If you have any questions or want to dive deeper into any part, I’m here to help!
Sources: basics/interrupts_user.py | examples/voice_agents/resume_interrupted_agent.pypolite-dog-12152
10/31/2025, 7:40 AMtall-airline-16756
10/31/2025, 7:40 AMaudio_buffer: list[np.int16] = []
chunk_size = 16 * 50 # 500ms of audio at 16kHz
async for frame in audio_stream:
audio_data = frame.data.tobytes()
audio_array = np.frombuffer(audio_data, dtype=np.int16)
audio_buffer.extend(audio_array)
while len(audio_buffer) >= chunk_size:
chunk_data = np.array(audio_buffer[:chunk_size], dtype=np.int16)
# Process or send the chunk
audio_buffer = audio_buffer[chunk_size:]
If you’d like, I’m here to walk you through more details or help with examples tailored just for your needs. Feel free to ask anytime!
Sources: livekit-plugins/livekit-plugins-sarvam/livekit/plugins/sarvam/stt.py | examples/local_audio/src/main.rs | AI Agents Framework | livekit/livekit_composite | DeepWiki | stream_audio.py | Processing raw media tracks | LiveKit docspolite-dog-12152
10/31/2025, 9:00 AMtall-airline-16756
10/31/2025, 9:02 AMupdate_options() method on your TTS instance to adjust parameters on the fly. For example:
self.tts.update_options(
model="blizzard",
voice="leah",
language="en",
format="mp3",
sample_rate=24000,
temperature=1.0,
top_p=0.8
)
These changes will take effect with the very next utterance. This means you can switch voices, languages, or other settings smoothly during your conversation.
Updating LLM Settings
When you want to tweak the LLM’s behavior, here are some handy methods you can use:
• await self.update_instructions("New instructions for the agent") - This updates the system instructions.
• await self.update_tools([new_tool_1, new_tool_2]) - Use this to change the available tools.
• await self.update_chat_ctx(new_chat_context) - This lets you update the chat context dynamically.
Example: Switching TTS Voice Mid-Conversation
class SayPhraseInVoiceAgent(Agent):
async def say_phrase_in_voice(self, phrase, voice="Hades"):
self.tts.update_options(voice=voice)
await self.session.say(phrase)
self.tts.update_options(voice="Ashley")
If you’d like, I’m here to help with more details or specific examples tailored to your use case—just let me know!
Sources: livekit-agents/livekit/agents/voice/agent_session.py | pipeline-tts/tts_comparison/README.md | Modifying LLM output before TTS | LiveKit Docs | examples/src/restaurant_agent.ts | Hume TTS plugin guide | LiveKit Docs