Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import numpy as np
|
4 |
-
|
5 |
-
|
6 |
|
7 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
|
8 |
|
9 |
-
def transcribe(
|
10 |
"""Transcribe audio bytes to text using Google Cloud Speech to Text."""
|
11 |
|
12 |
sr, y = audio_bytes
|
13 |
y = y.astype(np.float32)
|
14 |
y /= np.max(np.abs(y))
|
15 |
-
|
16 |
-
|
17 |
-
else:
|
18 |
-
stream = y
|
19 |
-
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
|
20 |
|
21 |
|
22 |
demo = gr.Interface(
|
23 |
transcribe,
|
24 |
-
|
25 |
-
|
26 |
live=True,
|
27 |
)
|
28 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import numpy as np
|
4 |
+
from google.cloud import speech_v1
|
5 |
+
from google.protobuf import timestamp_pb2
|
6 |
|
7 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
|
8 |
|
9 |
+
def transcribe(audio_bytes):
|
10 |
"""Transcribe audio bytes to text using Google Cloud Speech to Text."""
|
11 |
|
12 |
sr, y = audio_bytes
|
13 |
y = y.astype(np.float32)
|
14 |
y /= np.max(np.abs(y))
|
15 |
+
|
16 |
+
return transcriber({"sampling_rate": sr, "raw": y})["text"]
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
demo = gr.Interface(
|
20 |
transcribe,
|
21 |
+
gr.Audio(sources=["microphone"], streaming=False),
|
22 |
+
"text",
|
23 |
live=True,
|
24 |
)
|
25 |
|