can we have at the same time a Realtime model and ...
# ask-ai
a
can we have at the same time a Realtime model and a STT node for cases we want to specifically say a text?
t
Thanks for reaching out, Sebastián. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can use a Realtime model and a Speech-to-Text (STT) node together in LiveKit! This is a great approach when you want real-time transcription alongside the powerful speech understanding capabilities of a Realtime model. Here’s how you can set it up: • Configure the Realtime model as your LLM component. • Add a separate STT plugin to handle transcription. For example:
Copy code
agent = VoiceAgent(
    instructions="You are a helpful assistant",
    llm=RealtimeModel(model="gpt-4o-realtime"),
    stt=DeepgramSTT(model="nova-2"),
    vad=SileroVAD(),
    tts=CartesiaTTS(voice="sonic-2"),
)
This way, your Realtime model can focus on understanding and generating speech, while the STT plugin takes care of the transcription in real time. If you have any questions or want me to walk you through the setup, just let me know—I’m here to help! Sources: Realtime model plugins | LiveKit Docs | livekit-agents/livekit/agents/llm/realtime.py | Turn detection and interruptions | LiveKit Docs | complex-agents/nutrition-assistant/README.md
a
no i only want the the TTS for generating audio responses from a specific text since i cannot use session.say with Realtime models
t
To help you generate audio responses from specific text while using Realtime models, a great approach is to configure the Realtime model to work in text-only response mode and then connect a separate TTS (Text-to-Speech) instance for audio synthesis. This way, you can work around the limitation of not being able to use
session.say
with Realtime models. Here’s a simple way to set it up: 1. Set the Realtime model to text-only mode by specifying
modalities=["text"]
. 2. Integrate a TTS provider to generate the audio responses. Some popular options include Cartesia, ElevenLabs, Rime, and others. Here’s an example configuration you can try:
Copy code
agent = VoiceAgent(
    instructions="You are a helpful assistant",
    llm=RealtimeModel(modalities=["text"], model="gpt-4o-realtime"),
    tts=CartesiaTTS(voice="sonic-2"),
)
This setup lets the Realtime model focus on crafting the text responses, while the TTS engine takes care of turning those into audio. If you have any questions or need a hand with this setup, just let me know—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Realtime model plugins | LiveKit Docs | OpenAI Realtime API plugin guide | LiveKit Docs | Azure OpenAI Realtime API and LiveKit | LiveKit Docs | Text-to-speech (TTS) models | LiveKit Docs
a
but if i want to use TTS only for specific tasks and then Realtime for all other cases?
t
I'm glad you're exploring how to use TTS alongside Realtime models! To help you set up a system that smoothly switches between the two depending on the task, here’s a friendly guide: 1. Automatic Fallback: You can configure the Realtime model with a TTS instance so that whenever the Realtime model provides text responses instead of audio, the system automatically uses TTS. This keeps things running seamlessly. 2. Task-Specific TTS: It’s helpful to implement a function or tool within your agent that triggers TTS for certain tasks. For example:
Copy code
class HybridAgent(Agent):
    async def specific_task_function(self, task_type: str):
        return f"Handling {task_type} with controlled TTS output."
1. Multi-Agent Handoff: If you want even more precise control, you can create separate agents—one dedicated to TTS-specific tasks and another for general Realtime tasks—and switch between them dynamically using agent handoffs. This approach helps you enjoy the best of both worlds, integrating TTS exactly where you need it while keeping the Realtime model’s strengths for everything else. If you’d like, I’m here to provide more details or examples to make this even clearer! Sources: examples/voice_agents/realtime_turn_detector.py | README.md | Realtime model plugins | LiveKit Docs