Xybrid
SDKs

iOS / macOS

Native Swift SDK for on-device ML inference

The Swift SDK provides native bindings to the Xybrid runtime via UniFFI for iOS and macOS applications.

The Swift SDK is in early access. The API is stable but the package is not yet published as a release. Install via Swift Package Manager from source, or use the Flutter SDK for cross-platform development.

Installation

Add the Xybrid package via Swift Package Manager:

Package.swift
dependencies: [
    .package(url: "https://github.com/xybrid-ai/xybrid", from: "0.1.0")
]

Or in Xcode: File > Add Package Dependencies and enter the repository URL.

Supported platforms: iOS 13.0+, macOS 10.15+

Quick Start

import Xybrid

// Load a model from the registry
let loader = ModelLoader.fromRegistry(modelId: "kokoro-82m")
let model = try loader.load()

// Run inference
let envelope = Envelope.text("Hello, world!")
let result = try model.run(envelope: envelope)

if result.success {
    print("Output: \(result.text ?? "")")
    print("Latency: \(result.latency)s")
}

Model Loading

From Registry

let loader = ModelLoader.fromRegistry(modelId: "whisper-tiny")
let model = try loader.load()

From Local Bundle

let loader = ModelLoader.fromBundle(path: bundlePath)
let model = try loader.load()

Input Envelopes

Audio (Speech Recognition)

let envelope = Envelope.audio(pcmData: audioData, sampleRate: 16000, channels: 1)
let result = try model.run(envelope: envelope)
print("Transcription: \(result.text ?? "")")

Text (Text-to-Speech)

// Simple text
let envelope = Envelope.text("Hello, how are you?")

// With voice and speed
let envelope = Envelope.text("Hello", voice: "af_heart", speed: 1.0)

let result = try model.run(envelope: envelope)
if let audioBytes = result.audioBytes {
    // Play or save audio
}

Embedding

let envelope = Envelope.embedding(data: [0.1, 0.2, 0.3])
let result = try model.run(envelope: envelope)
if let vector = result.embedding {
    // Process embedding vector
}

Result Handling

let result = try model.run(envelope: envelope)

if result.success {
    switch result.outputType {
    case "text":
        print("Text: \(result.text!)")
    case "audio":
        playAudio(result.audioBytes!)
    case "embedding":
        process(result.embedding!)
    default:
        break
    }
    print("Latency: \(result.latency)s")  // TimeInterval in seconds
} else {
    print("Error: \(result.error ?? "Unknown")")
}

XybridResult Properties

PropertyTypeDescription
successBoolWhether inference succeeded
errorString?Error message if failed
outputTypeString"text", "audio", or "embedding"
textString?Text output (ASR, LLM)
audioBytesData?Audio output (TTS)
embedding[Float]?Embedding vector
latencyMsUInt32Inference latency in ms
isFailureBoolConvenience: !success
latencyTimeIntervalLatency in seconds

Error Handling

The SDK uses a Swift error enum for type-safe error handling:

do {
    let model = try ModelLoader.fromRegistry(modelId: "kokoro-82m").load()
    let result = try model.run(envelope: envelope)
} catch XybridError.ModelNotFound(let modelId) {
    print("Model not found: \(modelId)")
} catch XybridError.InferenceFailed(let message) {
    print("Inference failed: \(message)")
} catch XybridError.InvalidInput(let message) {
    print("Invalid input: \(message)")
} catch XybridError.IoError(let message) {
    print("I/O error: \(message)")
} catch {
    print("Unexpected error: \(error.localizedDescription)")
}

Type Aliases

The SDK provides short aliases for convenience:

AliasFull Type
ModelLoaderXybridModelLoader
ModelXybridModel
EnvelopeXybridEnvelope
ResultXybridResult

Platform Support

PlatformStatusAccelerators
iOSSupportedMetal, CoreML, ANE
macOS (Apple Silicon)SupportedMetal, CoreML, ANE
macOS (Intel)SupportedCPU

On this page