Skip to main content

Overview

The Synheart Emotion Swift SDK provides real-time emotion inference from biosignals for native iOS, macOS, and watchOS applications.

Installation

Swift Package Manager

Add to Package.swift:
dependencies: [
    .package(url: "https://github.com/synheart-ai/synheart-emotion-swift.git", from: "0.1.0")
]

Requirements

  • iOS 13.0+
  • Swift 5.9+

Quick Start

Basic Usage

import SynheartEmotion

let config = EmotionConfig()
let engine = try! EmotionEngine.fromPretrained(config: config)

engine.push(
    hr: 72.0,
    rrIntervalsMs: [850.0, 820.0, 830.0, 845.0, 825.0],
    timestamp: Date()
)

let results = engine.consumeReady()
results.forEach { result in
    print("Emotion: \(result.emotion) (\(result.confidence))")
}

Real-Time with Swift Concurrency

Task {
    let emotionEngine = try EmotionEngine.fromPretrained()

    // Stream from wearable
    for try await metrics in synheartWear.streamHRV(windowSize: 60.0) {
        emotionEngine.push(
            hr: metrics.getMetric(.hr) ?? 0.0,
            rrIntervalsMs: metrics.rrIntervals,
            timestamp: Date()
        )

        let results = emotionEngine.consumeReady()
        if let result = results.first {
            await updateUI(result)
        }
    }
}

API Reference

EmotionEngine

Methods:
MethodDescriptionReturns
fromPretrained(config:)Load pretrained modelEmotionEngine
push(hr:rrIntervalsMs:timestamp:)Push biosignal dataVoid
consumeReady()Get ready results[EmotionResult]

EmotionConfig

Parameters:
ParameterTypeDefault
windowDurationTimeInterval60.0 (seconds)
stepDurationTimeInterval5.0 (seconds)

EmotionResult

Properties:
PropertyTypeDescription
emotionEmotionDetected emotion
confidenceDoubleConfidence (0-1)
timestampDateWhen inferred

Resources

For comprehensive documentation, see the full README on GitHub.
Author: Israel Goytom