how do I mock tts and stt in livekit testing
# ask-ai
r
how do I mock tts and stt in livekit testing
t
Thanks for reaching out, Trevor. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to mock TTS and STT in LiveKit tests — here's what you can do. Summary answer • LiveKit testing doesn't provide direct mocks for TTS/STT engines. • Test agent behavior by mocking the tools that consume or produce TTS/STT results (use
mock_tools
), and/or run tests in text-only mode so the agent receives text input instead of audio. • To verify TTS output, assert on the structured text generated by the LLM/tts nodes rather than on audio bytes. How to mock (concise examples) 1. Mock downstream tools that depend on STT:
Copy code
from livekit.agents import mock_tools

with mock_tools(Assistant, {"process_transcript": lambda text: "parsed intent"}):
    result = await session.run(user_input="...")  # use text input representing STT transcription
    await result.expect.next_event(type="message").judge(llm, intent="parsed intent")
1. Use text-only testing to bypass STT: • Feed the agent the transcript string directly as
user_input
so STT isn't involved. 1. Verify TTS behavior by inspecting LLM/tts node outputs: • Assert the generated speech text or speech directives from the pipeline (structured output), not the audio file. When you might need E2E audio • For full audio pipeline tests (actual STT/TTS engines), use third-party audio providers or run integration tests against real STT/TTS services. If you want, tell me: • Whether you need example test code for a specific tool or node setup, or • If you want an example that asserts structured TTS output vs. audio files. Sources: Testing and evaluation | LiveKit Docs | Tool definition and use | LiveKit docs