abundant-father-33863
08/21/2025, 11:30 AMtall-airline-16756
08/21/2025, 11:30 AMtall-airline-16756
08/21/2025, 11:31 AMbefore_tts_cb Callback: This is the easiest way! Just add a callback to tweak the text before it goes to the TTS engine—perfect for simple text changes.
• Overriding the llm_node Method: If you want more control, create your own agent class and override this method to catch and modify the LLM output before it hits TTS.
• Overriding the tts_node Method: For even more advanced control, you can intercept text right at the TTS level to shape how the speech sounds.
• Using Structured Output: This lets you separate TTS instructions from the actual response, giving you cool options to adjust tone, emotion, and intonation.
If you'd like, I’m happy to walk you through the detailed steps for any of these—just let me know!
Sources: livekit-agents/livekit/agents/voice/generation.py | Pipeline nodes and hooks | LiveKit Docs | chain-of-thought-tts/README.mdoc | pipeline-tts/tts_node.pyabundant-father-33863
08/21/2025, 11:33 AMtall-airline-16756
08/21/2025, 11:35 AMparticipant parameter in the RoomIO constructor.
• Publishing Audio "On Behalf Of" a Participant: Try using the ATTRIBUTE_PUBLISH_ON_BEHALF attribute to show that the audio is being published for a specific participant.
• Subscription Control: Although TTS audio goes out to the whole room, you can still configure the agent to respond only to certain participants.
If you'd like, I can walk you through the detailed steps for any of these options—just let me know!
Sources: plugins/neuphonic/src/tts.ts | Voice Assistants | livekit/livekit_composite | DeepWiki | Text-to-speech (TTS) integrations | LiveKit Docs | examples/other/text-to-speech/cartesia_tts.py | How to set a fixed participant for agent audio processingabundant-father-33863
08/21/2025, 11:39 AMtall-airline-16756
08/21/2025, 11:39 AMawait ctx.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_NONE)
This makes sure you connect to the room without automatically subscribing to all tracks, giving you more control.
2. Set Up TTS:
Start by initializing the TTS engine with the model and voice you want:
tts = openai.TTS(model="tts-1", voice="nova")
3. Create an Audio Source and Track:
Next, set up an audio source and create a local audio track like this:
source = rtc.AudioSource(tts.sample_rate, tts.num_channels)
track = rtc.LocalAudioTrack.create_audio_track("agent-mic", source)
4. Configure Publish Options:
Set the track source to SOURCE_MICROPHONE so it’s clear where the audio is coming from:
options = rtc.TrackPublishOptions()
options.source = rtc.TrackSource.SOURCE_MICROPHONE
5. Set Target Participant:
Here’s a key step — use the ATTRIBUTE_PUBLISH_ON_BEHALF attribute to specify exactly who should receive the audio:
ctx.room.local_participant.set_attributes({
ATTRIBUTE_PUBLISH_ON_BEHALF: "target-user-identity"
})
6. Publish the Track:
Now, publish the audio track to the room:
publication = await ctx.room.local_participant.publish_track(track, options)
await publication.wait_for_subscription()
7. Synthesize and Publish Audio:
Finally, generate the TTS audio and send it to the audio source like this:
text = "Hello, this message is for you!"
async for output in tts.synthesize(text):
await source.capture_frame(output.frame)
If anything’s unclear or you’d like a hand with implementation, just let me know — I’m here to help!abundant-father-33863
08/21/2025, 11:54 AMtall-airline-16756
08/21/2025, 11:57 AM