This commit is contained in:
yumoqing 2024-11-13 17:58:47 +08:00
parent c954b81cea
commit d5bc2d072a
10 changed files with 88 additions and 69 deletions

View File

@ -1,35 +1,27 @@
import json import json
import os import os
from appPublic.dictObject import DictObject from appPublic.worker import awaitify
from appPublic.zmq_reqrep import ZmqReplier
from appPublic.jsonConfig import getConfig from appPublic.jsonConfig import getConfig
from ahserver.serverenv import ServerEnv
from ahserver.webapp import webapp
from time import time from time import time
from faster_whisper import WhisperModel from faster_whisper import WhisperModel
class ZmqASR: class FWASR:
def __init__(self): def __init__(self):
config = getConfig() config = getConfig()
self.model_dir = config.model_dir or "large-v3" self.modelname = config.modelname or "large-v3"
self.device = config.device or "cpu" self.device = config.device or "cpu"
self.zmq_url = config.zmq_url
self.compute_type=config.compute_type or "float16" self.compute_type=config.compute_type or "float16"
self.model = WhisperModel(self.model_dir, self.model = WhisperModel(self.modelname,
device=self.device, device=self.device,
compute_type=self.compute_type) compute_type=self.compute_type)
self.replier = ZmqReplier(self.zmq_url, self.generate)
def run(self): def inference(self, audiofile):
print(f'running {self.zmq_url}')
self.replier._run()
print('ended ...')
def generate(self, d):
msg= d.decode('utf-8')
data = DictObject(**json.loads(msg))
t1 = time() t1 = time()
segs, info = self.model.transcribe(data.audio_file) segs, info = self.model.transcribe(audio_file)
t2 = time() t2 = time()
d = DictObject(**{ d = DictObject(**{
'segments':[], 'segments':[],
@ -45,13 +37,13 @@ class ZmqASR:
d.segments.append(seg) d.segments.append(seg)
d.content += s.text d.content += s.text
d.time_cost = t2 - t1 d.time_cost = t2 - t1
print(f'{d}') return d
return json.dumps(d)
def init_func():
asr = FWASR()
g = ServerEnv()
g.inference = awaitify(asr.inference)
if __name__ == '__main__': if __name__ == '__main__':
workdir = os.getcwd() webapp(init_func)
config = getConfig(workdir)
print(f'{config=}')
asr = ZmqASR()
print('here')
asr.run()

View File

@ -1,6 +1,48 @@
{ {
"zmq_url" : "tcp://127.0.0.1:10002", "modelname" : "large-v3",
"model_dir" : "large-v3",
"device" : "cuda", "device" : "cuda",
"conpute_type": "float16" "conpute_type": "float16",
"logger":{
"name":"fwasr",
"levelname":"info",
"logfile":"$[workdir]$/logs/sage.log"
},
"filesroot":"$[workdir]$/files",
"website":{
"paths":[
["$[workdir]$/wwwroot",""]
],
"client_max_size":10000,
"host":"0.0.0.0",
"port":10093,
"coding":"utf-8",
"indexes":[
"index.html",
"index.tmpl",
"index.ui",
"index.dspy",
"index.md"
],
"startswiths":[
{
"leading":"/idfile",
"registerfunction":"idFileDownload"
}
],
"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"
}
} }

0
files/README.md Normal file
View File

4
logs/stderr.log Normal file
View File

@ -0,0 +1,4 @@
Traceback (most recent call last):
File "/data/ymq/py/fwasr/app/fwasr.py", line 6, in <module>
from ahserver.serverenv import ServerEnv
ModuleNotFoundError: No module named 'ahserver'

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
git+https://git.kaiyuancloud.cn/yumoqing/apppublic
git+https://git.kaiyuancloud.cn/yumoqing/sqlor
git+https://git.kaiyuancloud.cn/yumoqing/ahserver

11
script/fwasr.service Normal file
View File

@ -0,0 +1,11 @@
[Unit]
Description=fwasr service
Wants=systemd-networkd.service
Requires=nginx.service
[Service]
Type=forking
ExecStart=su - ymq -c "/data/ymq/py/fwasr/script/fwasr.sh"
ExecStop=su - ymq "/d/ymq/bin/killname fwasr.py"
[Install]
WantedBy=multi-user.target

5
script/fwasr.sh Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/bash
killname /data/ymq/py/fwasr/app/fwasr.py
/d/ymq/ve/fw/bin/python /data/ymq/py/fwasr/app/fwasr.py -w /data/ymq/py/fwasr > /data/ymq/py/fwasr/logs/stderr.log 2>&1 &
exit 0

4
script/install.sh Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/bash
sudo cp fwasr.service /etc/systemd/system
sudo systemctl enable fwasr.service
sudo systemctl start fwasr

0
wwwroot/index.dspy Normal file
View File

View File

@ -1,42 +0,0 @@
import json
import os
from appPublic.dictObject import DictObject
from appPublic.zmq_reqrep import ZmqRequester
from appPublic.jsonConfig import getConfig
zmq_url = "tcp://127.0.0.1:9999"
from time import time
class ASRClient:
def __init__(self, zmq_url):
self.zmq_url = zmq_url
self.requester = ZmqRequester(self.zmq_url)
def generate(self, audio_file):
d = {
"audio_file":audio_file
}
msg = json.dumps(d)
print(f'send={msg}')
resp = self.requester.send(msg)
if resp != None:
ret = json.loads(resp)
print(f'response={ret}')
else:
print(f'response is None')
def run(self):
print(f'running {self.zmq_url}')
while True:
print('input audio_file:')
af = input()
if len(af) > 0:
self.generate(af)
print('ended ...')
if __name__ == '__main__':
workdir = os.getcwd()
config = getConfig(workdir)
asr = ASRClient(config.zmq_url or zmq_url)
asr.run()