Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-tiny.en")
|
6 |
+
|
7 |
+
def transcribe(audio):
|
8 |
+
sr, y = audio
|
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 |
+
return transcriber({"sampling_rate": sr, "raw": y})["text"]
|
18 |
+
|
19 |
+
demo = gr.Interface(
|
20 |
+
transcribe,
|
21 |
+
gr.Audio(sources="microphone"),
|
22 |
+
"text",
|
23 |
+
)
|
24 |
+
|
25 |
+
demo.launch(share=True)
|
26 |
+
|
27 |
+
|