Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,12 +8,11 @@ import random
|
|
8 |
|
9 |
model = AutoModelForAudioClassification.from_pretrained("./")
|
10 |
|
11 |
-
def custom_feature_extraction(
|
12 |
-
|
13 |
-
S = librosa.feature.melspectrogram(y=waveform, sr=sample_rate, n_mels=n_mels, n_fft=n_fft, hop_length=hop_length)
|
14 |
S_DB = librosa.power_to_db(S, ref=np.max)
|
15 |
-
pitches, _ = librosa.piptrack(y=
|
16 |
-
spectral_centroids = librosa.feature.spectral_centroid(y=
|
17 |
features = np.concatenate([S_DB, pitches, spectral_centroids], axis=0)
|
18 |
features_tensor = torch.tensor(features).float()
|
19 |
if features_tensor.shape[1] > target_length:
|
@@ -30,7 +29,7 @@ def predict_voice(audio_file_path):
|
|
30 |
try:
|
31 |
waveform, sample_rate = librosa.load(audio_file_path, sr=None)
|
32 |
augmented_waveform = apply_time_shift(waveform)
|
33 |
-
original_features = custom_feature_extraction(
|
34 |
augmented_features = custom_feature_extraction(augmented_waveform, sr=sample_rate)
|
35 |
with torch.no_grad():
|
36 |
outputs_original = model(original_features)
|
|
|
8 |
|
9 |
model = AutoModelForAudioClassification.from_pretrained("./")
|
10 |
|
11 |
+
def custom_feature_extraction(audio, sr=16000, n_mels=128, n_fft=2048, hop_length=512, target_length=1024):
|
12 |
+
S = librosa.feature.melspectrogram(y=audio, sr=sr, n_mels=n_mels, n_fft=n_fft, hop_length=hop_length)
|
|
|
13 |
S_DB = librosa.power_to_db(S, ref=np.max)
|
14 |
+
pitches, _ = librosa.piptrack(y=audio, sr=sr, n_fft=n_fft, hop_length=hop_length)
|
15 |
+
spectral_centroids = librosa.feature.spectral_centroid(y=audio, sr=sr, n_fft=n_fft, hop_length=hop_length)
|
16 |
features = np.concatenate([S_DB, pitches, spectral_centroids], axis=0)
|
17 |
features_tensor = torch.tensor(features).float()
|
18 |
if features_tensor.shape[1] > target_length:
|
|
|
29 |
try:
|
30 |
waveform, sample_rate = librosa.load(audio_file_path, sr=None)
|
31 |
augmented_waveform = apply_time_shift(waveform)
|
32 |
+
original_features = custom_feature_extraction(waveform, sr=sample_rate)
|
33 |
augmented_features = custom_feature_extraction(augmented_waveform, sr=sample_rate)
|
34 |
with torch.no_grad():
|
35 |
outputs_original = model(original_features)
|