busy-monitor-72069
09/14/2025, 2:30 AMtall-airline-16756
09/14/2025, 2:30 AMtall-airline-16756
09/14/2025, 2:31 AMbusy-monitor-72069
09/14/2025, 2:32 AMtall-airline-16756
09/14/2025, 2:32 AMbusy-monitor-72069
09/14/2025, 2:33 AMtall-airline-16756
09/14/2025, 2:33 AMfrom livekit.plugins import openai
# Initialize GPT-4 streaming
llm = openai.LLM(model="gpt-4o")
# Process GPT-4 output in chunks
async for chunk in llm.chat(stream=chat_context):
text_chunk = chunk.text
# Send text chunk to TTS
tts_stream.push_text(text_chunk)
2. Integrate with ElevenLabs TTS: from livekit.plugins import elevenlabs
# Initialize ElevenLabs TTS
tts = elevenlabs.TTS(
voice_id="your_voice_id",
model="eleven_multilingual_v2"
)
# Start TTS streaming
tts_stream = tts.stream()
3. Real-Time Audio Playback: import asyncio
from livekit import rtc
# Set up audio source
source = rtc.AudioSource(tts.sample_rate, tts.num_channels)
track = rtc.LocalAudioTrack.create_audio_track("tts-audio", source)
# Queue for audio frames
audio_queue = asyncio.Queue()
async def play_audio():
while True:
frame = await audio_queue.get()
if frame is None:
break
source.capture_frame(frame)
# Process TTS audio frames
async def process_tts():
async for audio_frame in tts_stream:
await audio_queue.put(audio_frame)
await audio_queue.put(None)
# Run playback and TTS processing concurrently
asyncio.run(asyncio.gather(play_audio(), process_tts()))
I hope this example helps clarify the process of streaming GPT-4 output, sending it to ElevenLabs TTS, and playing the audio in real time. If you have any questions or need a hand with any part, please don’t hesitate to ask—I’m here to help!busy-monitor-72069
09/14/2025, 6:21 AMtall-airline-16756
09/14/2025, 6:21 AMgpt-4o-mini-tts
, for voice generation.
• LiveKit.fm Demo: This demo shows how to interact with OpenAI's gpt-4o-mini-tts
model in action.
These should give you a solid foundation to validate your integration steps and understand how OpenAI and ElevenLabs work together within LiveKit. If you have any questions or need a hand with anything else, please feel free to reach out—I’m here to help!
Sources: pipeline-tts/elevenlabs_tts.py | test/agents/host.py | ElevenLabs TTS integration guide | LiveKit Docs | OpenAI TTS integration guide | LiveKit Docs