music_analysis 0.1.0 copy "music_analysis: ^0.1.0" to clipboard
music_analysis: ^0.1.0 copied to clipboard

A Dart package allowing music processing and analysis BPM, Key, and more.

example/music_analysis_example.dart

import 'package:music_analysis/data/analysis_result.dart';
import 'package:music_analysis/data/camelot_key_prediction.dart';
import 'package:music_analysis/data/file_data.dart';
import 'package:music_analysis/music_analysis.dart';

Future<void> main(List<String> arguments) async {

  // Track name
  const String trackName = "550senta.wav";

  // Analyze the track:
  AnalysisResult result  = await Music.analyzeFile("test_music/$trackName");

  // Get BPM and Best Key
  double bpm = result.musicData.bpm;
  CamelotKeyPrediction camelotKeyPrediction = result.musicData.key.bestPrediction;

  // Get file metadata:
  FileData fileData = result.fileData;
  String fileName = fileData.fileName;
  String filePath = fileData.path;
  int fileSize = fileData.sizeInBytes;
  int sampleRate = fileData.sampleRate;
  int channels = fileData.channels;
  Duration duration = fileData.duration;

  //// PRINT RESULTS:

  // Data:
  print("Analysis of `$trackName`:");

  print("- BPM: $bpm");
  print("- Key: ${camelotKeyPrediction.key} (${camelotKeyPrediction.confidence * 100}%)");

  print("- File Name: $fileName");
  print("- File Path: $filePath");
  print("- File Size: ${fileSize / (1024 * 1024)} MB");
  print("- Sample Rate: $sampleRate Hz");
  print("- Channels: $channels");
  print("- Duration: ${duration.inSeconds} seconds");

  // Get all key predictions:
  print("\nAll Key Predictions:");
  for (var prediction in result.musicData.key.predictions) {
    print("- ${prediction.key}: ${prediction.confidence * 100}% confidence");
  }

}
1
likes
150
points
71
downloads

Documentation

API reference

Publisher

verified publisherraylabz.com

Weekly Downloads

A Dart package allowing music processing and analysis BPM, Key, and more.

Homepage
Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

buymeacoffee.com

License

Apache-2.0 (license)

More

Packages that depend on music_analysis