Swiftpack.co -  dmrschmidt/DSWaveformImage as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Generate waveform images from audio files in iOS
.package(url: "https://github.com/dmrschmidt/DSWaveformImage.git", from: "8.1.0")


Carthage compatible Swift Package Manager compatible

DSWaveformImage offers a few interfaces with the main purpose of drawing the envelope waveform of audio files in iOS. To do so, you can use WaveformImageDrawer or WaveformImageView.

Additionally, you can get a waveform's (normalized) samples directly as well by creating an instance of WaveformAnalyzer.

More related iOS Controls

You may also find the following iOS controls written in Swift interesting:


  • use SPM: add https://github.com/dmrschmidt/DSWaveformImage and set "Up to Next Major" with "8.1.0"
  • use carthage: github "dmrschmidt/DSWaveformImage" ~> 7.0
  • simply copy the DSWaveformImage folder directly into your project.
  • or, sunset since 6.1.1: use cocoapods: pod 'DSWaveformImage', '~> 6.1'


Calculations are always performed and returned on a background thread, so make sure to return to the main thread before doing any UI work.

To create a UIImage using WaveformImageDrawer:

let waveformImageDrawer = WaveformImageDrawer()
let audioURL = Bundle.main.url(forResource: "example_sound", withExtension: "m4a")!
waveformImageDrawer.waveformImage(fromAudioAt: audioURL,
                                  size: topWaveformView.bounds.size,
                                  style: .filled(UIColor.black),
                                  position: .top) { image in
    // need to jump back to main queue
    DispatchQueue.main.async {
        self.topWaveformView.image = image

To create a WaveformImageView (UIImageView subclass):

let audioURL = Bundle.main.url(forResource: "example_sound", withExtension: "m4a")!
waveformImageView = WaveformImageView(frame: CGRect(x: 0, y: 0, width: 500, height: 300)
waveformImageView.waveformAudioURL = audioURL

And finally, to get an audio file's waveform samples:

let audioURL = Bundle.main.url(forResource: "example_sound", withExtension: "m4a")!
waveformAnalyzer = WaveformAnalyzer(audioAssetURL: audioURL)
waveformAnalyzer.samples(count: 200) { samples in
    print("so many samples: \(samples)")

Playback Indication

If you're playing back audio files and would like to indicate the playback progress to your users, you can find inspiration in this ticket. There's various other ways of course, depending on your use case and design.

Loading remote audio files from URL

For one example way to display waveforms for audio files on remote URLs see https://github.com/dmrschmidt/DSWaveformImage/issues/22.

What it looks like

Waveforms can be rendered in 3 different styles: .filled, .gradient and .striped. Similarly, there are 3 positions .top, .middle and .bottom

  • relative to the canvas. The effect of each of those can be seen here:


In 7.0.0 colors have moved into associated values on the respective style enum.

Waveform and the UIImage category have been removed in 6.0.0 to simplify the API. See Usage for current usage.

See it live in action

SoundCard lets you send postcards with audio messages.

DSWaveformImage is used to draw the waveforms of the audio messages on postcards sent by SoundCard.

Check it out on the App Store.



Stars: 257
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API