Futuresony commited on
Commit
6c32e04
·
verified ·
1 Parent(s): f9ca152

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+
5
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
6
+
7
+ def transcribe(stream, new_chunk):
8
+ sr, y = new_chunk
9
+
10
+ # Convert to mono if stereo
11
+ if y.ndim > 1:
12
+ y = y.mean(axis=1)
13
+
14
+ y = y.astype(np.float32)
15
+ y /= np.max(np.abs(y))
16
+
17
+ if stream is not None:
18
+ stream = np.concatenate([stream, y])
19
+ else:
20
+ stream = y
21
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
22
+
23
+ demo = gr.Interface(
24
+ transcribe,
25
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
26
+ ["state", "text"],
27
+ live=True,
28
+ )
29
+
30
+ demo.launch()