Update app.py
Browse files
app.py
CHANGED
@@ -29,14 +29,15 @@ models_ru = {
|
|
29 |
}
|
30 |
|
31 |
models_en = {
|
32 |
-
name: onnx_asr.load_model(name
|
33 |
for name in [
|
34 |
"nemo-parakeet-ctc-0.6b",
|
35 |
"nemo-parakeet-rnnt-0.6b",
|
|
|
36 |
]
|
37 |
}
|
38 |
|
39 |
-
models_vad =
|
40 |
|
41 |
|
42 |
def recognize(audio: tuple[int, np.ndarray], models, language):
|
@@ -44,7 +45,8 @@ def recognize(audio: tuple[int, np.ndarray], models, language):
|
|
44 |
return None
|
45 |
|
46 |
sample_rate, waveform = audio
|
47 |
-
|
|
|
48 |
try:
|
49 |
waveform = waveform.astype(np.float32) / 2 ** (8 * waveform.itemsize - 1)
|
50 |
if waveform.ndim == 2:
|
@@ -52,6 +54,8 @@ def recognize(audio: tuple[int, np.ndarray], models, language):
|
|
52 |
|
53 |
results = []
|
54 |
for name, model in models.items():
|
|
|
|
|
55 |
start = timer()
|
56 |
result = model.recognize(waveform, sample_rate=sample_rate, language=language)
|
57 |
time = timer() - start
|
@@ -95,7 +99,7 @@ def recognize_with_vad(audio: tuple[int, np.ndarray], name: str):
|
|
95 |
|
96 |
|
97 |
with gr.Blocks() as recognize_short:
|
98 |
-
audio = gr.Audio(min_length=1, max_length=
|
99 |
with gr.Row():
|
100 |
gr.ClearButton(audio)
|
101 |
btn_ru = gr.Button("Recognize (ru)", variant="primary")
|
@@ -104,15 +108,28 @@ with gr.Blocks() as recognize_short:
|
|
104 |
btn_ru.click(fn=recognize_ru, inputs=audio, outputs=output)
|
105 |
btn_en.click(fn=recognize_en, inputs=audio, outputs=output)
|
106 |
|
|
|
107 |
with gr.Blocks() as recognize_long:
|
108 |
name = gr.Dropdown(models_vad.keys(), label="Model")
|
|
|
109 |
audio = gr.Audio(min_length=1, max_length=300)
|
110 |
with gr.Row():
|
111 |
gr.ClearButton(audio)
|
112 |
btn = gr.Button("Recognize", variant="primary")
|
113 |
-
output = gr.TextArea(label="result")
|
114 |
btn.click(fn=recognize_with_vad, inputs=[audio, name], outputs=output)
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
with gr.Blocks() as demo:
|
117 |
gr.Markdown("""
|
118 |
# ASR demo using onnx-asr
|
@@ -122,22 +139,25 @@ with gr.Blocks() as demo:
|
|
122 |
gr.TabbedInterface(
|
123 |
[recognize_short, recognize_long],
|
124 |
[
|
125 |
-
"Recognition of a short phrase (up to
|
126 |
"Recognition of a long phrase with VAD (up to 5 min.)",
|
127 |
],
|
128 |
)
|
129 |
-
with gr.Accordion("Models used in this demo
|
130 |
gr.Markdown("""
|
131 |
-
## ASR models
|
132 |
* `gigaam-v2-ctc` - Sber GigaAM v2 CTC ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
|
133 |
* `gigaam-v2-rnnt` - Sber GigaAM v2 RNN-T ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
|
134 |
* `nemo-fastconformer-ru-ctc` - Nvidia FastConformer-Hybrid Large (ru) with CTC decoder ([origin](https://huggingface.co/nvidia/stt_ru_fastconformer_hybrid_large_pc), [onnx](https://huggingface.co/istupakov/stt_ru_fastconformer_hybrid_large_pc_onnx))
|
135 |
* `nemo-fastconformer-ru-rnnt` - Nvidia FastConformer-Hybrid Large (ru) with RNN-T decoder ([origin](https://huggingface.co/nvidia/stt_ru_fastconformer_hybrid_large_pc), [onnx](https://huggingface.co/istupakov/stt_ru_fastconformer_hybrid_large_pc_onnx))
|
136 |
-
* `nemo-parakeet-ctc-0.6b` - Nvidia Parakeet CTC 0.6B (en) ([origin](https://huggingface.co/nvidia/parakeet-ctc-0.6b), [onnx](https://huggingface.co/istupakov/parakeet-ctc-0.6b-onnx))
|
137 |
-
* `nemo-parakeet-rnnt-0.6b` - Nvidia Parakeet RNNT 0.6B (en) ([origin](https://huggingface.co/nvidia/parakeet-rnnt-0.6b), [onnx](https://huggingface.co/istupakov/parakeet-rnnt-0.6b-onnx))
|
138 |
* `whisper-base` - OpenAI Whisper Base exported with onnxruntime ([origin](https://huggingface.co/openai/whisper-base), [onnx](https://huggingface.co/istupakov/whisper-base-onnx))
|
139 |
* `alphacep/vosk-model-ru` - Alpha Cephei Vosk 0.54-ru ([origin](https://huggingface.co/alphacep/vosk-model-ru))
|
140 |
* `alphacep/vosk-model-small-ru` - Alpha Cephei Vosk 0.52-small-ru ([origin](https://huggingface.co/alphacep/vosk-model-small-ru))
|
|
|
|
|
|
|
|
|
|
|
141 |
## VAD models
|
142 |
* `silero` - Silero VAD ([origin](https://github.com/snakers4/silero-vad), [onnx](https://huggingface.co/onnx-community/silero-vad))
|
143 |
""")
|
|
|
29 |
}
|
30 |
|
31 |
models_en = {
|
32 |
+
name: onnx_asr.load_model(name)
|
33 |
for name in [
|
34 |
"nemo-parakeet-ctc-0.6b",
|
35 |
"nemo-parakeet-rnnt-0.6b",
|
36 |
+
"nemo-parakeet-tdt-0.6b-v2",
|
37 |
]
|
38 |
}
|
39 |
|
40 |
+
models_vad = whisper | models_ru | models_en
|
41 |
|
42 |
|
43 |
def recognize(audio: tuple[int, np.ndarray], models, language):
|
|
|
45 |
return None
|
46 |
|
47 |
sample_rate, waveform = audio
|
48 |
+
length = waveform.shape[-1] / sample_rate
|
49 |
+
logger.debug("recognize: length %.3f, sample_rate %s, waveform.shape %s.", length, sample_rate, waveform.shape)
|
50 |
try:
|
51 |
waveform = waveform.astype(np.float32) / 2 ** (8 * waveform.itemsize - 1)
|
52 |
if waveform.ndim == 2:
|
|
|
54 |
|
55 |
results = []
|
56 |
for name, model in models.items():
|
57 |
+
if length > 20 and name == "alphacep/vosk-model-small-ru":
|
58 |
+
continue
|
59 |
start = timer()
|
60 |
result = model.recognize(waveform, sample_rate=sample_rate, language=language)
|
61 |
time = timer() - start
|
|
|
99 |
|
100 |
|
101 |
with gr.Blocks() as recognize_short:
|
102 |
+
audio = gr.Audio(min_length=1, max_length=30)
|
103 |
with gr.Row():
|
104 |
gr.ClearButton(audio)
|
105 |
btn_ru = gr.Button("Recognize (ru)", variant="primary")
|
|
|
108 |
btn_ru.click(fn=recognize_ru, inputs=audio, outputs=output)
|
109 |
btn_en.click(fn=recognize_en, inputs=audio, outputs=output)
|
110 |
|
111 |
+
|
112 |
with gr.Blocks() as recognize_long:
|
113 |
name = gr.Dropdown(models_vad.keys(), label="Model")
|
114 |
+
# lang = gr.Label()
|
115 |
audio = gr.Audio(min_length=1, max_length=300)
|
116 |
with gr.Row():
|
117 |
gr.ClearButton(audio)
|
118 |
btn = gr.Button("Recognize", variant="primary")
|
119 |
+
output = gr.TextArea(label="result")
|
120 |
btn.click(fn=recognize_with_vad, inputs=[audio, name], outputs=output)
|
121 |
|
122 |
+
def on_model_change(name: str):
|
123 |
+
if name in models_ru:
|
124 |
+
label = f"Model {name} support only Russian language"
|
125 |
+
elif name in models_en:
|
126 |
+
label = f"Model {name} support only English language"
|
127 |
+
else:
|
128 |
+
label = None
|
129 |
+
return gr.Audio(min_length=1, max_length=300, label=label)
|
130 |
+
|
131 |
+
name.change(on_model_change, inputs=name, outputs=audio)
|
132 |
+
|
133 |
with gr.Blocks() as demo:
|
134 |
gr.Markdown("""
|
135 |
# ASR demo using onnx-asr
|
|
|
139 |
gr.TabbedInterface(
|
140 |
[recognize_short, recognize_long],
|
141 |
[
|
142 |
+
"Recognition of a short phrase (up to 30 sec.)",
|
143 |
"Recognition of a long phrase with VAD (up to 5 min.)",
|
144 |
],
|
145 |
)
|
146 |
+
with gr.Accordion("Models used in this demo:", open=False):
|
147 |
gr.Markdown("""
|
148 |
+
## Russian ASR models
|
149 |
* `gigaam-v2-ctc` - Sber GigaAM v2 CTC ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
|
150 |
* `gigaam-v2-rnnt` - Sber GigaAM v2 RNN-T ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
|
151 |
* `nemo-fastconformer-ru-ctc` - Nvidia FastConformer-Hybrid Large (ru) with CTC decoder ([origin](https://huggingface.co/nvidia/stt_ru_fastconformer_hybrid_large_pc), [onnx](https://huggingface.co/istupakov/stt_ru_fastconformer_hybrid_large_pc_onnx))
|
152 |
* `nemo-fastconformer-ru-rnnt` - Nvidia FastConformer-Hybrid Large (ru) with RNN-T decoder ([origin](https://huggingface.co/nvidia/stt_ru_fastconformer_hybrid_large_pc), [onnx](https://huggingface.co/istupakov/stt_ru_fastconformer_hybrid_large_pc_onnx))
|
|
|
|
|
153 |
* `whisper-base` - OpenAI Whisper Base exported with onnxruntime ([origin](https://huggingface.co/openai/whisper-base), [onnx](https://huggingface.co/istupakov/whisper-base-onnx))
|
154 |
* `alphacep/vosk-model-ru` - Alpha Cephei Vosk 0.54-ru ([origin](https://huggingface.co/alphacep/vosk-model-ru))
|
155 |
* `alphacep/vosk-model-small-ru` - Alpha Cephei Vosk 0.52-small-ru ([origin](https://huggingface.co/alphacep/vosk-model-small-ru))
|
156 |
+
## English ASR models
|
157 |
+
* `nemo-parakeet-ctc-0.6b` - Nvidia Parakeet CTC 0.6B (en) ([origin](https://huggingface.co/nvidia/parakeet-ctc-0.6b), [onnx](https://huggingface.co/istupakov/parakeet-ctc-0.6b-onnx))
|
158 |
+
* `nemo-parakeet-rnnt-0.6b` - Nvidia Parakeet RNNT 0.6B (en) ([origin](https://huggingface.co/nvidia/parakeet-rnnt-0.6b), [onnx](https://huggingface.co/istupakov/parakeet-rnnt-0.6b-onnx))
|
159 |
+
* `nemo-parakeet-tdt-0.6b-v2` - Nvidia Parakeet TDT 0.6B V2 (en) ([origin](https://huggingface.co/nvidia/parakeet-tdt-0.6b-v2), [onnx](https://huggingface.co/istupakov/parakeet-tdt-0.6b-v2-onnx))
|
160 |
+
* `whisper-base` - OpenAI Whisper Base exported with onnxruntime ([origin](https://huggingface.co/openai/whisper-base), [onnx](https://huggingface.co/istupakov/whisper-base-onnx))
|
161 |
## VAD models
|
162 |
* `silero` - Silero VAD ([origin](https://github.com/snakers4/silero-vad), [onnx](https://huggingface.co/onnx-community/silero-vad))
|
163 |
""")
|