user01 commited on
Commit
619446c
1 Parent(s): 446aabb

[fix] fix error

Browse files
Files changed (2) hide show
  1. app.py +10 -9
  2. requirements.txt +1 -1
app.py CHANGED
@@ -16,24 +16,26 @@
16
  import json
17
  import gradio as gr
18
  import torch
19
- import wenetruntime as wenet
20
  import librosa
21
 
22
  wenet.set_log_level(2)
23
- chs_decoder = wenet.Decoder(lang='chs')
24
- en_decoder = wenet.Decoder(lang='en')
 
25
 
26
 
27
  def recognition(audio, lang='CN'):
28
  if audio is None:
29
  return "Input Error! Please enter one audio!"
30
- y, _ = librosa.load(audio, sr=16000)
31
  # NOTE: model supports 16k sample_rate
32
- y = (y * (1 << 15)).astype("int16")
33
  if lang == 'CN':
34
- ans = chs_decoder.decode(y.tobytes(), True)
 
35
  elif lang == 'EN':
36
- ans = en_decoder.decode(y.tobytes(), True)
37
  else:
38
  return "ERROR! Please select a language!"
39
 
@@ -43,8 +45,7 @@ def recognition(audio, lang='CN'):
43
  # {
44
  # 'nbest' : [{"sentence" : ""}], 'type' : 'final_result
45
  # }
46
- ans = json.loads(ans)
47
- txt = ans['nbest'][0]['sentence']
48
  return txt
49
 
50
 
 
16
  import json
17
  import gradio as gr
18
  import torch
19
+ import wenet
20
  import librosa
21
 
22
  wenet.set_log_level(2)
23
+ # TODO: add hotword
24
+ chs_model = wenet.load_model('chinese')
25
+ en_model = wenet.load_model('english')
26
 
27
 
28
  def recognition(audio, lang='CN'):
29
  if audio is None:
30
  return "Input Error! Please enter one audio!"
31
+ # y, _ = librosa.load(audio, sr=16000)
32
  # NOTE: model supports 16k sample_rate
33
+ # y = (y * (1 << 15)).astype("int16")
34
  if lang == 'CN':
35
+ # ans = chs_decoder.decode(y.tobytes(), True)
36
+ ans = chs_model.transcribe(audio)
37
  elif lang == 'EN':
38
+ ans = en_model.transcribe(audio)
39
  else:
40
  return "ERROR! Please select a language!"
41
 
 
45
  # {
46
  # 'nbest' : [{"sentence" : ""}], 'type' : 'final_result
47
  # }
48
+ txt = ans['text']
 
49
  return txt
50
 
51
 
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- wenetruntime
2
  gradio
3
  librosa
 
1
+ wenet @ git+https://github.com/wenet-e2e/wenet.git
2
  gradio
3
  librosa