simli-ai python SDK
Simli SDK is a powerful tool for integrating real-time audio and video streaming capabilities into your python applications using WebRTC. You can use this SDK to display a Simli outside the browser, save the stream into a file, or integrate your stream in your program however you want!
Getting Started
Prerequisites
Before you begin, make sure you have:
- A Simli account with an API key
- Python3.9 or higher
Installation
Install simli-ai
package:
Usage
Step 1: Creating the SimliClient
Create an instance of SimliClient and initialize it with your configuration:
Make sure to replace "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:
Ensure that your audio data is in PCM16 format with a 16KHz sample rate.
simli-ai API reference
simli.SimliConfig
This is a dataclass that represents the config sent to [https://api.simli.ai/startAudioVideoSession] to get a session_token
apiKey
: str. Your API key you get from [https://app.simli.com/profile]faceId
: str # FaceID you can get from [https://docs.simli.com/api-reference/available-faces] or create your own on [https://app.simli.com]syncAudio
: bool. Specify whether your want to receive the audio back (Leave true if unsure)handleSilence
: bool. Specify whether you want to keep the Simli Avatar Moving when you don’t send in AudiomaxSessionLength
: 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(config: SimliConfig, useTurnServer: bool = False, latencyInterval: int = 60)
- SimliClient constructor
- config: refer to SimliConfig
- useTurnServer: When set to True, it uses a Turn server to connect to Simli API, useful if behing a NATed firewall or using mobile data. Turn on if you’re having connectivity issues
- latencyInterval: delay (in seconds) between ping calls to calculate latency between your machine and simli server. Set to 0 to disable.
- SimliClient constructor
async def Initialize()
: Initializes the SimliClient with the provided configuration and starts the WebRTC Connectionasync close()
: Closes the WebRTC connection and cleans up resources.async send(data: bytes | string)
: Sends audio data or control signals to the server.async sedSilence(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 for
loop.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 for
loop.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
Fork 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.
Reach out to our support team for further assistance on Discord.