Giter Site home page Giter Site logo

alexanderkraynov / soundwaveform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benoit-pereira-da-silva/soundwaveform

0.0 1.0 0.0 22.3 MB

Generate WaveForms Images from Sounds and Videos on macOS and iOS (Swift 5.x)

Home Page: https://pereira-da-silva.com

License: MIT License

Swift 96.73% Objective-C 3.27%

soundwaveform's Introduction

Swift 5 Platform Carthage compatible

SoundWaveForm

Allows to extract sound samples from Video or Sounds files very efficiently (it relies on the Accelerate framework). SoundWaveForm expose an optimized cross platform drawing that renders the waveform into an Image.

It supports

  • macOS 10.11 & +
  • iOS 8 & +
  • swift 5.x
  • if you need to support swift 4 use v3.0.2
  • if you need to support swift 3 use the v2.0.1

Screen Shots

MacDown Screenshot MacDown Screenshot MacDown Screenshot

Usage sample

The framework is composed of a SamplesExtractor and a WaveFormDrawer.

// Configure the drawings
let configuration = WaveformConfiguration( size: waveFormView.bounds.size,
											backgroundColor: WaveColor.lightGray,
											color: WaveColor.red,
											style: .striped,
											position: .middle,
											scale: 1)

// Extract the downsampled samples
// Proceed to extraction
SamplesExtractor.samples(audioTrack: track,
        timeRange: nil,
        desiredNumberOfSamples: 500,
        onSuccess:{ samples, sampleMax, id in
        	// Let's display the waveform in a view                     
			self.waveFormView.image = WaveFormDrawer.image(from: samples, with: configuration)
        },
        onFailure: { error, id in 
            ... // Handle the error e.g: print("\(id ?? "") \(error)")
        }
)

How to extract sample from a specified timeRange?

You can define AVAssetReader.timeRange.

let asset = AVURLAsset(url: url)
let audioTracks:[AVAssetTrack] = asset.tracks(withMediaType: AVMediaTypeAudio)
if let track:AVAssetTrack = audioTracks.first{
		
		// Define the timeRange from second 1 to second 10
		let startTime = CMTime(seconds: 1, preferredTimescale: 1000)
		let endTime = CMTime(seconds: 10, preferredTimescale: 1000)
		let timeRange = CMTimeRangeMake(startTime, endTime)

		// Proceed to extraction (refer to previous code)
		SamplesExtractor.samples(audioTrack: track,
				timeRange:timeRange,
				desiredNumberOfSamples: 500,
				onSuccess:{ samples, sampleMax, id in
					... // Proceeed
				},
				onFailure: { error, id in 
					... // Handle the error
				}
		)
  
}

Installation

  • Via SPM: add https://github.com/benoit-pereira-da-silva/SoundWaveForm
  • Via Carthage: Add to your Cartfile github "benoit-pereira-da-silva/SoundWaveForm"
  • Copy the two source files : Sources/SoundWaveForm/

Inspiration

This project has been largely inspired by FDWaveformView and DSWaveformImage. Thanks to William aka @fulldecent and Daniel @dmrschmidt.

soundwaveform's People

Contributors

benoit-pereira-da-silva avatar

Watchers

James Cloos 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.