Documentation Index
Fetch the complete documentation index at: https://sdk.sleepcycle.com/llms.txt
Use this file to discover all available pages before exploring further.
Sleep Cycle SDK - Android Documentation
Overview
The Sleep Cycle SDK for Android enables developers to integrate advanced sleep analysis capabilities into their applications. The SDK provides real-time sleep tracking using audio and motion sensors, delivering detailed sleep insights and events throughout the night.System Requirements
Minimum Android API Level:- Min SDK: API level 28 (Android 9.0 Pie)
- Compile SDK: API level 35
- Kotlin Version: 1.9+ (JVM target 11)
- The SDK is written in Kotlin and provides a Kotlin-first API
Installation
Find the latest version on Maven Central.Groovy DSL
Add the Sleep Cycle SDK dependency to yourbuild.gradle:
Kotlin DSL
Add the Sleep Cycle SDK dependency to yourbuild.gradle.kts:
Prerequisites
Permissions
The SDK requires microphone access for audio-based sleep analysis:Keeping the analysis active using a foreground service
To ensure continuous sleep analysis throughout the night, you must implement a foreground service. This prevents Android from terminating the analysis process during extended periods. It is up to the host app to start the foreground service correctly. The service must declare appropriate foreground service types in its manifest to specify what system resources it needs access to. For sleep analysis, you’ll typically need thehealth or microphone service types, which grant access to health sensors and microphone respectively.
General
The SDK is thread safe and can be called from any thread.Initialize the SDK
The SDK requires authentication before use. The initialization process validates your credentials and determines available features.SleepAnalysisFeatures indicates which capabilities are available for your API key:
sleepStaging Boolean - Sleep staging analysissmartAlarm Boolean - Smart alarm functionalityaudioEvents Boolean - Audio event detectionsnoringDetection Boolean - Snoring detectionrealTimeSleepStaging Boolean - Real-time sleep stagingmultiChannelAnalysis Boolean - Multi-channel analysis (stereo, two channels)Get the SDK state
Monitor SDK state changes using the StateFlow:Start a sleep analysis session
Once initialized, you can start a sleep analysis session. The method returns aUUID that identifies the session.
config SleepAnalysisConfig - Configuration object specifying which sensors to usestartMillisUtc Long - Analysis start time in UTC milliseconds (defaults to current time)dataSource DataSource? - Optional custom data source. When null, the SDK uses live device sensorsaudioEventListeners List<AudioEventListener> - Optional list of listeners that receive callbacks during audio analysisResume a session
The SDK supports resuming a previously started analysis session. This is useful when your app restarts or the foreground service is terminated by the system.Stop a session
To stop an active analysis session and retrieve the results:Analysis result
TheAnalysisResult contains the complete output of a sleep analysis session:
sessionId UUID - Unique session identifierstartSecondsUtc Double - Session start time in UTC secondsendSecondsUtc Double - Session end time in UTC secondsevents List<Event> - Detected sleep eventsbreathingRates List<BreathingRate> - Breathing rate measurementssleepStageIntervals List<SleepStageInterval> - Sleep stage datastatistics SleepStatistics? - Aggregated sleep statistics (nullable)audioStatistics AudioStatistics? - Audio health statistics (nullable)SleepStatistics
When available,statistics contains aggregated metrics about the sleep session:
totalSleepDurationSeconds Double - Total time spent sleepingsleepOnsetLatencySeconds Double? - Time to fall asleepsleepEfficiency Double - Ratio of sleep to time in bed (0.0 to 1.0)finalWakeTimeSecondsUtc Double? - Time of final awakening (UTC seconds)numberOfAwakenings Int - Number of awakenings during the nightsnoreTimeSeconds Double - Total time spent snoringsnoreSessions List<SnoreSession> - Individual snoring sessionssleepStageDurationsSeconds Map<SleepStage, Double> - Duration per sleep stageAudioStatistics
When available,audioStatistics contains information about audio input health throughout the session.
Real-time events
The SDK provides real-time event updates during analysis through a Flow API:Event contains:
type EventType - The type of eventstartTime Double - Start timestamp in UTC secondsendTime Double - End timestamp in UTC secondsprobability Float - Confidence score (0.0 to 1.0)source EventSource - Source of detectionsessionId UUID - The session this event belongs tosignature FloatArray? - Optional feature vector (for snoring events)Real-time breathing rate
The SDK provides real-time breathing rate measurements during analysis:BreathingRate contains:
timestampSecondsUtc Double - Time of measurement in seconds since Unix epochbpm Float - Breathing rate in breaths per minuteconfidence Float - Confidence level of the measurement (0.0 to 1.0)sessionId UUID - The session this measurement belongs toReal-time sleep staging (Experimental)
The SDK can provide real-time sleep stage predictions during analysis. This feature requires therealTimeSleepStaging capability to be enabled for your API key.
SleepStageInterval objects approximately every 30 seconds during analysis, providing near real-time feedback on sleep state transitions.
Real-time audio health
The SDK monitors the health of the audio input during analysis and emits status updates when the audio state changes:AudioHealthStatus values:
HEALTHY - Audio input contains a varying signalFLATLINE - Constant value detected (non-functional microphone or muted input)MISSING_INPUT - No audio input received for an extended periodEvent signatures
For snoring events, theEvent.signature property contains a 16-dimensional feature vector that represents unique characteristics of the detected snore. Snore events from the same person are grouped close to each other in the signature space, allowing clustering of events by person.
Audio event listener
TheAudioEventListener interface allows you to receive real-time audio analysis updates during a session. Implement this interface to access raw audio samples, event detection, and volume information as analysis progresses.
audioSamples parameter contains all processed audio data in sequence, without any gaps or overlap between batches. Each batch continues exactly where the previous batch ended, ensuring complete coverage of all analyzed audio.
Audio clips
The SDK can capture short audio recordings when specific sleep events are detected, such as snoring, sleep talking, or coughing. To use audio clips, create an audio clips producer and pass it tostartAnalysis:
AudioClip contains:
startTime Double - Start timestamp in secondstype EventType - The event type that triggered the capturesamples FloatArray - Raw audio samplessampleRate Int - Sample rate in HzsessionId UUID - The session this clip belongs toMulti-channel analysis
The SDK supports analyzing two channels simultaneously using a stereo audio source. Multi-channel analysis separates the data source lifecycle from individual session lifecycles, allowing you to start and stop sessions on each channel independently. The stereo stream is expected to come from two separate mono microphones combined into a single stereo stream, with one microphone per channel. This requires themultiChannelAnalysis feature to be enabled for your API key.
Channel separation
When using stereo input,ChannelSeparationConfig controls how audio events are assigned to channels. Built-in presets:
BED_SIDE_MICS— bedside microphones placed apart (default)CENTERED_MIC_ARRAY— closely spaced microphone arrayDETECTION_STRENGTH_ONLY— no spatial filtering, uses only detection confidence
Data source lifecycle
Start the data source with a stereo audio configuration before starting individual sessions:Starting sessions on each channel
Once the data source is running, start a session on each channel:AnalysisChannel values:
PRIMARY - First audio channel (or mono)SECONDARY - Second audio channel in stereoStopping sessions independently
Each session can be stopped independently to retrieve its result:Stopping the data source
After all sessions have been stopped, stop the data source:stopDataSource() while sessions are still active will force-stop them and discard their results. To retrieve results, stop each session first.