How can I split response from agents
# ask-ai
b
How can I split response from agents
t
Thanks for reaching out, RikuKomiya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're exploring how to split agent responses into distinct components like text, audio, and transcripts in LiveKit! You can achieve this smoothly using the Realtime API by: • Subscribing to specific event types such as
response.text.delta
for text,
response.audio.delta
for audio, and
response.audio_transcript.delta
for transcripts. • Using separate asynchronous channels (
text_ch
for text and
audio_ch
for audio) to process and forward each modality. • Parsing and handling the stream of delta events to deliver content incrementally. Here’s a simple example of how you can access these split streams in your agent logic:
Copy code
# Access split audio output
async def custom_audio_node(agent, audio: AsyncIterable[rtc.AudioFrame]):
    async for frame in audio:
        yield frame

# Access split text output
async def custom_transcription_node(agent, text: AsyncIterable[str | TimedString]):
    async for chunk in text:
        yield chunk
This setup lets you handle text and audio separately, which is great for things like showing text in a UI while playing audio or analyzing transcripts on their own. If you have any questions or want me to walk you through this in more detail, just let me know—I’m here to help! Sources: plugins/openai/src/realtime/api_proto.ts | livekit-agents/livekit/agents/voice/agent.py