Music analysis
A music analysis package for Dart & Flutter.
The music_analysis package provides a set of tools for analyzing music data in Dart and Flutter applications.
It offers features such as audio feature extraction, tempo detection, key detection, and more.
The package is designed to be easy to use and efficient, making it suitable for a wide range of music analysis applications.
Contents
Features
- File data extraction such as sample size, sample rate, bit depth, number of channels, duration, and more.
- Audio feature extraction such as tempo, key, time signature, and more.
- Support for WAV formats.
- Upcoming support for MP3, FLAC, and other audio formats.
Getting started
Installation
Install/import the package by running the following command in your project folder terminal:
flutter pub add music_analysis
Detecting audio features
The package features one simple command: Music.analyzeFile() that takes in a file path and returns an AnalysisResult object containing the extracted audio features:
AnalysisResult result = await Music.analyzeFile("path-to-file");
To obtain analysis data like BPM and Key:
BPM (tempo) data
double bpm = result.musicData.bpm;
Tip
BPM data is very rarely an integer value, however, in your applications you can round it to the nearest integer if you wish.
Key (pitch) data
Key (pitch) data is represented by the CamelotKeyPrediction class, which contains information about
the detected key of the audio file. You can access the best prediction for the key using bestPrediction:
CamelotKeyPrediction camelotKeyPrediction = result.musicData.key.bestPrediction;
You can also access all predictions for the key using predictions:
List<CamelotKeyPrediction> predictions = result.musicData.key.predictions;
Note
Key predictions are sometimes not 100% accurate, especially for songs with complex harmonies or modulations.
It is recommended to use the best prediction as a reference and verify it with your own musical knowledge.
This is also why the package provides a list of predictions, so you can choose the one that best fits your needs.
You can also use the confidence property of the CamelotKeyPrediction class to determine how confident the algorithm is in its prediction.
Detecting file features
The package also provides file data extraction features such as sample size, sample rate, bit depth, number of channels, duration, and more. You can access these features through the fileData property of the AnalysisResult object:
FileData fileData = result.fileData;
From this you can get the file name, path, size, sample rate, bit depth, number of channels, duration, and more:
String fileName = fileData.fileName;
String filePath = fileData.path;
int fileSize = fileData.sizeInBytes;
int sampleRate = fileData.sampleRate;
int channels = fileData.channels;
Duration duration = fileData.duration;
Helper methods allow you also obtain the file size in kilobytes, megabytes, or gigabytes:
double sizeInKB = fileData.sizeInKB;
double sizeInMB = fileData.sizeInMB;
double sizeInGB = fileData.sizeInGB;
Information
Requirements
- Dart 3.2 or higher
- The package is compatible with both plain Dart applications or Flutter applications.
- The package has no dependencies and does not use Flutter FFI.
Known issues and feature requests
No known issues. If you find a bug or have a feature request, please report it on our GitHub repository.
View the change log for the latest updates and changes to Firestorm.
License
Music analysis is open-source and is released under the Apache 2.0 License. See the LICENSE file for more information.
Libraries
- analysis/bpm_detector
- analysis/energy_detector
- analysis/feature_detector
- analysis/key_detector
- analysis/music_analyzer
- data/analysis_result
- data/audio_data
- data/camelot_key
- data/camelot_key_predicition_set
- data/camelot_key_prediction
- data/complex
- data/extension
- data/file_data
- data/key_candidate
- data/music_data
- decoders/decoder
- decoders/mp3_decoder
- decoders/wav_decoder
- exceptions/music_analysis_exception
- music_analysis
- utils/fft
- utils/frame_splitter
- utils/hann_window
- utils/spectral_flux