Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
|
|
3 |
|
4 |
-
|
5 |
-
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")
|
6 |
-
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
|
7 |
|
8 |
-
def transcribe(
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
predicted_ids = torch.argmax(logits, dim=-1)
|
13 |
-
transcription = processor.batch_decode(predicted_ids)
|
14 |
-
|
15 |
-
return transcription[0]
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import numpy as np
|
4 |
|
5 |
+
transcriber = pipeline("automatic-speech-recognition", model="facebook/xm_transformer_s2ut_hk-en")
|
|
|
|
|
6 |
|
7 |
+
def transcribe(stream, new_chunk):
|
8 |
+
sr, y = new_chunk
|
9 |
+
y = y.astype(np.float32)
|
10 |
+
y /= np.max(np.abs(y))
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
if stream is not None:
|
13 |
+
stream = np.concatenate([stream, y])
|
14 |
+
else:
|
15 |
+
stream = y
|
16 |
+
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
|
17 |
+
|
18 |
+
|
19 |
+
demo = gr.Interface(
|
20 |
+
transcribe,
|
21 |
+
["state", gr.Audio(sources=["microphone"], streaming=True)],
|
22 |
+
["state", "text"],
|
23 |
+
live=True,
|
24 |
+
)
|
25 |
+
|
26 |
+
demo.launch()
|