pierrelf commited on
Commit
f2fd281
·
1 Parent(s): ea92cff

Update transcribe function to support audio

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -7,18 +7,23 @@ transcriber = pipeline(
7
  )
8
 
9
 
10
- def transcribe(audio):
11
- sr, y = audio
12
  y = y.astype(np.float32)
13
  y /= np.max(np.abs(y))
14
 
15
- return transcriber({"sampling_rate": sr, "raw": y})["text"]
 
 
 
 
16
 
17
 
18
  demo = gr.Interface(
19
  transcribe,
20
- gr.Audio(sources=["microphone"]),
21
- "text",
 
22
  )
23
 
24
  demo.launch()
 
7
  )
8
 
9
 
10
+ def transcribe(stream, new_chunk):
11
+ sr, y = new_chunk
12
  y = y.astype(np.float32)
13
  y /= np.max(np.abs(y))
14
 
15
+ if stream is not None:
16
+ stream = np.concatenate([stream, y])
17
+ else:
18
+ stream = y
19
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
20
 
21
 
22
  demo = gr.Interface(
23
  transcribe,
24
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
25
+ ["state", "text"],
26
+ live=True,
27
  )
28
 
29
  demo.launch()