first commit
This commit is contained in:
commit
c2897091b7
47
app/asr.py
Normal file
47
app/asr.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from ahserver.webapp import webapp
|
||||||
|
from ahserver.serverenv import ServerEnv
|
||||||
|
from ahserver.filestorage import FileStorage
|
||||||
|
from appPublic.log import debug,exception, error
|
||||||
|
from appPublic.worker import awaitify
|
||||||
|
from appPublic.jsonConfig import getConfig
|
||||||
|
import torch
|
||||||
|
import nemo.collections.asr as nemo_asr
|
||||||
|
|
||||||
|
class NVidiaASR:
|
||||||
|
def __init__(self):
|
||||||
|
config = getConfig()
|
||||||
|
self.models = {}
|
||||||
|
device = torch.device(config.device)
|
||||||
|
for lang, model_path in config.asr_models.items():
|
||||||
|
debug(f'{lang=}, {model_path=}')
|
||||||
|
model = None
|
||||||
|
if lang == 'en':
|
||||||
|
model = nemo_asr.models.EncDecCTCModelBPE.restore_from(model_path)
|
||||||
|
elif lang == 'cn':
|
||||||
|
model = nemo_asr.models.EncDecCTCModel.restore_from(model_path)
|
||||||
|
model.to(device)
|
||||||
|
self.models[lang] = model
|
||||||
|
|
||||||
|
def _generate(self, audio_file, lang):
|
||||||
|
model = self.models.get(lang)
|
||||||
|
output = model.transcribe([audio_file])
|
||||||
|
return output
|
||||||
|
|
||||||
|
async def generate(self, audio_file, lang='en'):
|
||||||
|
f = awaitify(self._generate)
|
||||||
|
t1 = time.time()
|
||||||
|
content = await f(audio_file, lang)
|
||||||
|
t2 = time.time()
|
||||||
|
return {
|
||||||
|
'content':content,
|
||||||
|
'timecost':t2 - t1
|
||||||
|
}
|
||||||
|
|
||||||
|
def init():
|
||||||
|
g = ServerEnv()
|
||||||
|
g.asr_engine = NVidiaASR()
|
||||||
|
g.generate = g.asr_engine.generate
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
webapp(init)
|
||||||
|
|
||||||
50
conf/config.json
Normal file
50
conf/config.json
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"device" : "cuda",
|
||||||
|
"asr_models":{
|
||||||
|
"cn": "/share/models/nvidia/stt_zh_citrinet_1024_gamma_0_25/stt_zh_citrinet_1024_gamma_0_25.nemo",
|
||||||
|
"en": "/share/models/nvidia/stt_en_conformer_ctc_large/stt_en_conformer_ctc_large.nemo"
|
||||||
|
},
|
||||||
|
"logger":{
|
||||||
|
"name":"asr",
|
||||||
|
"levelname":"info",
|
||||||
|
"logfile":"$[workdir]$/logs/asr.log"
|
||||||
|
},
|
||||||
|
"filesroot":"$[workdir]$/files",
|
||||||
|
"website":{
|
||||||
|
"paths":[
|
||||||
|
["$[workdir]$/wwwroot",""]
|
||||||
|
],
|
||||||
|
"client_max_size":10000,
|
||||||
|
"host":"0.0.0.0",
|
||||||
|
"port":9992,
|
||||||
|
"coding":"utf-8",
|
||||||
|
"indexes":[
|
||||||
|
"index.html",
|
||||||
|
"index.tmpl",
|
||||||
|
"index.ui",
|
||||||
|
"index.dspy",
|
||||||
|
"index.md"
|
||||||
|
],
|
||||||
|
"startswiths":[
|
||||||
|
{
|
||||||
|
"leading":"/idfile",
|
||||||
|
"registerfunction":"idfile"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"processors":[
|
||||||
|
[".dspy","dspy"],
|
||||||
|
[".md","md"]
|
||||||
|
],
|
||||||
|
"session_max_time":3000,
|
||||||
|
"session_issue_time":2500,
|
||||||
|
"session_redis_notuse":{
|
||||||
|
"url":"redis://127.0.0.1:6379"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"langMapping":{
|
||||||
|
"zh-Hans-CN":"zh-cn",
|
||||||
|
"zh-CN":"zh-cn",
|
||||||
|
"en-us":"en",
|
||||||
|
"en-US":"en"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
nvidia-asr.service
Normal file
15
nvidia-asr.service
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Wants=systemd-networkd.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=ymq
|
||||||
|
Group=ymq
|
||||||
|
Type=forking
|
||||||
|
WorkingDirectory=/share/ymq/run/nvidia-asr
|
||||||
|
ExecStart=/share/ymq/run/nvidia-asr/start.sh
|
||||||
|
ExecStop=/share/ymq/run/nvidia-asr/stop.sh
|
||||||
|
StandardOutput=append:/var/log/asr/asr.log
|
||||||
|
StandardError=append:/var/log/asr/asr.log
|
||||||
|
SyslogIdentifier=asr
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
wheel
|
||||||
|
typing_extensions
|
||||||
|
numpy
|
||||||
|
nemo-toolkit[asr]
|
||||||
7
start.sh
Executable file
7
start.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
rundir=/share/ymq/run/nvidia-asr
|
||||||
|
cd $rundir
|
||||||
|
CUDA_VISIBLE_DEVICES=6 $rundir/nvidia-asr.env/bin/python app/asr.py -p 9992 &
|
||||||
|
CUDA_VISIBLE_DEVICES=6 $rundir/nvidia-asr.env/bin/python app/asr.py -p 9992 &
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user