JSWaveform is a Swift Package that has native interfaces consisting of audio engine and pure animatable SwiftUI components in iOS, iPadOS and visionOS.
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.
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
JSWaveform
provides native Swift and SwiftUI components. For now, it has 2 major SwiftUI views:
AudioPlayerView
AudioVisualizerView
AudioPlayerView
renders audio player which consits of play/pause button, downsampled waveform and time pitch effect button.
let url = Bundle.main.url(forResource: "Example", withExtension: "aif")
AudioPlayerView(audioURL: url!)
If you want to configure it, you can, by setting AudioPlayer.Configuration in it's init.
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.
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()
}
}
If you want to configure it, you can, by setting AudioVisualizer.Configuration in its init.
You can read more about this at my site juraskrlec.com.