1
1
"""
2
- MFCC ( Mel Frequency Cepstral Coefficients) Calculation
2
+ Mel Frequency Cepstral Coefficients (MFCC ) Calculation
3
3
4
4
MFCC is a feature widely used in audio and speech processing to represent the
5
5
short-term power spectrum of a sound signal in a more compact and
@@ -138,12 +138,10 @@ def normalize(audio: np.ndarray) -> np.ndarray:
138
138
max_abs_value = np .max (np .abs (audio ))
139
139
140
140
# Divide the entire audio signal by the maximum absolute value
141
- normalized_audio = audio / max_abs_value
141
+ return audio / max_abs_value
142
142
143
- return normalized_audio
144
143
145
-
146
- def frame (
144
+ def audio_frames (
147
145
audio : np .ndarray ,
148
146
sample_rate : int ,
149
147
hop_length : int = 20 ,
@@ -168,7 +166,7 @@ def frame(
168
166
audio = np .pad (audio , int (ftt_size / 2 ), mode = "reflect" )
169
167
170
168
# Calculate the number of frames
171
- frame_num = int ((len (audio ) - ftt_size ) / hop_size ) + 1
169
+ frame_count = int ((len (audio ) - ftt_size ) / hop_size ) + 1
172
170
173
171
# Initialize an array to store the frames
174
172
frames = np .zeros ((frame_num , ftt_size ))
@@ -206,9 +204,7 @@ def calculate_fft(audio_windowed: np.ndarray, ftt_size: int = 1024) -> np.ndarra
206
204
audio_fft [:, n ] = fft .fft (audio_transposed [:, n ], axis = 0 )[: audio_fft .shape [0 ]]
207
205
208
206
# Transpose the FFT results back to the original shape
209
- audio_fft = np .transpose (audio_fft )
210
-
211
- return audio_fft
207
+ return np .transpose (audio_fft )
212
208
213
209
214
210
def calculate_signal_power (audio_fft : np .ndarray ) -> np .ndarray :
@@ -289,9 +285,7 @@ def mel_spaced_filterbank(
289
285
# normalize filters
290
286
# taken from the librosa library
291
287
enorm = 2.0 / (mel_freqs [2 : mel_filter_num + 2 ] - mel_freqs [:mel_filter_num ])
292
- filters *= enorm [:, np .newaxis ]
293
-
294
- return filters
288
+ return filters * enorm [:, np .newaxis ]
295
289
296
290
297
291
def get_filters (filter_points : np .ndarray , ftt_size : int ) -> np .ndarray :
0 commit comments