Konstantin Dorichev commited on
Block based app
Browse files
app.py
CHANGED
|
@@ -6,9 +6,11 @@ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-bas
|
|
| 6 |
|
| 7 |
|
| 8 |
def transcribe(stream, new_chunk):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Convert to mono if stereo
|
| 14 |
if y.ndim > 1:
|
|
@@ -17,20 +19,27 @@ def transcribe(stream, new_chunk):
|
|
| 17 |
y = y.astype(np.float32)
|
| 18 |
y /= np.max(np.abs(y))
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
demo.launch()
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def transcribe(stream, new_chunk):
|
| 9 |
+
|
| 10 |
+
if stream is None:
|
| 11 |
+
return ""
|
| 12 |
+
|
| 13 |
+
sr, y = stream
|
| 14 |
|
| 15 |
# Convert to mono if stereo
|
| 16 |
if y.ndim > 1:
|
|
|
|
| 19 |
y = y.astype(np.float32)
|
| 20 |
y /= np.max(np.abs(y))
|
| 21 |
|
| 22 |
+
text = transcriber({"sampling_rate": sr, "raw": y})["text"]
|
| 23 |
+
return text
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def clear(audio, transcribed):
|
| 27 |
+
audio = None
|
| 28 |
+
transcribed = None
|
| 29 |
+
return audio, transcribed
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
with gr.Blocks() as demo:
|
| 33 |
+
gr.HTML(value="<h1>Transcribe Audio to Text Demo</h1>")
|
| 34 |
+
with gr.Row():
|
| 35 |
+
with gr.Column():
|
| 36 |
+
audio = gr.Audio(sources=["upload"], streaming=False, label="wav")
|
| 37 |
+
with gr.Row():
|
| 38 |
+
clr = gr.Button(value="Clear", variant="huggingface")
|
| 39 |
+
btn = gr.Button(value="Transcribe", variant="primary")
|
| 40 |
+
transcribed = gr.TextArea(label="Transcribed", lines=9)
|
| 41 |
+
|
| 42 |
+
btn.click(fn=transcribe, inputs=audio, outputs=transcribed)
|
| 43 |
+
clr.click(fn=clear, inputs=[audio, transcribed], outputs=[audio, transcribed])
|
| 44 |
|
| 45 |
demo.launch()
|