Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(audio1, audio2):
|
| 8 |
+
sr1, y1 = audio1
|
| 9 |
+
sr2, y2 = audio2
|
| 10 |
+
|
| 11 |
+
def convertToMono(y):
|
| 12 |
+
if y.ndim > 1:
|
| 13 |
+
y = y.mean(axis=1)
|
| 14 |
+
|
| 15 |
+
y = y.astype(np.float32)
|
| 16 |
+
y /= np.max(np.abs(y))
|
| 17 |
+
return y
|
| 18 |
+
# Convert to mono if stereo
|
| 19 |
+
y1 = convertToMono(y1)
|
| 20 |
+
y2 = convertToMono(y2)
|
| 21 |
+
|
| 22 |
+
text1 = transcriber({"sampling_rate": sr1, "raw": y1})["text"]
|
| 23 |
+
text2 = transcriber({"sampling_rate": sr1, "raw": y2})["text"]
|
| 24 |
+
return text1 + " -- " + text2
|
| 25 |
+
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
transcribe,
|
| 28 |
+
[gr.Audio(sources="upload"), gr.Audio(sources="upload")],
|
| 29 |
+
["text"],
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
demo.launch()
|