broad-painter-9222
11/03/2025, 2:12 PMtall-airline-16756
11/03/2025, 2:13 PMtall-airline-16756
11/03/2025, 2:13 PMroom.local_participant.publish_audio_track method or through a custom agent participant.
This approach lets you simulate user input, which is super helpful for testing or automation. Plus, you can customize the voice and audio features depending on the TTS provider you choose.
If you’d like, I’m here to help with any part of the implementation or to provide more details—just let me know!
Sources: pipeline-tts/cartesia_tts.py | Realtime model plugins | LiveKit Docs | OpenAI Realtime API plugin guide | LiveKit docs | Text-to-speech (TTS) models | LiveKit Docs | examples/voice_agents/realtime_load_chat_history.pybroad-painter-9222
11/03/2025, 2:14 PMtall-airline-16756
11/03/2025, 2:14 PMimport asyncio
import logging
from livekit import rtc
from livekit.agents.tts import StreamAdapter
from livekit.plugins import rime
async def simulate_voice():
# Initialize Rime TTS
tts = rime.TTS(model="arcana", speaker="astra")
# Set up audio source and track
source = rtc.AudioSource(tts.sample_rate, tts.num_channels)
track = rtc.LocalAudioTrack.create_audio_track("agent-mic", source)
# Publish the audio track to the room
room = await rtc.connect_to_room("your_room_url", "your_token")
await room.local_participant.publish_track(track)
# Prepare text for streaming
text = "Hello! This is a test of the TTS simulation in LiveKit."
stream = StreamAdapter(tts=tts).stream()
# Push text to TTS and stream audio
stream.push_text(text)
async for audio in stream:
await source.capture_frame(audio.frame)
# End the stream
stream.end_input()
# Run the simulation
asyncio.run(simulate_voice())
This script sets up a TTS model, streams the synthesized audio to a LiveKit room, and simulates user voice messages. Just be sure to swap out the placeholders like "your_room_url" and "your_token" with your actual LiveKit room details.
If you have any questions or would like me to walk you through a more specific example, please don’t hesitate to ask—I’m here to help!
Sources: Baseten TTS plugin guide | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | Text-to-speech (TTS) models | LiveKit Docsbroad-painter-9222
11/03/2025, 2:15 PMtall-airline-16756
11/03/2025, 2:17 PMimport asyncio
from livekit import rtc
from livekit.agents.tts import StreamAdapter
from livekit.plugins import rime
async def test_tts():
# Initialize TTS model
tts = rime.TTS(model="arcana", speaker="astra")
# Create a stream for TTS
stream = StreamAdapter(tts=tts).stream()
# Push text to simulate user input
stream.push_text("Hello, this is a test message.")
stream.push_text("This simulates user voice input.")
# Collect synthesized audio frames
audio_frames = []
async for audio in stream:
audio_frames.append(audio.frame)
# End the stream
stream.end_input()
# Use audio_frames in your tests
print(f"Generated {len(audio_frames)} audio frames.")
# Run the test
asyncio.run(test_tts())
This script gently guides you through initializing a TTS model, streaming synthesized audio, and collecting audio frames for your testing needs. Feel free to swap out the TTS provider and model to best fit your unique use case.
If you have any questions or would like more examples, just let me know—I’m here to help!
Sources: plugins/google/src/beta/gemini_tts.test.ts | Text-to-speech (TTS) models | LiveKit Docs | Node.js Agents Architecture | livekit/livekit_composite | DeepWikibroad-painter-9222
11/03/2025, 2:17 PMtall-airline-16756
11/03/2025, 2:18 PMresponse_format to "text". This way, the agent will output text that the TTS model can easily process.
2. Integrate the TTS Model: Next, bring in a standalone TTS instance (like Cartesia or ElevenLabs) into your agent session. Here’s a quick example:
from livekit.agents import AgentSession
from livekit.plugins import cartesia
tts = cartesia.TTS()
session = AgentSession(
llm=realtime_model,
tts=tts,
# Add other configurations like STT if needed
)
1. Simulate User Input: Then, push text to the TTS model to generate audio and publish it to the LiveKit room. This helps simulate user voice messages for your agent to work with.
2. Monitor and Validate: Keep an eye on metrics events (like MetricsCollected) to check latency and synchronization. If you want, you can also transcribe the audio output using Whisper or another STT model to ensure accuracy.
3. Dynamic Testing: Feel free to test multiple TTS providers by switching between them during a session. For example, you can use the handoff mechanism to hand over control to a new agent with a different TTS model.
If you’d like, I’m happy to provide a specific code example for any of these steps—just let me know!
Sources: Realtime model plugins | LiveKit Docs | plugins/rime/src/tts.test.ts | pipeline-tts/tts_comparison/README.md | Text-to-speech (TTS) models | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.pybroad-painter-9222
11/03/2025, 2:19 PMtall-airline-16756
11/03/2025, 2:20 PMcreate_mock_room() function:
from livekit.agents.ipc.mock_room import create_mock_room
from livekit.agents.voice import RoomIO
# Create a mock room
mock_room = create_mock_room()
# Initialize RoomIO with the mock room
room_io = RoomIO(
session=your_agent_session,
room=mock_room,
input_options={"audio_enabled": True}
)
# Start the RoomIO instance
await room_io.start()
1. For Integration Testing: You can connect to a real LiveKit server using test credentials. Just generate tokens with the right permissions and pass the connected room to RoomIO.
2. Customize RoomIO: Feel free to adjust input_options and output_options to control how media behaves, like enabling audio or focusing on specific participants.
If you’d like, I’m here to help with more details or examples tailored to your testing needs—just let me know!
Sources: livekit-agents/livekit/agents/ipc/mock_room.py | Community & Support | livekit/livekit_composite | DeepWiki | livekit/tests/common/e2e/mod.rs | Tests/LiveKitTestSupport/Room.swift | agents/src/voice/agent_session.tsbroad-painter-9222
11/03/2025, 2:26 PMtall-airline-16756
11/03/2025, 2:27 PMcreate_mock_room function gives you a mocked room instance with essential properties like participants and connection state. However, it doesn’t automatically simulate active interactions between agents and users, such as voice or data exchange.
To help you simulate agent-user interactions, here are a few approaches you might find useful:
• Try agent-to-agent testing, where one agent acts as a simulated user. You can configure RoomInputOptions to listen to other agents.
• Use mocking tools like FakeSTT, FakeTTS, and FakeAudioInput to simulate speech, text, and audio streams.
• For a more comprehensive approach, the LiveKit CLI offers an agent load testing tool that simulates echo participants and helps evaluate agent performance under load.
If you'd like, I’d be happy to walk you through an example of setting up agent-to-agent testing or show you how to use these tools. Just let me know!
Sources: tests/test_agent_session.py | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki | README.mdbroad-painter-9222
11/03/2025, 2:31 PMtall-airline-16756
11/03/2025, 2:32 PMRoomInputOptions so agents can listen to each other. Here’s a simple example to get you started:
from livekit.agents.voice import RoomIO
from livekit.agents.voice.room_io import RoomInputOptions
room_io = RoomIO(
session=your_agent_session,
room=ctx.room,
input_options=RoomInputOptions(
listen_to_agents=True # Enables agent-to-agent interaction
)
)
await room_io.start()
1. Develop a Test/Evaluation Agent: Try creating an agent that has predefined test scenarios along with grading logic. For instance, you can use LLM tool calls to assess responses from the target agent.
2. Use the LiveKit CLI for Load Testing: The lk perf agent-load-test command is super helpful to simulate multiple rooms and echo participants for performance checks. Here’s how you might run it:
lk perf agent-load-test \
--rooms 5 \
--agent-name test-agent \
--echo-speech-delay 10s \
--duration 5m
1. Integrate with Testing Frameworks: Don’t forget to use pytest alongside LiveKit’s built-in testing helpers. This will help you validate agent behavior, tool calls, and keep your conversation flow smooth.
If you’d like, I’m here to help with a specific example for any of these steps—just let me know!
Sources: How to test your agent using another agent | README.md | docs/index.yaml | Testing and evaluation | LiveKit Docs | README.mdbroad-painter-9222
11/03/2025, 2:54 PMtall-airline-16756
11/03/2025, 2:54 PMlivekit-cli agents console --url <livekit_url> --api-key <api_key> --api-secret <api_secret>
1. Programmatically Simulate a User: Try using the simulate_job method to create a room and connect a simulated user like this:
await worker.simulate_job(SimulateJobInfo(room="test-room", participant_identity="simulated-user"))
1. Enable Agent-to-Agent Interaction: If your simulated user is actually another agent, you’ll want to configure RoomInputOptions to listen to agent participants:
room_io = RoomIO(session, room=ctx.room,
input_options=RoomInputOptions(listen_to_agents=True))
1. Alternative: Load Testing: You can also use the LiveKit CLI’s load testing tool to simulate multiple users and agents in a room with this command:
lk perf agent-load-test \
--rooms 1 \
--agent-name test-agent \
--echo-speech-delay 10s \
--duration 5m
If you’d like, I’m here to provide more details or examples on any of these methods—just let me know!
Sources: examples/avatar_agents/bey/README.md | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki | Community & Support | livekit/livekit_composite | DeepWiki | Web and mobile frontends | LiveKit Docs | pkg/loadtester/agentloadtester.gobroad-painter-9222
11/03/2025, 2:56 PMtall-airline-16756
11/03/2025, 2:57 PMSimulateAgentWorker method from LiveKit server’s test utilities. This handy tool lets you create a simulated worker that connects to the LiveKit server and manages job availability and assignments smoothly.
2. Create a TestServer: Try instantiating a test server with NewTestServer(bus) or NewTestServerWithService(s). This sets up an environment that mimics agent-service communication, making your testing more realistic.
3. Control Job Flow: You can programmatically manage job assignments during your simulation using helper methods like Accept() or Reject() on job requests. This gives you great control over how jobs are handled.
This method is mainly designed for internal testing within the LiveKit server codebase. However, if you're looking to perform end-to-end testing in a deployed environment, the LiveKit CLI or sample applications are excellent tools to simulate participants and trigger agent dispatch.
Please feel free to reach out if you'd like more details or examples—I’m here to help you get this set up smoothly!
Sources: README.md | LiveKit CLI Setup | LiveKit Docsbroad-painter-9222
11/03/2025, 2:57 PMtall-airline-16756
11/03/2025, 2:58 PMfrom livekit.agents import Worker
from livekit.agents.api import SimulateJobInfo
async def simulate_worker():
# Initialize the worker
worker = Worker(api_key="your_api_key", api_secret="your_api_secret")
# Simulate a job by creating a room and participant
await worker.simulate_job(SimulateJobInfo(
room="test-room",
participant_identity="simulated-user"
))
# Run the simulation
import asyncio
asyncio.run(simulate_worker())
This snippet sets up a simulated worker, creates a room, and connects a participant for testing purposes. Just be sure to swap out "your_api_key" and "your_api_secret" with your own LiveKit credentials.
If you have any questions or want me to walk you through more examples, please feel free to ask—I’m here to help!
Sources: README.md | livekit-agents/livekit/agents/worker.py | README.md | Worker lifecycle | LiveKit Docs | Worker options | LiveKit Docs