Mr7Explorer commited on
Commit
27b0097
·
verified ·
1 Parent(s): 097e143

Update spectral.py

Browse files
Files changed (1) hide show
  1. spectral.py +2 -12
spectral.py CHANGED
@@ -1,9 +1,3 @@
1
- # spectral.py
2
- # ============================================================
3
- # Spectral Analysis Module for Audio Forensic Analyzer
4
- # Logic preserved exactly from original app.py (cleaned + modular)
5
- # ============================================================
6
-
7
  import numpy as np
8
  import librosa
9
  import scipy.signal as sps
@@ -30,7 +24,7 @@ def compute_spectral_analysis(y, sr, n_fft=4096):
30
  S_db = librosa.amplitude_to_db(S, ref=np.max)
31
 
32
  # ============================================================
33
- # 90th Percentile Energy Envelope (Major Improvement)
34
  # ============================================================
35
  S_power = S ** 2
36
  energy = np.percentile(S_power, 90, axis=1) + 1e-20
@@ -118,10 +112,7 @@ def compute_spectral_analysis(y, sr, n_fft=4096):
118
  flatness = float(np.mean(librosa.feature.spectral_flatness(S=S)))
119
  rolloff = float(np.mean(librosa.feature.spectral_rolloff(S=S, sr=sr)))
120
 
121
- # ============================================================
122
- # FINAL RETURN STRUCTURE
123
- # (Matches original format exactly)
124
- # ============================================================
125
  return {
126
  "S_db": S_db,
127
  "freqs": freqs,
@@ -144,7 +135,6 @@ def compute_spectral_analysis(y, sr, n_fft=4096):
144
  "spectral_flatness": flatness,
145
  "spectral_rolloff": rolloff,
146
 
147
- # Added envelopes for downstream detectors (unchanged logic)
148
  "hf_env": mean_db_per_bin,
149
  "lf_env": mean_db_per_bin[:200] if len(mean_db_per_bin) > 200 else mean_db_per_bin
150
  }
 
 
 
 
 
 
 
1
  import numpy as np
2
  import librosa
3
  import scipy.signal as sps
 
24
  S_db = librosa.amplitude_to_db(S, ref=np.max)
25
 
26
  # ============================================================
27
+ # 90th Percentile Energy Envelope
28
  # ============================================================
29
  S_power = S ** 2
30
  energy = np.percentile(S_power, 90, axis=1) + 1e-20
 
112
  flatness = float(np.mean(librosa.feature.spectral_flatness(S=S)))
113
  rolloff = float(np.mean(librosa.feature.spectral_rolloff(S=S, sr=sr)))
114
 
115
+
 
 
 
116
  return {
117
  "S_db": S_db,
118
  "freqs": freqs,
 
135
  "spectral_flatness": flatness,
136
  "spectral_rolloff": rolloff,
137
 
 
138
  "hf_env": mean_db_per_bin,
139
  "lf_env": mean_db_per_bin[:200] if len(mean_db_per_bin) > 200 else mean_db_per_bin
140
  }