Sonix Audio Utils
object SonixAudioUtils
Audio utility functions for manipulating AudioRawData and converting between frame indices and time.
When to Use
| Scenario | Use This? | Why |
|---|---|---|
| Join audio clips end-to-end | Yes | concatenate(listOf(a, b, c)) |
| Peak-normalize audio | Yes | normalize(audio) |
| Mix audio tracks offline | Yes | mix(listOf(a, b), gains) |
| Convert frame indices to seconds | Yes | framesToTime(frames, sr, hop) |
| Find voiced regions from a mask | Yes | framesToSegments(mask, sr, hop) |
| Mix audio for real-time playback | No | Use SonixMixer |
| Decode audio files | No | Use SonixDecoder |
Quick Start
Kotlin
// Concatenate multiple audio clips
val combined = SonixAudioUtils.concatenate(listOf(audio1, audio2, audio3))
// Convert frame indices to time
val times = SonixAudioUtils.framesToTime(intArrayOf(0, 10, 20), sampleRate = 16000, hopLength = 512)
// Convert a boolean frame mask to time segments
val mask = booleanArrayOf(false, true, true, true, false, false, true, true)
val segments = SonixAudioUtils.framesToSegments(mask, sampleRate = 16000, hopLength = 512)
// segments: [(start1, end1), (start2, end2)]Content copied to clipboard
Swift
// Concatenate multiple audio clips
let combined = SonixAudioUtils.concatenate([audio1, audio2, audio3])
// Convert frame indices to time
let times = SonixAudioUtils.framesToTime(frames: [0, 10, 20], sampleRate: 16000, hopLength: 512)
// Convert a boolean frame mask to time segments
let mask: [Bool] = [false, true, true, true, false, false, true, true]
let segments = SonixAudioUtils.framesToSegments(frameMask: mask, sampleRate: 16000, hopLength: 512)
// segments: [(start: 0.032, end: 0.128), (start: 0.192, end: 0.256)]Content copied to clipboard
See also
For decoding audio files to AudioRawData
For encoding AudioRawData to compressed formats
Functions
Link copied to clipboard
Concatenate multiple AudioRawData objects sequentially.
Link copied to clipboard
fun framesToSegments(frameMask: BooleanArray, sampleRate: Int, hopLength: Int): List<Pair<Float, Float>>
Convert a boolean frame mask to time segments.
Link copied to clipboard
Convert frame indices to time in seconds.
Link copied to clipboard
fun mix(audioList: List<AudioRawData>, gains: FloatArray? = null, targetSampleRate: Int? = null): AudioRawData
Mix multiple mono AudioRawData tracks into a single output.
Link copied to clipboard
Peak-normalize audio so the maximum absolute sample value reaches 1.0.
Link copied to clipboard
Convert time in seconds to frame indices.