I want my mobile app voice agent to generate speec...
# ask-ai
p
I want my mobile app voice agent to generate speech when for example user completes a task. Is it possible to invoke livekit api to pass a text and the agent responds back with speech ?
t
Thanks for reaching out, mithun. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to let you know that LiveKit does support text-to-speech (TTS) functionality, which is perfect for creating speech in a mobile app voice agent. You can easily use the LiveKit API to set up a TTS model with a voice profile tailored to the tone, accent, and other speech characteristics you want. LiveKit works with a variety of TTS providers, including: • Cartesia • ElevenLabs • Inworld • Rime • OpenAI • AWS Polly • Speechify • Hume AI • Deepgram You have the flexibility to pick a voice model through LiveKit Inference or even connect directly to a broader selection of model providers using a plugin with your own account. The TTS model then takes the output from an LLM model to bring the agent’s responses to life with speech for your users. Sources: Agent speech and audio | LiveKit docs | Text-to-speech (TTS) models | LiveKit Docs | README.md | livekit-plugins/livekit-plugins-cartesia/livekit/plugins/cartesia/tts.py
p
what I am looking for is do equivalend of agent.say("good job. task completed") on-demand from the app code
t
I'd be happy to help you with this! You can easily have a LiveKit agent say a specific phrase like "good job. task completed" whenever you want, right from your app code using the
session.say()
method. This handy method lets the agent speak the text you provide by using the Text-to-Speech (TTS) plugin you have set up. Here’s a simple example to get you started:
Copy code
await self.session.say("good job. task completed")
Plus, if you want to control whether the speech can be interrupted, you can do that too:
Copy code
await self.session.say("good job. task completed", allow_interruptions=False)
Just make sure your agent session is configured with a TTS plugin, since that’s needed for the speech to work. If you have any questions or want me to walk you through the setup, feel free to ask—I’m here to help! Sources: pipeline-tts/tts_node.py | meditation_assistant/README.mdoc | Agent speech and audio | LiveKit docs
p
does it go to the session context or it can be said independendly
t
Hi there! Just a quick note: the
session.say()
method works only when there's an active session context. It’s tied to the lifecycle of an
AgentSession
, so you can use it only while the session is running. To make sure
session.say()
works smoothly, please start by initializing and starting the session. Here's a simple example:
Copy code
await session.start()
await session.say("good job. task completed")
If you're looking to use speech features outside of a session, you might want to consider a custom approach or check out other APIs. Feel free to reach out if you'd like me to explain anything further—I’m here to help! Sources: sip-refer/README.mdoc | livekit-agents/livekit/agents/voice/agent_session.py | examples/src/custom_text_handler.ts | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki
p
Can I invoke it from the mobile app that runs the livekit client
t
I understand this can be a bit tricky! The
session.say()
method isn’t something you can call directly from a mobile app using the LiveKit client. It’s actually a server-side method that’s part of the LiveKit Agents framework and needs to be used within the agent’s server logic. What your mobile app can do is join a LiveKit room as a participant. From there, the agent running on the server listens to what users say in the room and uses
session.say()
to create speech responses through TTS. If you’d like, I’m here to help you step through setting this up or answer any questions you have! Sources: Agent speech and audio | LiveKit docs | Mobile SDKs (Flutter, iOS, Android) | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/agent_session.py | examples/src/custom_text_handler.ts | basics/say_in_voice.py
p
any other approach to get this functionality ?
t
I'd love to share some alternative ways you can achieve text-to-speech (TTS) functionality triggered from your mobile app. Here are a few approaches you might find helpful: 1. Use `VoiceAgent.say()`: Your mobile app can use the LiveKit JavaScript/TypeScript SDK to directly trigger speech synthesis by calling
voiceAgent.say("Your message")
. The TTS synthesis happens server-side, but the trigger comes right from your app. 2. Standalone TTS Stream: Your app can send text input to the server (for example, via WebSocket or data publishing). Then, the server-side agent uses a TTS plugin to generate audio, which streams back to your app or to room participants. 3. Real-Time Text Streaming: You can send incremental text (like word-by-word) from your app to the server. The agent processes this input using a streaming TTS engine (such as ElevenLabs) for quick, low-latency speech synthesis. 4. Local Playback Control: Your app receives the synthesized audio from the server and handles playback using LiveKit's client SDKs. This gives you the flexibility to build custom UI controls and create a great user experience. All these options rely on server-side TTS synthesis, but the exciting part is that your mobile app stays in control of when and how the speech happens. If you'd like, I'm here to help you dive into any specific implementation or answer any questions you have! Sources: examples/other/text-to-speech/README.md | Speechify TTS plugin guide | LiveKit Docs | agents/src/voice/agent_activity.ts | Text-to-speech (TTS) models | LiveKit Docs