commit 24be32dc62062708559636248eccdfb20a709f97 Author: yumoqing Date: Mon Oct 21 11:15:47 2024 +0800 first commit diff --git a/conf/config.json b/conf/config.json new file mode 100644 index 0000000..eedb146 --- /dev/null +++ b/conf/config.json @@ -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" +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2923af5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +git+https://git.kaiyuancloud.cn/yumoqing/apppublic +openai-whisper diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..90fa59d --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +r=$HOME/ve/rtc/bin/python +$r $* diff --git a/test.wav b/test.wav new file mode 100644 index 0000000..4027401 Binary files /dev/null and b/test.wav differ diff --git a/test_en_1_ref_short.wav b/test_en_1_ref_short.wav new file mode 100644 index 0000000..3c593c3 Binary files /dev/null and b/test_en_1_ref_short.wav differ diff --git a/test_zh_1_ref_short.wav b/test_zh_1_ref_short.wav new file mode 100644 index 0000000..8cc055e Binary files /dev/null and b/test_zh_1_ref_short.wav differ diff --git a/zmq_client.py b/zmq_client.py new file mode 100644 index 0000000..5510b47 --- /dev/null +++ b/zmq_client.py @@ -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() diff --git a/zmq_whisper.py b/zmq_whisper.py new file mode 100644 index 0000000..b9b6793 --- /dev/null +++ b/zmq_whisper.py @@ -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()