Spaces:
Running
Running
Liangcd
commited on
Commit
•
a487abc
1
Parent(s):
df3e2ff
[demo] Initialize the first version
Browse files- app.py +62 -0
- examples/BAC009S0764W0121.wav +0 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import json
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import wenetruntime as wenet
|
6 |
+
|
7 |
+
wenet.set_log_level(2)
|
8 |
+
decoder = wenet.Decoder(lang='chs')
|
9 |
+
|
10 |
+
|
11 |
+
def recognition(audio):
|
12 |
+
print(audio)
|
13 |
+
if audio is None:
|
14 |
+
return "Input Error! Please enter one audio!"
|
15 |
+
sr, y = audio
|
16 |
+
assert sr in [48000, 16000]
|
17 |
+
if sr == 48000: # Optional resample to 16000
|
18 |
+
y = (y / max(np.max(y), 1) * 32767)[::3].astype("int16")
|
19 |
+
ans = decoder.decode(y.tobytes(), True)
|
20 |
+
if ans == None:
|
21 |
+
return "ERROR! No text output! Please try again!"
|
22 |
+
# ans (json)
|
23 |
+
# {
|
24 |
+
# 'nbest' : [{"sentence" : ""}], 'type' : 'final_result
|
25 |
+
# }
|
26 |
+
ans = json.loads(ans)
|
27 |
+
print(ans)
|
28 |
+
txt = ans['nbest'][0]['sentence']
|
29 |
+
return txt
|
30 |
+
|
31 |
+
|
32 |
+
# input
|
33 |
+
inputs = [
|
34 |
+
gr.inputs.Audio(source="microphone",
|
35 |
+
type="numpy",
|
36 |
+
label='Speaker#1')
|
37 |
+
]
|
38 |
+
|
39 |
+
output = gr.outputs.Textbox(label="Output Text")
|
40 |
+
|
41 |
+
# examples = ['examples/BAC009S0764W0121.wav']
|
42 |
+
text = "Speech Recognition in WeNet | 基于 WeNet 的语音识别"
|
43 |
+
|
44 |
+
# description
|
45 |
+
description = ("WeSpeaker Demo ! Try it with your own voice !")
|
46 |
+
|
47 |
+
article = (
|
48 |
+
"<p style='text-align: center'>"
|
49 |
+
"<a href='https://github.com/wenet-e2e/wespeaker' target='_blank'>Github: Learn more about WeSpeaker</a>"
|
50 |
+
"</p>")
|
51 |
+
|
52 |
+
interface = gr.Interface(
|
53 |
+
fn=recognition,
|
54 |
+
inputs=inputs,
|
55 |
+
outputs=output,
|
56 |
+
title=text,
|
57 |
+
description=description,
|
58 |
+
article=article,
|
59 |
+
theme='huggingface',
|
60 |
+
)
|
61 |
+
|
62 |
+
interface.launch(enable_queue=True)
|
examples/BAC009S0764W0121.wav
ADDED
Binary file (135 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
wenetruntime
|
2 |
+
gradio
|