Spaces:
Runtime error
Runtime error
Liangcd
commited on
Commit
·
45ed0df
1
Parent(s):
f6f3627
[demo] support English
Browse files
app.py
CHANGED
|
@@ -19,7 +19,8 @@ import wenetruntime as wenet
|
|
| 19 |
import librosa
|
| 20 |
|
| 21 |
wenet.set_log_level(2)
|
| 22 |
-
|
|
|
|
| 23 |
# decoder_en = wenet.Decoder(lang='en')
|
| 24 |
|
| 25 |
|
|
@@ -30,12 +31,20 @@ def recognition(audio, lang='CN'):
|
|
| 30 |
# NOTE: model supports 16k sample_rate
|
| 31 |
y = (y * (1 << 15)).astype("int16")
|
| 32 |
if lang == 'CN':
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
elif lang == 'EN':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# ans = decoder_en.decode(y.tobytes(), True)
|
| 36 |
return "ERROR! English is not supported yet!"
|
| 37 |
else:
|
| 38 |
return "ERROR! Please select a language!"
|
|
|
|
| 39 |
if ans is None:
|
| 40 |
return "ERROR! No text output! Please try again!"
|
| 41 |
# NOTE: ans (json)
|
|
|
|
| 19 |
import librosa
|
| 20 |
|
| 21 |
wenet.set_log_level(2)
|
| 22 |
+
decoder = wenet.Decoder(lang='chs')
|
| 23 |
+
cur_lang = 'CN'
|
| 24 |
# decoder_en = wenet.Decoder(lang='en')
|
| 25 |
|
| 26 |
|
|
|
|
| 31 |
# NOTE: model supports 16k sample_rate
|
| 32 |
y = (y * (1 << 15)).astype("int16")
|
| 33 |
if lang == 'CN':
|
| 34 |
+
if cur_lang != lang:
|
| 35 |
+
del decoder
|
| 36 |
+
decoder = wenet.Decoder(lang='chs')
|
| 37 |
+
cur_lang = 'CN'
|
| 38 |
elif lang == 'EN':
|
| 39 |
+
if cur_lang != lang:
|
| 40 |
+
del decoder
|
| 41 |
+
decoder = wenet.Decoder(lang='en')
|
| 42 |
+
cur_lang = 'EN'
|
| 43 |
# ans = decoder_en.decode(y.tobytes(), True)
|
| 44 |
return "ERROR! English is not supported yet!"
|
| 45 |
else:
|
| 46 |
return "ERROR! Please select a language!"
|
| 47 |
+
ans = decoder.decode(y.tobytes(), True)
|
| 48 |
if ans is None:
|
| 49 |
return "ERROR! No text output! Please try again!"
|
| 50 |
# NOTE: ans (json)
|