Spaces:
Runtime error
Runtime error
debug
Browse files
app.py
CHANGED
|
@@ -12,20 +12,22 @@ asr = pipeline(
|
|
| 12 |
feature_extractor=processor.feature_extractor, decoder=processor.decoder
|
| 13 |
)
|
| 14 |
def run_asr(audio):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
if audio_array.shape
|
| 19 |
-
audio_array
|
| 20 |
-
|
| 21 |
-
audio_array
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
text_out = gr.outputs.Textbox(label="transcript")
|
| 31 |
interface = gr.Interface(
|
|
@@ -38,4 +40,4 @@ interface = gr.Interface(
|
|
| 38 |
flagging_options=["incorrect"]
|
| 39 |
)
|
| 40 |
|
| 41 |
-
interface.launch()
|
|
|
|
| 12 |
feature_extractor=processor.feature_extractor, decoder=processor.decoder
|
| 13 |
)
|
| 14 |
def run_asr(audio):
|
| 15 |
+
try:
|
| 16 |
+
sr, audio_array = audio
|
| 17 |
+
audio_array = audio_array.astype(np.float32)
|
| 18 |
+
if len(audio_array.shape) > 1:
|
| 19 |
+
if audio_array.shape[1] == 1:
|
| 20 |
+
audio_array = audio_array.squeeze()
|
| 21 |
+
elif audio_array.shape[1] == 2:
|
| 22 |
+
audio_array = to_mono(audio_array.T)
|
| 23 |
+
else:
|
| 24 |
+
raise ValueError("Audio with > 2 channels not supported")
|
| 25 |
+
if sr != 16_000:
|
| 26 |
+
audio_array = resample(audio_array, orig_sr=sr, target_sr=16_000)
|
| 27 |
+
res = asr(audio_array, chunk_length_s=20, stride_length_s=2)["text"]
|
| 28 |
+
except Exception as e:
|
| 29 |
+
res = e
|
| 30 |
+
return res
|
| 31 |
|
| 32 |
text_out = gr.outputs.Textbox(label="transcript")
|
| 33 |
interface = gr.Interface(
|
|
|
|
| 40 |
flagging_options=["incorrect"]
|
| 41 |
)
|
| 42 |
|
| 43 |
+
interface.launch(debug=True)
|