SonixLessonSynthesizer

Synthesizes audio lessons from svara (note) sequences.

What is Lesson Synthesis?

In Indian classical music education, lessons are built from svaras (notes like Sa, Re, Ga, Ma, Pa, Dha, Ni). This synthesizer:

  • Combines individual svara recordings into a complete lesson

  • Applies proper timing based on beat length

  • Handles crossfades and loop smoothing

  • Adds configurable silence at start/end

When to Use

ScenarioUse This?Why
Generate lesson audioYesCore use case
Create practice tracksYesFrom svara sequence
Synthesize from MIDINoUse SonixMidiSynthesizer
Play existing audioNoUse SonixPlayer

Quick Start

Kotlin

val svaras = listOf(
LessonSvara(
svaraName = "Sa",
svaraLabel = "S",
svaraAudioFilePath = "/path/to/sa.wav",
numBeats = 2,
numSamplesConsonant = 100
),
LessonSvara(
svaraName = "Re",
svaraLabel = "R",
svaraAudioFilePath = "/path/to/re.wav",
numBeats = 2,
numSamplesConsonant = 100
)
)

val synth = SonixLessonSynthesizer.create(
svaras = svaras,
beatLengthMs = 500
)

if (synth.loadAudioSync()) {
val audioData = synth.synthesize()
// audioData is ready to play or save
}

synth.release()

Swift

let svaras = [
LessonSvara(
svaraName: "Sa",
svaraLabel: "S",
svaraAudioFilePath: "/path/to/sa.wav",
numBeats: 2,
numSamplesConsonant: 100
),
LessonSvara(
svaraName: "Re",
svaraLabel: "R",
svaraAudioFilePath: "/path/to/re.wav",
numBeats: 2,
numSamplesConsonant: 100
)
]

let synth = SonixLessonSynthesizer.create(
svaras: svaras,
beatLengthMs: 500
)

// Load audio (async)
if await synth.loadAudio() {
if let audioData = synth.synthesize() {
// audioData is ready to play or save
}
}

synth.release()

Builder Pattern (Advanced)

Kotlin

val synth = SonixLessonSynthesizer.Builder()
.svaras(svaraList)
.beatLengthMs(500)
.silenceBeats(start = 2, end = 2)
.sampleRate(44100)
.onError { error -> println("Error: $error") }
.build()

StateFlows

StateFlowTypeDescription
isLoadingBooleanTrue while loading audio files
isLoadedBooleanTrue when ready to synthesize
errorSonixError?Error state

Platform Notes

iOS/Android

  • Audio files must be accessible at specified paths

  • Loading happens asynchronously (use loadAudio() suspend function)

  • Synthesis runs synchronously after loading

Common Pitfalls

  1. Call loadAudio first: Must load before synthesize

  2. Audio file paths: Must be absolute paths to valid audio files

  3. Memory usage: All svara files loaded into memory

  4. Sample rate: Output defaults to 16kHz (for Calibra compatibility)

See also

For svara specification format

For MIDI-based synthesis

For output format

Types

Link copied to clipboard
class Builder

Builder for advanced SonixLessonSynthesizer configuration.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Beat length in milliseconds.

Link copied to clipboard
val error: StateFlow<SonixError?>

Error state, null if no error.

Link copied to clipboard
val isLoaded: StateFlow<Boolean>

Whether audio has been successfully loaded and ready for synthesis.

Link copied to clipboard
val isLoading: StateFlow<Boolean>

Whether audio is currently being loaded.

Link copied to clipboard

Sample rate for output audio.

Link copied to clipboard

Number of silence beats at the end.

Link copied to clipboard

Number of silence beats at the start.

Functions

Link copied to clipboard
suspend fun loadAudio(): Boolean

Load audio files for all svaras.

Link copied to clipboard

Load audio files synchronously (blocking).

Link copied to clipboard
fun release()

Release resources.

Link copied to clipboard

Synthesize the lesson track from loaded audio.