first commit
This commit is contained in:
commit
24be32dc62
6
conf/config.json
Normal file
6
conf/config.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"zmq_url" : "tcp://127.0.0.1:9999",
|
||||||
|
"model_dir" : "/d/ymq/models/funasr/SenseVoiceSmall",
|
||||||
|
"model_dir" : "turbo",
|
||||||
|
"device" : "cuda:0"
|
||||||
|
}
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
git+https://git.kaiyuancloud.cn/yumoqing/apppublic
|
||||||
|
openai-whisper
|
BIN
test_en_1_ref_short.wav
Normal file
BIN
test_en_1_ref_short.wav
Normal file
Binary file not shown.
BIN
test_zh_1_ref_short.wav
Normal file
BIN
test_zh_1_ref_short.wav
Normal file
Binary file not shown.
41
zmq_client.py
Normal file
41
zmq_client.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
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)
|
||||||
|
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()
|
45
zmq_whisper.py
Normal file
45
zmq_whisper.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from appPublic.dictObject import DictObject
|
||||||
|
from appPublic.zmq_reqrep import ZmqReplier
|
||||||
|
from appPublic.jsonConfig import getConfig
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
import whisper
|
||||||
|
|
||||||
|
class ZmqASR:
|
||||||
|
def __init__(self, zmq_url, model_dir, device):
|
||||||
|
self.model = whisper.load_model(model_dir, device=device)
|
||||||
|
self.model_dir = model_dir
|
||||||
|
self.device = device
|
||||||
|
self.zmq_url = zmq_url
|
||||||
|
self.replier = ZmqReplier(self.zmq_url, self.generate)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
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()
|
||||||
|
res = self.model.transcribe(data.audio_file)
|
||||||
|
t2 = time()
|
||||||
|
text = res['text']
|
||||||
|
d = {k:v for k, v in res.items() if k!='text'}
|
||||||
|
d['content'] = text
|
||||||
|
d['time_cost'] = t2 - t1
|
||||||
|
print(f'{d}')
|
||||||
|
return json.dumps(d)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
workdir = os.getcwd()
|
||||||
|
config = getConfig(workdir)
|
||||||
|
print(f'{config=}')
|
||||||
|
asr = ZmqASR(config.zmq_url or zmq_url,
|
||||||
|
config.model_dir or model_dir,
|
||||||
|
config.device or device)
|
||||||
|
print('here')
|
||||||
|
asr.run()
|
Loading…
Reference in New Issue
Block a user