Warning
This SDK is currently in development. Please do not depend on it for any production use-cases.
Elevenlabs Conversational AI Swift SDK is a framework designed to integrate ElevenLabs' powerful conversational AI capabilities into your Swift applications. Leverage advanced audio processing and seamless WebSocket communication to create interactive and intelligent conversational voivce experiences.
Note
This library is launching to primarily support Conversational AI. The support for speech synthesis and other more generic use cases is planned for the future.
Add the Elevenlabs Conversational AI Swift SDK to your project using Swift Package Manager:
- Open Your Project in Xcode
- Navigate to your project directory and open it in Xcode.
- Add Package Dependency
- Go to
File
>Add Packages...
- Go to
- Enter Repository URL
- Input the following URL:
https://github.com/elevenlabs/ElevenLabsSwift
- Input the following URL:
- Select Version
- Import the SDK
import ElevenLabsSDK
- Ensure
NSMicrophoneUsageDescription
is added to your Info.plist to explain microphone access.
-
Configure the Session Create a
SessionConfig
with either anagendId
orsignedUrl
.let config = ElevenLabsSDK.SessionConfig(agentId: "your-agent-id")
-
Define Callbacks Implement callbacks to handle various conversation events.
var callbacks = ElevenLabsSDK.Callbacks() callbacks.onConnect = { conversationId in print("Connected with ID: \(conversationId)") } callbacks.onMessage = { message, role in print("\(role.rawValue): \(message)") } callbacks.onError = { error, info in print("Error: \(error), Info: \(String(describing: info))") } callbacks.onStatusChange = { status in print("Status changed to: \(status.rawValue)") } callbacks.onModeChange = { mode in print("Mode changed to: \(mode.rawValue)") }
-
Start the Conversation Initiate the conversation session asynchronously.
Task { do { let conversation = try await ElevenLabsSDK.Conversation.startSession(config: config, callbacks: callbacks) // Use the conversation instance as needed } catch { print("Failed to start conversation: \(error)") } }
-
End Session
conversation.endSession()
-
Control Recording
conversation.startRecording() conversation.stopRecording()
Explore practical implementations and examples in our ElevenLabs Examples repository. (Coming soon)