Étape 1 — Calcul du spectrogramme Mel

4. 3.3 Architecture du modèle de détection de mot-clé

4.1. Étape 1 — Calcul du spectrogramme Mel

Le modèle prend en entrée des spectrogrammes Mel (40 bins × 49 frames), pas l'audio brut. Chaque frame couvre 25 ms, avec un pas de 10 ms → 49 frames pour 1 seconde.

// Simplified Mel spectrogram computation
void compute_mel_features(const int16_t* audio, int len, float* out) {
  const int frame_len  = 400;  // 25ms at 16kHz
  const int frame_step = 160;  // 10ms hop
  const int mel_frames = 49;
  const int mel_bins   = 40;

  for (int f = 0; f < mel_frames; f++) {
    int offset = f * frame_step;
    for (int b = 0; b < mel_bins; b++) {
      float energy = 0;
      int start = offset + (b * frame_len / mel_bins);
      int end   = offset + ((b + 1) * frame_len / mel_bins);
      for (int i = start; i < end && i < len; i++) {
        float s = audio[i] / 32768.0f;
        energy += s * s;
      }
      out[f * mel_bins + b] = logf(energy + 1e-6f);
    }
  }
}

Se connecter pour suivre votre progression.