Skip to content

A modern, Jetpack Compose-based Android library to visualize audio waveforms, playback progress, and interactively select or segment audio clips with ease.

Notifications You must be signed in to change notification settings

karya-inc/Waveform

Repository files navigation

🎵 Waveform

A modern, Jetpack Compose-based Android library to visualize audio waveforms, playback progress, and interactively select or segment audio clips with ease.

✨ Features

  • 📊 Graph Visualizations: Render line and bar graphs for audio amplitude data.
  • 🎧 Playback Visualizer: Display a scrollable, center-pinned waveform synced to audio playback.
  • ✂️ Audio Segmentation Tool: Select multiple audio segments using an intuitive timeline interface.
  • 🔍 Audio Segment Picker: Zoom into waveform regions and fine-tune a single segment.

📦 Installation

dependencies {
    implementation("io.github.karya-inc:waveform:<latest-version>")
}

🚀 Quick Start

Amplitude Bar Graph

@Composable
fun BarGraphExample() {
    AmplitudeBarGraph(
        amplitudes = listOf(100, 200, 300, 500, 100, 20),
        onProgressChange = { newProgress -> /* handle scrub */ }
    )
}
image

Center-Pinned Waveform for Playback

@Composable
fun PlaybackVisualizer() {
    CenterPinnedAmplitudeBarGraph(
        amplitudes = listOf(100, 200, 300, 500, 100, 20),
        durationMs = 2000,
        progressMs = 1000
    )
}
image

✂️ Audio Segmentation

Segment Selector with Multiple Segments

val segmentationState = rememberAudioSegmentationState(
    audioFilePath = audioPath,
    amplitudes = amplitudeList,
    durationMs = totalDuration,
    enableAdjustment = true
)

AudioSegmentationUi(state = segmentationState)
image
  • ✅ Drag to select segments
  • 🛠️ Enable adjustments with min/max segment durations
  • 📄 Output format: List<Pair<startMs, endMs>>

🎚 Audio Segment Picker

Zoom into a waveform and select a precise segment interactively.

val pickerState = rememberAudioSegmentPickerState(
    audioFilePath = audioPath,
    amplitudes = amplitudeList,
    durationMs = totalDuration,
    segment = Pair(0, totalDuration / 4),
    window = Pair(0, totalDuration / 8)
)

AudioSegmentPicker(
    state = pickerState,
    mainPlayerProgress = pickerState.activeSegment.first + currentProgress,
    segmentPlaybackProgress = pickerState.activeSegment.first + currentProgress,
    isPlaying = isPlaying,
    toggleSegmentPlayback = { 
        val segment = pickerState.activeSegment
        // Control playback with your own ExoPlayer instance
    }
)
image

📈 Graph Variants

Bar and Line Graphs

Graph(
    amplitudes = listOf(200f, 30f, 45f, 5f, 16f, 20f),
    type = GraphType.Bar,
    maxAmplitude = 300f
)

Graph(
    amplitudes = listOf(200f, 30f, 45f, 5f, 16f, 20f),
    type = GraphType.Line,
    maxAmplitude = 300f
)
image

🛠 Customization

You can customize:

  • Spike width, spacing, and corner radius
  • Waveform alignment (Top, Center, Bottom)
  • Drawing style (Fill or Stroke)
  • Amplitude aggregation (Max, Average)
  • Zoom levels and segment constraints

🧱 Built With

  • Jetpack Compose
  • ExoPlayer (integration friendly)
  • Kotlin Coroutines

📄 License

MIT License. See LICENSE for details.

🤝 Contributing

Contributions, bug reports, and feature suggestions are welcome! Feel free to open an issue or pull request.

🙏 Acknowledgements

This library is inspired by compose-audiowaveform by lincollincol

About

A modern, Jetpack Compose-based Android library to visualize audio waveforms, playback progress, and interactively select or segment audio clips with ease.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages