mirror of
https://github.com/livekit/agents.git
synced 2026-12-06 03:38:32 +00:00
Run realtime DST scenarios through production provider bookkeeping, with asynchronous transcription, provider failures, response correlation and cross-provider history coverage. Ignore unknown provider messages and settle pending operations when streams or host tasks disappear. Make job phases own their operations, preserve token restrictions on refresh, validate inference options and contain failures at external boundaries. Remove the duplicate Rust media benchmark. Compare recordings against independent speaker PCM and keep transcripts, provider spans and reports on the session audio clock across wall-clock corrections. Preserve silence duration in Gladia energy filtering. Add regression tests and document the provider and recording audit findings, including the remaining backend waveform issue and two independently reproduced baseline storage DST failures.
Resemble plugin for LiveKit Agents
Support for voice synthesis with the Resemble AI API, using both their REST API and WebSocket streaming interface.
See https://docs.livekit.io/agents/integrations/tts/resemble/ for more information.
Installation
pip install livekit-plugins-resemble
Pre-requisites
You'll need an API key from Resemble AI. It can be set as an environment variable: RESEMBLE_API_KEY
Additionally, you'll need the voice UUID from your Resemble AI account.
Examples
Recommended
import asyncio
from livekit.plugins.resemble import TTS
async def run_tts_example():
# Use TTS with async context manager for automatic resource cleanup
async with TTS(
api_key="your_api_key", # or set RESEMBLE_API_KEY environment variable
voice_uuid="your_voice_uuid",
# Optional parameters
sample_rate=44100, # Sample rate in Hz (default: 44100)
precision="PCM_16", # Audio precision (PCM_32, PCM_24, PCM_16, MULAW)
output_format="wav", # Output format (wav or mp3)
) as tts:
# One-off synthesis (uses REST API)
audio_stream = tts.synthesize("Hello, world!")
# Process chunks as they arrive
async for chunk in audio_stream:
# Audio data is in the 'frame.data' attribute of SynthesizedAudio objects
audio_data = chunk.frame.data
print(f"Received chunk: {len(audio_data)} bytes")
# Alternative: collect all audio at once into a single AudioFrame
audio_stream = tts.synthesize("Another example sentence.")
audio_frame = await audio_stream.collect()
print(f"Collected complete audio: {len(audio_frame.data)} bytes")
# Real-time streaming synthesis (uses WebSocket API)
# Only available for Business plan users in Resemble AI
stream = tts.stream()
await stream.synthesize_text("Hello, world!")
# Run the example
asyncio.run(run_tts_example())
Alternative: Manual Resource Management
If you prefer to manage resources manually, make sure to properly clean up:
import asyncio
from livekit.plugins.resemble import TTS
async def run_tts_example():
# Initialize TTS with your credentials
tts = TTS(
api_key="your_api_key",
voice_uuid="your_voice_uuid",
)
try:
# TTS operations
audio_stream = tts.synthesize("Hello, world!")
async for chunk in audio_stream:
# Access audio data correctly
process_audio(chunk.frame.data)
finally:
# Always clean up resources when done
await tts.aclose()
# Run the example
asyncio.run(run_tts_example())
Resource Management
When using this plugin outside of the LiveKit agent framework, it's important to properly manage the TTS instance lifecycle:
- Preferred method: Use the async context manager pattern (
async with TTS(...) as tts:) - If managing manually, always call
await tts.aclose()in a finally block - If you prefer to provide your own HTTP session, you can pass it using the
http_sessionparameter:
from livekit.agents import http
async def with_custom_session():
session = http.HttpSession()
try:
async with TTS(
api_key="your_api_key",
voice_uuid="your_voice_uuid",
http_session=session
) as tts:
# Use TTS...
finally:
await session.aclose()
Implementation Details
This plugin uses two different approaches to generate speech:
- One-off Synthesis - Uses Resemble's REST API for simple text-to-speech conversion
- Streaming Synthesis - Uses Resemble's WebSocket API for real-time streaming synthesis
The WebSocket streaming API is only available for Resemble AI Business plan users.