broad-painter-9222
11/03/2025, 3:45 PMtall-airline-16756
11/03/2025, 3:46 PMtall-airline-16756
11/03/2025, 3:46 PMroom.local_participant.publish_track in LiveKit! Let me walk you through the steps in a simple and clear way:
1. Initialize the TTS engine: First, set up an instance of the TTS service you want to use, like OpenAI, making sure to provide the necessary parameters such as the model and speed.
2. Create an AudioSource and LocalAudioTrack: Next, create an AudioSource using the TTS engine’s sample rate and number of channels. Then, create a LocalAudioTrack from this source:
source = rtc.AudioSource(tts.sample_rate, tts.num_channels)
track = rtc.LocalAudioTrack.create_audio_track("agent-mic", source)
3. Define TrackPublishOptions: Here, you specify the source of your track, like setting it to microphone for TTS audio:
options = rtc.TrackPublishOptions()
options.source = rtc.TrackSource.SOURCE_MICROPHONE
4. Connect to the room and publish the track: Now, connect your participant to the room and publish the audio track with these commands:
await job.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_NONE)
publication = await job.room.local_participant.publish_track(track, options)
await publication.wait_for_subscription()
5. Stream and play synthesized audio: Finally, use the TTS stream interface to send chunks of text and push the synthesized audio frames to the source:
stream = tts.stream()
async def _playback_task():
async for audio in stream:
await source.capture_frame(audio.frame)
task = asyncio.create_task(_playback_task())
words = text.split()
for i in range(0, len(words), 2):
chunk = " ".join(words[i : i + 2])
stream.push_text(chunk + " ")
stream.flush()
stream.end_input()
await asyncio.gather(task)
This method lets you publish synthesized speech in real-time within a LiveKit room, whether you're sending the entire text at once or streaming it bit by bit. If you have any questions or need further help, feel free to ask—I'm here to support you every step of the way!
Sources: examples/other/text-to-speech/sync_tts_transcription.pybroad-painter-9222
11/03/2025, 4:14 PMtall-airline-16756
11/03/2025, 4:15 PMlisten_to_agents=True in `RoomInputOptions`:
room_io = RoomIO(session, room=ctx.room,
input_options=RoomInputOptions(
listen_to_agents=True
))
◦ Alternatively, explicitly include agent participants with `participant_kinds`:
room_io = RoomIO(
session,
room=ctx.room,
input_options=RoomInputOptions(
participant_kinds=[
ParticipantKind.STANDARD,
ParticipantKind.AGENT # Enable agent-to-agent interaction
]
)
)
await room_io.start()
1. Initialize agent sessions: Make sure to configure your agent session with RoomInputOptions to include agent participants, like this:
await session.start(
agent=SimpleEvaluationAgent(),
room=ctx.room,
room_input_options=RoomInputOptions(
participant_kinds=[
rtc.ParticipantKind.PARTICIPANT_KIND_AGENT,
]
),
)
2. Best practices for testing:
◦ Define clear user personas and evaluation dimensions such as accuracy and latency.
◦ Run your tests in isolated rooms to avoid any interference.
◦ Consider using deterministic scenarios for regression testing and randomized ones for exploratory evaluation.
1. Structured evaluation workflow: It’s helpful to implement a workflow that includes:
◦ Creating an evaluation agent with predefined test scenarios.
◦ Using LLM tool calls to grade responses (like PASS/FAIL).
◦ Collecting important performance metrics such as response latency and turn-taking accuracy.
◦ Generating structured evaluation reports to keep track of results.
1. Testing frameworks: Tools like pytest can be very useful for behavioral tests, including fixtures, function tool mocking, and validating conversation flows.
Following these steps will set you up for success with agent-to-agent testing in LiveKit. If you have any questions or need further assistance, feel free to ask—I'm here to help!
Sources: How to test your agent using another agent | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | docs/index.yaml | Testing and evaluation | LiveKit Docs | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki