app.py 566 Bytes
Newer Older
Sugon_ldc's avatar
Sugon_ldc committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import json
import gradio as gr
import numpy as np
import wenetruntime as wenet

wenet.set_log_level(2)
decoder = wenet.Decoder(lang='chs')

def recognition(audio):
    sr, y = audio
    assert sr in [48000, 16000]
    if sr == 48000:  # Optional resample to 16000
        y = (y / max(np.max(y), 1) * 32767)[::3].astype("int16")
    ans = decoder.decode(y.tobytes(), True)
    return json.loads(ans)

text = "Speech Recognition in WeNet | 基于 WeNet 的语音识别"
gr.Interface(recognition, inputs="mic", outputs="json",
             description=text).launch()