melSpectrogram function
Loads a WAV file and computes its Mel-frequency spectrogram in decibels (dB).
This is a high-level convenience function that combines audio loading, Short-Time Fourier Transform (STFT), Mel filterbank application, and power-to-dB conversion.
Returns a 2D list (list of frames, where each frame is a list of Mel bins).
Matches the behavior of librosa.feature.melspectrogram followed by librosa.power_to_db.
Implementation
Future<List<Float64List>> melSpectrogram(
String filePath, {
int sampleRate = 22050,
int nFft = 2048,
int? hopLength,
int nMels = 128,
double fMin = 0.0,
double? fMax,
double topDb = 80.0,
}) async {
final audio = await loadAudio(filePath, sampleRate);
final powerSpec = calculateSpectrogram(
audio.samples,
fftSize: nFft,
hopSize: hopLength,
);
final filterbank = createMelFilterbank(
sampleRate: sampleRate,
nFft: nFft,
nMels: nMels,
fMin: fMin,
fMax: fMax,
);
final melSpec = applyMelFilterbank(powerSpec, filterbank);
return powerToDb(melSpec, topDb: topDb);
}