VocalRangeSession

High-level vocal range detection session with observable state.

This class provides a simplified API that:

  • Emits state changes via StateFlow for reactive UI

  • Runs auto-flow by default (countdown -> low -> high -> done)

  • Supports manual phase control for custom flows

Auto-Flow Usage (Recommended)

val session = VocalRangeSession.create()

// Observe state in UI
session.state.collect { state ->
updateUI(state)
}

// Start detection - runs full flow automatically
session.start()

// Feed audio from your recorder (resample to 16kHz)
recorder.audioBuffers.collect { buffer ->
val samples16k = SonixResampler.resample(buffer.floatSamples, hwRate, 16000)
session.addAudio(samples16k)
}

// Cleanup
session.release()

Manual Flow Control

val session = VocalRangeSession.create(VocalRangeSessionConfig(autoFlow = false))

session.startPhase(VocalRangePhase.DETECTING_LOW)
// ... feed audio ...
session.advancePhase() // Move to DETECTING_HIGH
// ... feed audio ...
session.complete()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val state: StateFlow<VocalRangeState>

Functions

Link copied to clipboard
fun addAudio(samples: FloatArray, sampleRate: Int = 16000)

Add audio samples for processing.

Link copied to clipboard

Manually advance to the next phase. Captures the current stable note for the current phase.

Link copied to clipboard
fun cancel()

Cancel the current session.

Link copied to clipboard
fun complete()

Complete detection and calculate final result.

Link copied to clipboard

Lock the current best note and advance to next phase.

Link copied to clipboard
fun release()

Release all resources. Must be called when done.

Link copied to clipboard
fun reset()

Reset to start a new session.

Link copied to clipboard
fun start()

Start the detection session (auto-flow mode).

Link copied to clipboard

Start a specific phase (manual mode). Use when autoFlow = false for custom flows.