vibe_analysis 0.1.0
vibe_analysis: ^0.1.0 copied to clipboard
Pure-Dart audio analysis from PCM samples. Estimates tempo (BPM), musical key, energy, timbre and mood. No native code.
example/vibe_analysis_example.dart
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:vibe_analysis/vibe_analysis.dart';
/// Builds a 30 second click track at 120 BPM so the example runs anywhere.
/// In a real app, decode your file to mono samples instead (see the README).
Float32List demoTrack() {
const sr = 8000;
final x = Float32List(sr * 30);
final rnd = math.Random(1);
const step = sr ~/ 2; // 120 BPM
for (var s = 0; s < x.length; s += step) {
for (var i = 0; i < 240 && s + i < x.length; i++) {
x[s + i] = (rnd.nextDouble() * 2 - 1) * math.exp(-i / 50);
}
}
return x;
}
void main() {
final report = analyzeTrack(demoTrack(), sampleRate: 8000);
print('BPM: ${report.analysis.bpm}');
print('Energy: ${report.analysis.energy}');
print(
'Key: ${report.analysis.keyLabel.isEmpty ? 'unclear' : report.analysis.keyLabel}');
print('Mood estimate: ${report.features.mood}');
}