Getting Started
Prerequisites
Before you begin, make sure you have:- A Simli account with an API key
- Python3.9 or higher
Installation
Installsimli-ai package:
Usage
Step 1: Creating the SimliClient
Create an instance of SimliClient and initialize it with your configuration:"YOUR_SIMLI_API_KEY" with your actual Simli API key, and "YOUR_FACE_ID" with the desired face ID for your application.
Step 2: Send Audio Data
Once the connection is established, you can start sending audio data:simli-ai API reference
simli.SimliConfig
This is a dataclass that represents the config sent to this endpoint to get a session_tokenfaceId: str # FaceID you can get from default avatars or create your own on the simli websitehandleSilence: bool. Specify whether you want to keep the Simli Avatar Moving when you don’t send in Audio default true. Set to false for absolute control (difficult to get response time right)maxSessionLength: int. A hard time limit (in seconds) after which the session will disconnectmaxIdleTime: int. A soft time limit (in seconds) that disconnects the session after a period of not sending in data
simli.SimliClient
-
class SimlClient(api_key: str, config: SimliConfig, simliURL: str = "https://api.simli.ai",retry_count: int = 3, retry_timeout: float = 15.0, enableSFU: bool = True, transport_mode: TransportMode = TransportMode.P2P)- SimliClient constructor
api_key: str. Your API key you get from this pageconfig: refer to SimliConfigsimliURL: str. Used if you’re setting up a proxy for Simli Backend. Not useful for mostretry_count: int = 3. How many reconnection attempts before an error is thrownretry_timeout: float. Time between retry attemptsenableSFU: bool. Only works for TransportMode.P2P. Specifies whether traffic should run through cloudflare network or nottransport_mode: TransportMode. Transport Mode. Livekit or Peer to Peer
- SimliClient constructor
-
async def start(): Initializes the SimliClient with the provided configuration and starts the WebRTC Connection -
async close(): Closes the WebRTC connection and cleans up resources. -
registerEventCallback(event: SimliEvent,async_callback: Callable[[], Awaitable[None]]). Register a callback to a SimliEvent -
async send(data: bytes | string): Sends audio data or control signals to the server. -
async sendImmediate(data: bytes): Sends audio data for immediate playback. Clears all previous audio in the buffer. -
async sendSilence(duration: float= 0.1875): Sends the specified duration to the server as silent audio, used mostly in Idle mode. -
async clearBuffer(): Clears the audio buffer, best used when you want the avatar to stop talking. -
async getNextVideoFrame(): returns the following PyAV VideoFrame. -
async getNextAudioFrame(): returns the following PyAV AudioFrame. -
async getVideoStreamIterator(targetFormat:str): Creates an async iterator that retrieves all the video frames in order. Can be used in anasync forloop.targetFormat: specify what format you want the frames to be in, defaults to RGB.
-
async getAudioStreamIterator(targetSampleRate): Creates an async iterator that retrieves all the video frames in order. Can be used in anasync forloop.targetSampleRate: int: specify the sampling rate of the output audio, specify if you want to use the audio in something else that has specific sampling rate constraints
SimliEvent
Possible signals that are sent from the server. Can be used for callbacks. You can refer to JS SDKfor an explanation of the eventsFork and Contribute to simli-client
simli-ai
Fork and contribute to the simli-client repository on GitHub or clone for your own usecase.
Troubleshooting
If you encounter issues:- Ensure your API key is correct and active.
- Verify that your face ID is valid and associated with your account.
- Check that your audio data is in the correct format (PCM16, 16KHz).
- Verify that you have the necessary permissions for accessing the user’s media devices.
- Review the console logs for any error messages or warnings.