wang0507 commited on
Commit
e35df71
·
1 Parent(s): 8c387c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -14,12 +14,17 @@ p = pipeline("automatic-speech-recognition", model=model)
14
 
15
  transcriber = pipeline("automatic-speech-recognition", model=model)
16
 
17
- def transcribe(audio):
18
- sr, y = audio
 
19
  y = y.astype(np.float32)
20
  y /= np.max(np.abs(y))
21
 
22
- return transcriber({"sampling_rate": sr, "raw": y})["text"]
 
 
 
 
23
 
24
 
25
 
@@ -45,8 +50,9 @@ with gr.Blocks() as demo:
45
  with gr.Tab("Real Time Speech Recognition"):
46
  with gr.Row():
47
  transcribe,
48
- gr.Audio(sources=["microphone"]),
49
- "text",
 
50
 
51
 
52
  demo.launch()
 
14
 
15
  transcriber = pipeline("automatic-speech-recognition", model=model)
16
 
17
+
18
+ def transcribe(stream, new_chunk):
19
+ sr, y = new_chunk
20
  y = y.astype(np.float32)
21
  y /= np.max(np.abs(y))
22
 
23
+ if stream is not None:
24
+ stream = np.concatenate([stream, y])
25
+ else:
26
+ stream = y
27
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
28
 
29
 
30
 
 
50
  with gr.Tab("Real Time Speech Recognition"):
51
  with gr.Row():
52
  transcribe,
53
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
54
+ ["state", "text"],
55
+ live=True
56
 
57
 
58
  demo.launch()