Spaces:
Runtime error
Runtime error
Commit
·
c112a84
1
Parent(s):
3480b5a
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,10 +11,18 @@ import gradio as gr
|
|
| 11 |
|
| 12 |
|
| 13 |
def speech_file_to_array_fn(path, sampling_rate):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def predict(path, sampling_rate, feature_extractor, device, model, config):
|
| 20 |
speech = speech_file_to_array_fn(path, sampling_rate)
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def speech_file_to_array_fn(path, sampling_rate):
|
| 14 |
+
try:
|
| 15 |
+
speech_array, _sampling_rate = torchaudio.load(path)
|
| 16 |
+
resampler = torchaudio.transforms.Resample(_sampling_rate)
|
| 17 |
+
speech = resampler(speech_array).squeeze().numpy()
|
| 18 |
+
return speech
|
| 19 |
+
except:
|
| 20 |
+
speech_array, _sampling_rate = torchaudio.load(path)
|
| 21 |
+
resampler = torchaudio.transforms.Resample(_sampling_rate)
|
| 22 |
+
speech = resampler(speech_array[1]).squeeze().numpy()
|
| 23 |
+
return speech
|
| 24 |
+
|
| 25 |
+
|
| 26 |
|
| 27 |
def predict(path, sampling_rate, feature_extractor, device, model, config):
|
| 28 |
speech = speech_file_to_array_fn(path, sampling_rate)
|