istupakov commited on
Commit
1ba0470
·
verified ·
1 Parent(s): 6c82f6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -57,6 +57,7 @@ def recognize(audio: tuple[int, np.ndarray], models, language):
57
  time = timer() - start
58
  logger.debug("recognized by %s: result '%s', time %.3f s.", name, result, time)
59
  results.append([name, result, f"{time:.3f} s."])
 
60
  except Exception as e:
61
  raise gr.Error(f"{e} Audio: sample_rate: {sample_rate}, waveform.shape: {waveform.shape}.") from e
62
  else:
@@ -82,16 +83,15 @@ def recognize_with_vad(audio: tuple[int, np.ndarray], name: str):
82
  if waveform.ndim == 2:
83
  waveform = waveform.mean(axis=1)
84
 
85
- model = models_vad[name].with_vad(vad)
86
- results = []
87
  for res in model.recognize(waveform, sample_rate=sample_rate):
88
  logger.debug("recognized by %s: result '%s'.", name, res)
89
- results.append([res.start, res.end, res.text])
 
90
 
91
  except Exception as e:
92
  raise gr.Error(f"{e} Audio: sample_rate: {sample_rate}, waveform.shape: {waveform.shape}.") from e
93
- else:
94
- return results
95
 
96
 
97
  with gr.Blocks() as recognize_short:
@@ -110,7 +110,7 @@ with gr.Blocks() as recognize_long:
110
  with gr.Row():
111
  gr.ClearButton(audio)
112
  btn = gr.Button("Recognize", variant="primary")
113
- output = gr.Dataframe(headers=["start", "end", "result"], wrap=True)
114
  btn.click(fn=recognize_with_vad, inputs=[audio, name], outputs=output)
115
 
116
  with gr.Blocks() as demo:
 
57
  time = timer() - start
58
  logger.debug("recognized by %s: result '%s', time %.3f s.", name, result, time)
59
  results.append([name, result, f"{time:.3f} s."])
60
+
61
  except Exception as e:
62
  raise gr.Error(f"{e} Audio: sample_rate: {sample_rate}, waveform.shape: {waveform.shape}.") from e
63
  else:
 
83
  if waveform.ndim == 2:
84
  waveform = waveform.mean(axis=1)
85
 
86
+ model = models_vad[name].with_vad(vad, batch_size=1)
87
+ results = ""
88
  for res in model.recognize(waveform, sample_rate=sample_rate):
89
  logger.debug("recognized by %s: result '%s'.", name, res)
90
+ results += f"[{res.start:5.1f}, {res.end:5.1f}]: {res.text}\n"
91
+ yield results
92
 
93
  except Exception as e:
94
  raise gr.Error(f"{e} Audio: sample_rate: {sample_rate}, waveform.shape: {waveform.shape}.") from e
 
 
95
 
96
 
97
  with gr.Blocks() as recognize_short:
 
110
  with gr.Row():
111
  gr.ClearButton(audio)
112
  btn = gr.Button("Recognize", variant="primary")
113
+ output = gr.TextArea(label="result") # headers=["start", "end", "result"], wrap=True, every=0.1)
114
  btn.click(fn=recognize_with_vad, inputs=[audio, name], outputs=output)
115
 
116
  with gr.Blocks() as demo: