deveix commited on
Commit
08af9a0
·
1 Parent(s): 3dddc6f
Files changed (1) hide show
  1. app/main.py +21 -21
app/main.py CHANGED
@@ -27,16 +27,16 @@ default_sample_rate=22050
27
  def load(file_name, skip_seconds=0):
28
  return librosa.load(file_name, sr=None, res_type='kaiser_fast')
29
 
30
- # def preprocess_audio(audio_data, rate):
31
- # # Apply preprocessing steps
32
- # audio_data = nr.reduce_noise(y=audio_data, sr=rate)
33
- # audio_data = librosa.util.normalize(audio_data)
34
- # audio_data, _ = librosa.effects.trim(audio_data)
35
- # audio_data = librosa.resample(audio_data, orig_sr=rate, target_sr=default_sample_rate)
36
- # # audio_data = fix_length(audio_data)
37
- # rate = default_sample_rate
38
 
39
- # return audio_data, rate
40
 
41
  def extract_features(X, sample_rate):
42
  # Generate Mel-frequency cepstral coefficients (MFCCs) from a time series
@@ -187,22 +187,22 @@ pca = joblib.load('app/pca.pkl')
187
  scaler = joblib.load('app/1713696947.894978_scaler.joblib')
188
  label_encoder = joblib.load('app/1713696954.9487948_label_encoder.joblib')
189
 
190
- def preprocess_audio(audio_data, rate):
191
- # Resample first if the target rate is lower to reduce data size for subsequent operations
192
- if rate > default_sample_rate:
193
- audio_data = librosa.resample(audio_data, orig_sr=rate, target_sr=default_sample_rate)
194
- rate = default_sample_rate
195
 
196
- # Trim silence before applying computationally expensive noise reduction
197
- audio_data, _ = librosa.effects.trim(audio_data)
198
 
199
- # Normalize the audio data
200
- audio_data = librosa.util.normalize(audio_data)
201
 
202
- # Apply noise reduction
203
- audio_data = nr.reduce_noise(y=audio_data, sr=rate)
204
 
205
- return audio_data, rate
206
 
207
  # def preprocess_audio(audio_data, rate):
208
  # audio_data = nr.reduce_noise(y=audio_data, sr=rate)
 
27
  def load(file_name, skip_seconds=0):
28
  return librosa.load(file_name, sr=None, res_type='kaiser_fast')
29
 
30
+ def preprocess_audio(audio_data, rate):
31
+ # Apply preprocessing steps
32
+ audio_data = nr.reduce_noise(y=audio_data, sr=rate)
33
+ audio_data = librosa.util.normalize(audio_data)
34
+ audio_data, _ = librosa.effects.trim(audio_data)
35
+ audio_data = librosa.resample(audio_data, orig_sr=rate, target_sr=default_sample_rate)
36
+ # audio_data = fix_length(audio_data)
37
+ rate = default_sample_rate
38
 
39
+ return audio_data, rate
40
 
41
  def extract_features(X, sample_rate):
42
  # Generate Mel-frequency cepstral coefficients (MFCCs) from a time series
 
187
  scaler = joblib.load('app/1713696947.894978_scaler.joblib')
188
  label_encoder = joblib.load('app/1713696954.9487948_label_encoder.joblib')
189
 
190
+ # def preprocess_audio(audio_data, rate):
191
+ # # Resample first if the target rate is lower to reduce data size for subsequent operations
192
+ # if rate > default_sample_rate:
193
+ # audio_data = librosa.resample(audio_data, orig_sr=rate, target_sr=default_sample_rate)
194
+ # rate = default_sample_rate
195
 
196
+ # # Trim silence before applying computationally expensive noise reduction
197
+ # audio_data, _ = librosa.effects.trim(audio_data)
198
 
199
+ # # Normalize the audio data
200
+ # audio_data = librosa.util.normalize(audio_data)
201
 
202
+ # # Apply noise reduction
203
+ # audio_data = nr.reduce_noise(y=audio_data, sr=rate)
204
 
205
+ # return audio_data, rate
206
 
207
  # def preprocess_audio(audio_data, rate):
208
  # audio_data = nr.reduce_noise(y=audio_data, sr=rate)