arampacha commited on
Commit
6b3bdcb
·
1 Parent(s): 868269b
Files changed (1) hide show
  1. app.py +17 -15
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
- sr, audio_array = audio
16
- audio_array = audio_array.astype(np.float32)
17
- if len(audio_array.shape) > 1:
18
- if audio_array.shape[1] == 1:
19
- audio_array = audio_array.squeeze()
20
- elif audio_array.shape[1] == 2:
21
- audio_array = to_mono(audio_array.T)
22
- else:
23
- raise ValueError("Audio with > 2 channels not supported")
24
- if sr != 16_000:
25
- audio_array = resample(audio_array, orig_sr=sr, target_sr=16_000)
26
- res = asr(audio_array, chunk_length_s=20, stride_length_s=2)
27
-
28
- return res["text"]
 
 
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)