Update app.py
Browse files
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 |
-
|
18 |
-
|
|
|
19 |
y = y.astype(np.float32)
|
20 |
y /= np.max(np.abs(y))
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
49 |
-
|
|
|
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()
|