Skip to content

Heilum/SFAudioWaveformHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#SFAudioWaveformHelper

This project illustrates how to use Accelerate framework and generate the waveform image of an audio file

ScreenShot

The code is derived from https://github.com/fulldecent/FDWaveformView and enlightened from http://www.davidstarke.com/2015/04/waveforms.html

Features

  • Using Swift 3;
  • Using Accelerate framework;
  • Just a simple function calling, you get the waveform image.

How to use


@IBAction func onGenerate(_ sender: Any) {
    let now = Date.timeIntervalSinceReferenceDate;
    let audioURL = Bundle.main.url(forResource: "audio", withExtension: "mp3")!;
    let scale = UIScreen.main.scale;
    let imageSizeInPixel =  CGSize(width:imageView.bounds.width * scale,height:imageView.bounds.height * scale);
    generateWaveformImage(audioURL: audioURL, imageSizeInPixel: imageSizeInPixel, waveColor: UIColor.red) {[weak self] (waveFormImage) in
        if let waveFormImage = waveFormImage {
            self?.imageView.image = waveFormImage;
            print("image.size = \(waveFormImage.size),scale=\(waveFormImage.scale)")
            self?.alert(str: "Seconds costed:\(Date.timeIntervalSinceReferenceDate - now)");
        }else{
            self?.alert(str: "Shit happens");
        }
    }
}

License

This code is distributed under the terms and conditions of the MIT license.

About

Generate waveform image from an audio file on iOS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages