Swift SDK for the Outspeed Live API that enables real-time voice conversations using WebRTC.
- Real-time voice conversations with AI
- Support for both Outspeed and OpenAI providers
- WebRTC-based audio streaming
- Customizable voice and model selection
-
Open Your Project in Xcode
-
Go to
File
>Add Packages...
-
Enter Repository URL in the Search Bar:
https://github.com/outspeed-ai/OutspeedSwift
-
Import the SDK
import OutspeedSDK
Important
Ensure NSMicrophoneUsageDescription
is added to your Info.plist to explain microphone access.
- iOS 15.2 or later
- Swift 6.1+
import OutspeedSDK
// Create a session configuration
let config = OutspeedSDK.SessionConfig()
// Create callbacks to handle events
let callbacks = OutspeedSDK.Callbacks()
callbacks.onMessage = { message, role in
print("Received message from \(role.rawValue): \(message)")
}
callbacks.onError = { message, error in
print("Error: \(message)")
}
callbacks.onStatusChange = { status in
print("Status changed to: \(status.rawValue)")
}
// Start the conversation
Task {
do {
let conversation = try await OutspeedSDK.Conversation.startSession(
config: config,
callbacks: callbacks
apiKey: "<YOUR_OUTSPEED_API_KEY>"
)
// When done with the conversation
conversation.endSession()
} catch {
print("Failed to start conversation: \(error)")
}
}
OutspeedSDK is fully compatible with Elevenlabs Swift SDK specifications, but registering tools is not supported yet.
To switch from ElevenLabsSDK:
-
Replace all occurrences of "ElevenLabsSDK" with "OutspeedSDK". So for example:
import ElevenLabsSDK let config = ElevenLabsSDK.SessionConfig(agentId: "testagent")
becomes
import OutspeedSDK let config = OutspeedSDK.SessionConfig(agentId: "testagent") // you can even skip agentId
-
Add your Outspeed API key to
startSession
:let conversation = try await ElevenLabsSDK.Conversation.startSession( config: config, callbacks: callbacks )
becomes
let conversation = try await OutspeedSDK.Conversation.startSession( config: config, callbacks: callbacks apiKey: "<YOUR_OUTSPEED_API_KEY>" // required )
-
AgentConfig: Customize the AI's behavior and initial response
prompt
: System instructions that define the AI's personality and behaviorfirstMessage
: Optional initial message the AI will speak when the conversation starts
-
TTSConfig: Configure voice settings
voiceId
: Select from available voices (e.g.,OutspeedSDK.Voice.david.rawValue
)
Note
All configuration objects (AgentConfig
, TTSConfig
, and ConversationConfigOverride
) are fully compatible with ElevenLabs SDK specifications.
System Prompt:
let agentConfig = OutspeedSDK.AgentConfig(
prompt: "You are a helpful assistant with a witty personality."
)
let config = OutspeedSDK.SessionConfig(
overrides: OutspeedSDK.ConversationConfigOverride(agent: agentConfig)
)
First Message:
let agentConfig = OutspeedSDK.AgentConfig(
firstMessage: "Hey there, how can I help you with Outspeed today?"
)
let config = OutspeedSDK.SessionConfig(
overrides: OutspeedSDK.ConversationConfigOverride(agent: agentConfig)
)
Voice Selection:
let ttsConfig = OutspeedSDK.TTSConfig(voiceId: OutspeedSDK.Voice.david.rawValue)
let config = OutspeedSDK.SessionConfig(
overrides: OutspeedSDK.ConversationConfigOverride(tts: ttsConfig)
)
Example snippet to customize the AI's behavior, initial message, and voice together using configuration objects:
// Configure the AI agent's behavior and initial message (ElevenLabs compatible)
let agentConfig = OutspeedSDK.AgentConfig(
prompt: "You are a helpful assistant with a witty personality.",
firstMessage: "Hey there, how can I help you with Outspeed today?"
)
// Configure voice selection (also ElevenLabs compatible)
let ttsConfig = OutspeedSDK.TTSConfig(voiceId: OutspeedSDK.Voice.david.rawValue)
// Create session configuration with overrides
let config = OutspeedSDK.SessionConfig(
overrides: OutspeedSDK.ConversationConfigOverride(
agent: agentConfig,
tts: ttsConfig
)
)
// Set up callbacks
var callbacks = OutspeedSDK.Callbacks()
callbacks.onMessage = { message, role in
print("Received message from \(role.rawValue): \(message)")
}
callbacks.onError = { message, error in
print("Error: \(message)")
}
callbacks.onStatusChange = { status in
print("Status changed to: \(status.rawValue)")
}
// Start the conversation with custom configuration
Task {
do {
let conversation = try await OutspeedSDK.Conversation.startSession(
config: config,
callbacks: callbacks,
apiKey: "<YOUR_OUTSPEED_API_KEY>",
)
} catch {
print("Failed to start conversation: \(error)")
}
}
You can find examples of the SDK here: https://github.com/outspeed-ai/outspeed-swift-examples