Giter Club home page Giter Club logo

dswaveformimage's Introduction

DSWaveformImage

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, WaveformImageView or an extension on UIImage.

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

More related iOS Controls

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

Installation

  • use carthage: github "dmrschmidt/DSWaveformImage" ~> 5.0
  • use cocoapods: pod 'DSWaveformImage', '~> 5.0'
  • or add the DSWaveformImage folder directly into your project.

Usage

To create a UIImage using WaveformImageDrawer:

let waveformImageDrawer = WaveformImageDrawer()
let audioURL = Bundle.main.url(forResource: "example_sound", withExtension: "m4a")!
let topWaveformImage = waveformImageDrawer.waveformImage(fromAudioAt: audioURL,
                                                         size: UIScreen.main.bounds.size,
                                                         color: UIColor.black,
                                                         backgroundColor: UIColor.black,
                                                         style: .filled,
                                                         position: .top,
                                                         scale: UIScreen.main.scale)

To create a UIImage using a UIImage extension:

let audioURL = Bundle.main.url(forResource: "example_sound", withExtension: "m4a")!
let waveform = Waveform(audioAssetURL: audioURL)!
let configuration = WaveformConfiguration(size: UIScreen.main.bounds.size,
                                          color: UIColor.blue,
                                          style: .striped,
                                          position: .middle,
                                          scale: UIScreen.main.scale,
                                          paddingFactor: 4.0)
let waveformImage = UIImage(waveform: waveform, configuration: configuration)

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")!
let waveform = Waveform(audioAssetURL: audioURL)!
print("so many samples: \(waveform.samples(count: 200))")

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:

Screenshot

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.

Screenshot

dswaveformimage's People

Contributors

dmrschmidt avatar tewha avatar chakrit avatar adamritenauer avatar victorbaro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.