Spaces:
Runtime error
Runtime error
File size: 1,379 Bytes
94d47c9 897e744 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from stt import Model
import gradio as gr
import numpy as np
model = 'stt-comodoro-czech-2022-05-31.tflite'
scorer = 'czech-large-vocab.scorer'
beam_width = 512
lm_alpha = 0.94
lm_beta = 2.52
model = Model(model)
model.enableExternalScorer(scorer)
model.setScorerAlphaBeta(lm_alpha, lm_beta)
model.setBeamWidth(beam_width)
def reformat_freq(sr, y):
if sr not in (
48000,
16000,
): # Deepspeech only supports 16k, (we convert 48k -> 16k)
raise ValueError("Unsupported rate", sr)
if sr == 48000:
y = (
((y / max(np.max(y), 1)) * 32767)
.reshape((-1, 3))
.mean(axis=1)
.astype("int16")
)
sr = 16000
return sr, y
def transcribe(speech):
_, y = reformat_freq(*speech)
stream = model.createStream()
stream.feedAudioContent(y)
text = stream.intermediateDecode()
return text
with gr.Blocks() as blocks:
audio = gr.Audio(source="microphone", type="numpy", streaming=False,
label='Pokud je to třeba, povolte mikrofon pro tuto stránku, \
klikněte na Record from microphone, po dokončení nahrávání na Stop recording a poté na Rozpoznat')
btn = gr.Button('Rozpoznat')
output = gr.Textbox(show_label=False)
btn.click(fn=transcribe, inputs=[audio],
outputs=[output])
blocks.launch(enable_queue=True, debug=True, share=True) |