waveform_extractor

Creator: coderz1093

Last updated:

Add to Cart

Description:

waveform extractor

waveform_extractor #

A Lightweight dart library for extracting waveform data from audio streams using Amplituda.
Platforms Support: #

Android: ✅

Installation #

Add as dependency
in android/build.gradle:

buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // <-- add this
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' } // <-- add this
}
}
copied to clipboard
Usage #

Basic Usage:

final waveformExtractor = WaveformExtractor();
final audioSourceFile = audioPath; // source could be a path to local file
final audioSourceNetwork = audioUrl; // or a network url
final result = await waveformExtractor.extractWaveform(audioSourceFile);
print("Waveform: $result");

copied to clipboard

Available Data:

final result = await waveformExtractor.extractWaveform(audioFile.path);
final List<int> waveformData = result.waveformData;
final List<int> amplitudesForFirstSecond = result.amplitudesForFirstSecond;
final Duration duration = result.duration;
print("Waveform Data: $waveform");
print("Waveform Data (first second): $amplitudesForFirstSecond");
print("Waveform Audio Duration: $duration");
copied to clipboard

With Progress:

waveformExtractor.extractWaveform(
source,
onProgress: (progress) {
final percentage = progress.percentage; // current percentage (0-100)
final operation = progress.operation; // the type of operation (processing, decoding, downloading)
final source = progress.source; // the current source being extracted.
final type = progress.type; // the type of event (start, progress, stop, done)
print("Progress $progress");
},
);
copied to clipboard

Caching:

// Caching is useful to avoid unnecessary re-extractions.
_waveformExtractor.extractWaveform(
source,
useCache: true, // caching is enabled by default.
cacheKey: 'my_unique_key', // optional cache key used for storing output data, defaulted to hashcode of source path.
);

// Clearing cache key:
_waveformExtractor.clearCache(
audioPath: audioPath, // audio source if you have't specied cacheKey before
cacheKey: cacheKey, // clears specific cache key
);

// Clearing all cache:
_waveformExtractor.clearAllWaveformCache();

copied to clipboard

Compressing:

// Compressing is a good choice for long audios, as the resulted data would be huge; causing, possibly, memory overload or jank
final staticSamples = 4; // use default sample for all audios
final dynamicSamples = _waveformExtractor.getSampleRateFromDuration(audioDuration: audioDuration); // or dynamically change depending on audio duration
_waveformExtractor.extractWaveform(
source,
samplesPerSecond: dynamicSamples,
);
copied to clipboard
Benchmarks #

waveform_extractor is extremely fast, thanks to the inlying ffmpeg implementations made by Amplituda
Estimated extraction time:

1 second for a 3min 20s audio.
20 seconds for a 1 hour audio.


For more details and real-time testing, check out the full example

Special thanks #
@lincollincol for providing Amplituda Library based on FFMPEG.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.