Spaces:
Runtime error
Runtime error
Update transcribe function to support audio
Browse files
app.py
CHANGED
|
@@ -7,18 +7,23 @@ transcriber = pipeline(
|
|
| 7 |
)
|
| 8 |
|
| 9 |
|
| 10 |
-
def transcribe(
|
| 11 |
-
sr, y =
|
| 12 |
y = y.astype(np.float32)
|
| 13 |
y /= np.max(np.abs(y))
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
transcribe,
|
| 20 |
-
gr.Audio(sources=["microphone"]),
|
| 21 |
-
"text",
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
demo.launch()
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
|
| 10 |
+
def transcribe(stream, new_chunk):
|
| 11 |
+
sr, y = new_chunk
|
| 12 |
y = y.astype(np.float32)
|
| 13 |
y /= np.max(np.abs(y))
|
| 14 |
|
| 15 |
+
if stream is not None:
|
| 16 |
+
stream = np.concatenate([stream, y])
|
| 17 |
+
else:
|
| 18 |
+
stream = y
|
| 19 |
+
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
|
| 20 |
|
| 21 |
|
| 22 |
demo = gr.Interface(
|
| 23 |
transcribe,
|
| 24 |
+
["state", gr.Audio(sources=["microphone"], streaming=True)],
|
| 25 |
+
["state", "text"],
|
| 26 |
+
live=True,
|
| 27 |
)
|
| 28 |
|
| 29 |
demo.launch()
|