How can I send a request for TTS without adding it...
# ask-ai
a
How can I send a request for TTS without adding it to context
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can send a TTS request in LiveKit without adding it to context by using the
session.say()
method with the
add_to_chat_ctx
parameter set to `False`:
Copy code
await session.say(
    "Your text here",
    add_to_chat_ctx=False,
    allow_interruptions=True,
)
This ensures the spoken text isn't added to the chat or application context. Alternatively, you can use a standalone TTS instance directly for even more control, bypassing session context entirely. This approach involves creating a TTS plugin instance and managing audio frames yourself. If you need details about configuring a standalone TTS or require sample code, let me know. Sources: Agent speech | LiveKit Docs | Text-to-speech (TTS) integrations | LiveKit Docs
a
give me the examlpe of second one
t
Hey there! Let me walk you through a super cool way to use LiveKit's TTS in standalone mode. It's like having complete control over your audio magic, without any extra baggage. 😊
Copy code
from livekit import rtc
from livekit.agents.tts import SynthesizedAudio
from livekit.plugins import elevenlabs

# Create a TTS instance using the ElevenLabs plugin (adjust model as needed)
tts = elevenlabs.TTS(model_id="eleven_turbo_v2")
tts_stream = tts.stream()

audio_source = rtc.AudioSource(44100, 1)
track = rtc.LocalAudioTrack.create_audio_track("agent-audio", audio_source)
await ctx.room.local_participant.publish_track(track)

tts_stream.push_text("Your text here")
tts_stream.end_input()

async for synthesized_audio in tts_stream:
    await audio_source.capture_frame(synthesized_audio.frame)
• tts = elevenlabs.TTS(...): Feel free to swap this out with your favorite TTS provider and model. • tts_stream.push_text(...): Just drop in the text you want to turn into audio. • audio_source.capture_frame(...): This nifty bit processes each audio frame directly. • No worries about messing with the agent session context! The best part? You can totally customize the plugin, model, and audio source to fit exactly what you need. It's like audio tailoring! 🎧