Spaces:
Runtime error
Runtime error
Simplest speech to text example
Browse files- .gitignore +1 -0
- app.py +28 -0
- packages.txt +1 -0
- requirements.txt +2 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
/venv
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline, AutoFeatureExtractor, AutoTokenizer, Wav2Vec2ForCTC
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
model_id = 'comodoro/wav2vec2-xls-r-300m-cs-250'
|
| 6 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
|
| 7 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_id)
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 9 |
+
|
| 10 |
+
p = pipeline("automatic-speech-recognition", chunk_length_s=5, model=model,
|
| 11 |
+
tokenizer=tokenizer, feature_extractor=feature_extractor)
|
| 12 |
+
|
| 13 |
+
def transcribe(audio, state=""):
|
| 14 |
+
time.sleep(2)
|
| 15 |
+
text = p(audio)["text"]
|
| 16 |
+
state += text + " "
|
| 17 |
+
return state
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as blocks:
|
| 20 |
+
audio = gr.Audio(source="microphone", type="filepath",
|
| 21 |
+
label='Pokud je to třeba, povolte mikrofon pro tuto stránku, \
|
| 22 |
+
klikněte na Record from microphone, po dokončení nahrávání na Stop recording a poté na Rozpoznat')
|
| 23 |
+
btn = gr.Button('Rozpoznat')
|
| 24 |
+
output = gr.Textbox(show_label=False)
|
| 25 |
+
btn.click(fn=transcribe, inputs=[audio,],
|
| 26 |
+
outputs=[output,])
|
| 27 |
+
|
| 28 |
+
blocks.launch(enable_queue=True, debug=True)
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|