Liangcd commited on
Commit
8775cab
1 Parent(s): b72dbd0

[demo] support English

Browse files
app.py CHANGED
@@ -18,18 +18,23 @@ import gradio as gr
18
  import wenetruntime as wenet
19
  import librosa
20
 
21
-
22
  wenet.set_log_level(2)
23
  decoder_cn = wenet.Decoder(lang='chs')
 
24
 
25
 
26
- def recognition(audio):
27
  if audio is None:
28
  return "Input Error! Please enter one audio!"
29
  y, _ = librosa.load(audio, sr=16000)
30
  # NOTE: model supports 16k sample_rate
31
  y = (y * (1 << 15)).astype("int16")
32
- ans = decoder_cn.decode(y.tobytes(), True)
 
 
 
 
 
33
  if ans is None:
34
  return "ERROR! No text output! Please try again!"
35
  # NOTE: ans (json)
@@ -42,20 +47,28 @@ def recognition(audio):
42
 
43
 
44
  # input
45
- inputs = gr.inputs.Audio(source="microphone", type="filepath", label='Input audio')
 
 
 
46
 
47
  output = gr.outputs.Textbox(label="Output Text")
48
 
49
  examples = [
50
- ['examples/BAC009S0767W0127.wav'],
51
- ['examples/BAC009S0767W0424.wav'],
52
- ['examples/BAC009S0767W0488.wav'],
 
 
 
53
  ]
54
 
55
  text = "Speech Recognition in WeNet | 基于 WeNet 的语音识别"
56
 
57
  # description
58
- description = ("Wenet Demo ! This is a Mandarin streaming speech recognition !")
 
 
59
 
60
  article = (
61
  "<p style='text-align: center'>"
 
18
  import wenetruntime as wenet
19
  import librosa
20
 
 
21
  wenet.set_log_level(2)
22
  decoder_cn = wenet.Decoder(lang='chs')
23
+ decoder_en = wenet.Decoder(lang='en')
24
 
25
 
26
+ def recognition(audio, lang='CN'):
27
  if audio is None:
28
  return "Input Error! Please enter one audio!"
29
  y, _ = librosa.load(audio, sr=16000)
30
  # NOTE: model supports 16k sample_rate
31
  y = (y * (1 << 15)).astype("int16")
32
+ if lang == 'CN':
33
+ ans = decoder_cn.decode(y.tobytes(), True)
34
+ elif lang == 'EN':
35
+ ans = decoder_en.decode(y.tobytes(), True)
36
+ else:
37
+ return "ERROR! Please select a language!"
38
  if ans is None:
39
  return "ERROR! No text output! Please try again!"
40
  # NOTE: ans (json)
 
47
 
48
 
49
  # input
50
+ inputs = [
51
+ gr.inputs.Audio(source="microphone", type="filepath", label='Input audio'),
52
+ gr.Radio(['EN', 'CN'], label='Language')
53
+ ]
54
 
55
  output = gr.outputs.Textbox(label="Output Text")
56
 
57
  examples = [
58
+ ['examples/BAC009S0767W0127.wav', 'CN'],
59
+ ['examples/BAC009S0767W0424.wav', 'CN'],
60
+ ['examples/BAC009S0767W0488.wav', 'CN'],
61
+ ['examples/1995-1836-0002.flac', 'EN'],
62
+ ['examples/61-70968-0000.flac', 'EN'],
63
+ ['examples/672-122797-0000.flac', 'EN'],
64
  ]
65
 
66
  text = "Speech Recognition in WeNet | 基于 WeNet 的语音识别"
67
 
68
  # description
69
+ description = (
70
+ "Wenet Demo ! This is a speech recognition demo that supports Mandarin and English !"
71
+ )
72
 
73
  article = (
74
  "<p style='text-align: center'>"
examples/1995-1836-0002.flac ADDED
Binary file (46.6 kB). View file
 
examples/61-70968-0000.flac ADDED
Binary file (97.2 kB). View file
 
examples/672-122797-0000.flac ADDED
Binary file (87.1 kB). View file