Skip to main content

LiveKit Agents Plugin for Resemble AI

Project description

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:

  1. Preferred method: Use the async context manager pattern (async with TTS(...) as tts:)
  2. If managing manually, always call await tts.aclose() in a finally block
  3. If you prefer to provide your own HTTP session, you can pass it using the http_session parameter:
import aiohttp

async def with_custom_session():
    async with aiohttp.ClientSession() as session:
        async with TTS(
            api_key="your_api_key",
            voice_uuid="your_voice_uuid",
            http_session=session
        ) as tts:
            # Use TTS...
            # No need to manually close anything - context managers handle it all

Implementation Details

This plugin uses two different approaches to generate speech:

  1. One-off Synthesis - Uses Resemble's REST API for simple text-to-speech conversion
  2. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

livekit_plugins_resemble-1.1.7.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

livekit_plugins_resemble-1.1.7-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file livekit_plugins_resemble-1.1.7.tar.gz.

File metadata

File hashes

Hashes for livekit_plugins_resemble-1.1.7.tar.gz
Algorithm Hash digest
SHA256 edd64bd121a4ec199cc52046553ffa6e63fb8b9dfa182285495847b8581893f2
MD5 4ff8476d1a831dd61009507672bbca8e
BLAKE2b-256 b2d3b832d37f86c83cd7087dc8ee585bae6968bbaa233b9833e12ac55f9795a9

See more details on using hashes here.

File details

Details for the file livekit_plugins_resemble-1.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for livekit_plugins_resemble-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1326a543520e6cd09b6aec180587e1f162301515ed1f3f5cd5663735112d533d
MD5 a53c0cd9e5a7fee7d0398c3c104f9e20
BLAKE2b-256 738f9bd6e6814e2b5fa57e6bf128c6db4ce0b2274a53037f7c4036fefe4e7138

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page