powerSpectrogram function

Future<List<Float64List>> powerSpectrogram(
  1. String filePath, {
  2. int sampleRate = 22050,
  3. int nFft = 2048,
  4. int? hopLength,
  5. double topDb = 80.0,
})

Loads a WAV file and computes its Power spectrogram via STFT in decibels (dB).

Returns a 2D list (list of frames, where each frame is a list of frequency bins). The number of frequency bins is nFft / 2 + 1.

Implementation

Future<List<Float64List>> powerSpectrogram(
  String filePath, {
  int sampleRate = 22050,
  int nFft       = 2048,
  int? hopLength,
  double topDb   = 80.0,
}) async {
  final audio      = await loadAudio(filePath, sampleRate);
  final powerSpec  = calculateSpectrogram(
    audio.samples,
    fftSize: nFft,
    hopSize: hopLength,
  );
  return powerToDb(powerSpec, topDb: topDb);
}