l
hi
t
Thanks for reaching out, Pavan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi — how can I help you today? Tell me what you're trying to do (e.g., SDK/platform, room or participant issues, API keys, billing, or an error message) and any relevant details like project ID, room ID, SDK/language, and screenshots or logs if available.
l
can i change the session tts config after the agent initient and start apeaking
t
Yes — you can change the session TTS configuration after the agent is initialized and speaking. Changes apply on the next utterance. If you're using the Hume plugin, for example, call:
Copy code
session.tts.update_options(
  voice=hume.VoiceByName(name="Colton Rivers", provider=hume.VoiceProvider.hume),
  description="Calm, serene voice",
  speed=2,
)
This updates the TTS settings and they'll take effect for subsequent speech. If you tell me which TTS provider or SDK/language you're using, I can give the exact code snippet for that environment. Sources: Hume TTS plugin guide | LiveKit Docs | ElevenLabs TTS plugin guide | LiveKit Docs
l
i need this for sarvam tts
t
Yes — you can change Sarvam TTS settings after the agent is initialized. Changes take effect on the next utterance, but Sarvam does not support an
update_options
call; instead you override the agent's
tts_node
so a new
sarvam.TTS
instance is created per utterance using current settings. If this fits, try this pattern: 1. Store TTS parameters (e.g.,
speaker
,
target_language_code
,
pace
) as instance variables on your Agent. 2. Provide a tool/method to update those variables at runtime. 3. Override
tts_node
to instantiate
sarvam.TTS(...)
with the current variables and delegate to
Agent.default.tts_node
. Example (Python):
Copy code
from livekit import agents
from livekit.plugins import sarvam
from typing import AsyncIterable

class MyAgent(agents.Agent):
    def __init__(self):
        super().__init__(instructions="You are a helpful assistant.")
        self.speaker = "anushka"
        self.target_language_code = "hi-IN"

    @agents.function_tool()
    async def change_voice(self, speaker: str, language: str):
        self.speaker = speaker
        self.target_language_code = language
        return f"Voice changed to {speaker} ({language})."

    async def tts_node(self, text: AsyncIterable[str], model_settings: agents.ModelSettings) -> AsyncIterable:
        dynamic_tts = sarvam.TTS(
            target_language_code=self.target_language_code,
            speaker=self.speaker,
            # add other dynamic params like pace, pitch if needed
        )
        return agents.Agent.default.tts_node(self, text, model_settings, tts=dynamic_tts)
Would you like a version of this for a specific SDK/language or help adding parameters like
pace
or
pitch
? Sources: Agent speech and audio | LiveKit docs
l
config = language_configs.get(language_code) new_tts = get_tts(assistant, language=config["tts_language"], voice=config["tts_voice"])
t
You're on the right track — instead of creating a new TTS instance with
get_tts(...)
, call
update_options
on the existing Sarvam TTS instance so the change applies to the next utterance. Example pattern:
Copy code
config = language_configs.get(language_code)

# If `session.tts` is your Sarvam TTS instance:
session.tts.update_options(
    target_language_code=config["tts_language"],
    speaker=config["tts_voice"],
    # optional: pace=config.get("pace"), pitch=config.get("pitch"), loudness=...
)
If you need help wiring this into your agent/session: • Tell me where the current TTS instance lives (e.g.,
session.tts
,
agent.tts
, or created in
tts_node
). • Or share
get_tts(...)
implementation and I’ll show exactly where to call
update_options
. Sources: Sarvam TTS plugin guide | LiveKit Docs
l
def get_tts(assistant: 'Assistant', language: str = None, voice: str = None): """Factory function to get the configured TTS instance.""" # provider = assistant.voice_provider # language = assistant.language["code"] # voice = assistant.voice_id # model = assistant.tts_model() provider = "sarvam" language = language or "en-IN" # Use provided language or default voice = "anushka" model = "bulbul:v2" return sarvam.TTS( api_key=assistant.sarvam_api_key or settings.SARVAM_API_KEY, model= model or "bulbul:v2", speaker=voice or "karun", target_language_code=language or "en-IN", enable_preprocessing=True, speech_sample_rate=22050, )
t
Thanks — I reviewed your
get_tts
factory. You can use it, but the simplest, supported approach is to update the existing Sarvam TTS instance with
update_options
so changes apply on the next utterance rather than replacing the object mid-stream. Two concise options: 1) Update the existing TTS instance (recommended) • Keep one Sarvam TTS instance on the session/agent (e.g.,
session.tts
). • When you need new language/voice, call:
Copy code
config = language_configs.get(language_code)
session.tts.update_options(
    target_language_code=config["tts_language"],
    speaker=config["tts_voice"],
    # optional: pace=config.get("pace"), pitch=config.get("pitch"), loudness=...
)
This applies on the next utterance. If speech is currently playing, wait for playout or let it finish before speaking again. 2) Replace the TTS instance (if you prefer factory use) • Create a new instance with
get_tts(...)
and assign it to the session/agent:
Copy code
config = language_configs.get(language_code)
new_tts = get_tts(assistant, language=config["tts_language"], voice=config["tts_voice"])
session.tts = new_tts
This also takes effect for future utterances. Use this only if you must reconstruct the object (e.g., different API key or model settings). Which do you want help wiring into your agent: calling
update_options
on
session.tts
, or replacing
session.tts
using
get_tts(...)
?
l
123223.622 ERROR asyncio Task exception was never retrieved future: <Task finished name='Task-47' coro=<entrypoint.<locals>.switch_lan… done, defined at C:\Codeshastra_Projects\hamariai-hea… exception=AttributeError("property 'tts' of 'AgentSession' object has no setter")> Traceback (most recent call last): File "C:\Codeshastra_Projects\hamariai-he… line 646, in switch_language session.tts = new_tts ^^^^^^^^^^^ AttributeError: property 'tts' of 'AgentSession' object has no setter {"pid": 8916, "job_id": "AJ_GUJoLdfsRpto", "room_id": "RM_xL3wh9SXB77x"} Traceback (most recent call last): File "C:\Codeshastra_Projects\hamariai-health\api\services\agent-runner\main.py", line 646, in switch_language session.tts = new_tts ^^^^^^^^^^^ AttributeError: property 'tts' of 'AgentSession' object has no setter
t
You're seeing that AttributeError because
AgentSession.tts
is a read-only property — you can't assign a new TTS instance to
session.tts
. What to do instead (recommended) • Call
update_options
on the existing Sarvam TTS instance so changes apply on the next utterance. Example:
Copy code
config = language_configs.get(language_code)
# update existing tts instance
session.tts.update_options(
    target_language_code=config["tts_language"],
    speaker=config["tts_voice"],
    pace=config.get("pace"),
    pitch=config.get("pitch"),
)
If you need to let current speech finish first, await the playout before updating:
Copy code
await ctx.wait_for_playout()
session.tts.update_options(...)
await ctx.agent.say("Now speaking in the new voice.")
If you prefer replacing the instance (not recommended because
session.tts
is read-only), override
tts_node
on your Agent to construct a new
sarvam.TTS
per utterance (example I shared earlier). Tell me which approach you want and where your current TTS instance is created (in session init or
tts_node
) and I’ll give the exact code to plug in.