[go: up one dir, main page]

Skip to content

Animate and generate waveform from audio files for iOS, iPadOS and visionOS. Native SwiftUI Swift Package

License

Notifications You must be signed in to change notification settings

juraskrlec/JSWaveform

Repository files navigation

SwiftPM compatible

JSWaveform

JSWaveform is a Swift Package that has native interfaces consisting of audio engine and pure animatable SwiftUI components in iOS, iPadOS and visionOS.

Requirements

Swift Package contains full source code under MIT License. The package can be deployed on iOS and iPadOS 17 and later, and visionOS 1 or later. The package supports full Swift and SwiftUI projects. This package doesn't contain any UIKit components.

Installation

Please check out Swift Package Manager documentation if you are new to Swift Package Manager.

Use URL https://github.com/juraskrlec/JSWaveform and use the latest version.

import JSWaveform

Usage

JSWaveform provides native Swift and SwiftUI components. For now, it has 2 major SwiftUI views:

  • AudioPlayerView
  • AudioVisualizerView

AudioPlayerView

AudioPlayerView renders audio player which consits of play/pause button, downsampled waveform and time pitch effect button.

AudioPlayer

Usage

    let url = Bundle.main.url(forResource: "Example", withExtension: "aif")
    AudioPlayerView(audioURL: url!)

Configuration

If you want to configure it, you can, by setting AudioPlayer.Configuration in it's init.

AudioVisualizerView

AudioVisualizerView renders audio visualizer which animates AudioVisualizerShape based on audio amplitudes. This image shows default animation called symetricMiddleHigh where peak amplitudes are in the middle and average on the sides. You can see more available animations and set them using AudioVisualizer.Configuration.

AudioVisualizer

Usage

    let url = Bundle.main.url(forResource: "Example", withExtension: "aif")
    AudioVisualizerView(audioURL: url!)

You can also play/stop audio. Example:

    Toggle("Play audio", isOn: $playAudio)
        .tint(.blue)
        .onChange(of: playAudio) { _, _ in
            if playAudio {
                audioVisualizerView.playAudio()
            }
            else {
                audioVisualizerView.stopAudio()
            }
        }

Configuration

If you want to configure it, you can, by setting AudioVisualizer.Configuration in its init.

Read more about it

You can read more about this at my site juraskrlec.com.

Connect

Linkedin

Twitter/X