papasega commited on
Commit
9876963
1 Parent(s): 5111bf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -22,15 +22,20 @@ import gradio as gr
22
 
23
  model = EncoderASR.from_hparams("speechbrain/asr-wav2vec2-dvoice-wolof")
24
 
25
- def transcribe(audio_or_file):
26
- if isinstance(audio_or_file, str): # If input is a file path
27
- return model.transcribe_file(audio_or_file)
28
- else: # If input is audio from microphone
29
- return model.transcribe_array(audio_or_file)
 
 
 
 
 
30
 
31
  demo = gr.Interface(
32
  transcribe,
33
- ["state", gr.inputs.Microphone(source="local", type="wav"), "text"],
34
  ["state", "text"],
35
  live=True,
36
  )
 
22
 
23
  model = EncoderASR.from_hparams("speechbrain/asr-wav2vec2-dvoice-wolof")
24
 
25
+ def transcribe(stream, new_chunk):
26
+ sr, y = new_chunk
27
+ y = y.astype(np.float32)
28
+ y /= np.max(np.abs(y))
29
+
30
+ if stream is not None:
31
+ stream = np.concatenate([stream, y])
32
+ else:
33
+ stream = y
34
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
35
 
36
  demo = gr.Interface(
37
  transcribe,
38
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
39
  ["state", "text"],
40
  live=True,
41
  )