Swift SDK
Conversational AI SDK: deploy customized, interactive voice agents in your Swift applications.
Also see the Conversational AI overview
Installation
Add the ElevenLabs Swift SDK to your project using Swift Package Manager:
Add the Package Dependency
- Open your project in Xcode
- Go to
File
>Add Packages...
- Enter the repository URL:
https://github.com/elevenlabs/ElevenLabsSwift
- Select your desired version
Import the SDK
Ensure you add NSMicrophoneUsageDescription
to your Info.plist to explain
microphone access to users.
Usage
This library is primarily designed for Conversational AI integration in Swift applications. Please use an alternative dependency for other features, such as speech synthesis.
Initialize Conversation
First, create a session configuration and set up the necessary callbacks:
Session Configuration
There are two ways to initialize a session:
You can obtain an Agent ID through the ElevenLabs UI:
Starting the Conversation
Initialize the conversation session asynchronously:
Audio Sample Rates
The ElevenLabs SDK currently uses a default input sample rate of 16,000 Hz
. However, the output sample rate is configurable based on the agent’s settings. Ensure that the output sample rate aligns with your specific application’s audio requirements for smooth interaction.
The SDK does not currently support ulaw format for audio encoding. For compatibility, consider using alternative formats.
Managing the Session
Example Implementation
For a full, working example, check out the example application on GitHub.
Here’s an example SwiftUI view implementing the conversation interface:
This SDK is currently experimental and under active development. While it’s stable enough for testing and development, it’s not recommended for production use yet.