Commit 42283ff5 by ‘chizw’

[+]热词优化

1 parent bfed35a3
......@@ -18,8 +18,7 @@ model = AutoModel(
spk_model="cam++",
ncpu=2,
device="cpu",
batch_size_s=1,
batch_size_threshold_s=60 * 60
batch_size=1,
# model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
# vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",
# punc_model="iic/punc_ct-transformer_cn-en-common-vocab471067-large",
......@@ -45,12 +44,14 @@ class FunasrService(object):
@timeit
def transform(self):
res = model.generate(input=self.path, batch_size_s=1,
res = model.generate(input=self.path,
batch_size_s=1,
batch_size_threshold_s=60 * 60,
hotword="问界 100\n质保经理 100\n易损易耗件 100\n电瓶 100\nM5 100\nM7 100\nM9 100\n石子 100"
"\n橡胶棒 100\n电子助力泵 100\n电子真空助力泵 100\n充电桩 100\n密封圈 100\n4S店 100\n老化 100"
"\n打死 100\n油车 100\n电车 100\n备忘录 100\n自费 100\n胶套求成密封圈 100\n安信无忧 100"
"\n全车易损耗件 100\n厂家 100\n喷漆 100\n封釉 100\n雾化 100\n里程 100\n延保 100\n外地牌 100"
"\n轮胎 100\n胶条 100\n漆面 100\n充电接口 100\n车衣 100\n传动车身 100")
"\n轮胎 100\n胶条 100\n漆面 100\n充电接口 100\n车衣 100\n传动车身 100\n喜提新车 100")
# print(res)
return res
......@@ -118,7 +119,7 @@ def deal_worker(task_id: str):
return
sentence_info = output_res[0]["sentence_info"]
json_output = fine_grained_transform_output(sentence_info)
log.info("json_output: %s" % json_output)
# log.info("json_output: %s" % json_output)
execute_time = time.perf_counter() - consuming_start_time
funasr_db.update_ali_asr_model_res(task_id, json_output, int((execute_time * 1000)))
log.info(
......
......@@ -16,11 +16,33 @@ from mysql_service import funasr_db
# value = message.value
# print(f"Key: {key}, Value: {value}")
datas = ['0f4ba9a0-e7f6-11ee-b77c-b083fec01e48']
for task_id in datas:
sql_res = funasr_db.select_ali_asr_model_res(task_id)
url = sql_res[0]["file_url"]
output_res = funasr_service.FunasrService(url).transform()
res = funasr_service.fine_grained_transform_output(output_res[0]["sentence_info"])
print(res)
datas = ['50457010-0625-11ef-bfcc-b083fec01e48',
'5049b706-0625-11ef-bfcc-b083fec01e48']
def not_insert_run():
for task_id in datas:
out_put: str
if task_id.find("/") != -1:
output_res = funasr_service.FunasrService(task_id).transform()
else:
sql_res = funasr_db.select_ali_asr_model_res(task_id)
url = sql_res[0]["file_url"]
output_res = funasr_service.FunasrService(url).transform()
res = funasr_service.fine_grained_transform_output(output_res[0]["sentence_info"])
print(res)
def insert_run():
for task_id in datas:
funasr_service.deal_worker(task_id)
def run():
url = 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/7cf068ad-2592-4033-93c0-02c9b2735189.mp3'
res = funasr_service.FunasrService(url).transform
print(f"res:{str(res)}")
# print(f"sentence_info:{funasr_service.fine_grained_transform_output(res[0]['sentence_info'])}")
insert_run()
......@@ -51,10 +51,8 @@ class ConnPool:
result = cursor.fetchall()
self.close(conn, cursor)
log.info(f"execute_select_all result:{result}")
if str(result) == "()":
return []
else:
return result
return result
def insert_one(self, sql, args):
"""插入单条数据"""
......
from funasr import AutoModel
import soundfile as sf
from mysql_service import funasr_db
# # 初始化VAD模型和流式ASR模型
# vad_model = AutoModel(model="fsmn-vad")
# asr_model = AutoModel(model="paraformer-zh-streaming", chunk_size=[0, 10, 5])
#
# # 读取长音频文件
# long_audio_path = "D:/software/python/project/funasr_web/字节-安静环境.mp3"
# speech, sample_rate = sf.read(long_audio_path)
#
# # 使用VAD模型分割音频
# vad_segments = vad_model.generate(input=long_audio_path)
#
# # 对每个VAD分割的片段应用流式ASR模型
# for segment_start, segment_end in vad_segments:
# # 根据VAD分割结果获取音频片段
# segment = speech[int(segment_start * sample_rate):int(segment_end * sample_rate)]
# # 流式处理音频片段
# total_chunk_num = int(len(segment) / asr_model.chunk_size[1] * 960) + 1
# for i in range(total_chunk_num):
# speech_chunk = segment[i * asr_model.chunk_size[1] * 960:(i + 1) * asr_model.chunk_size[1] * 960]
# is_final = i == total_chunk_num - 1
# res = asr_model.generate(input=speech_chunk, is_final=is_final)
# print(res)
#
......@@ -8,17 +8,21 @@ import funasr_service
model = AutoModel(
# model="paraformer-zh",
# model="paraformer-zh-spk",
model="iic/speech_paraformer-large-vad-punc-spk_asr_nat-zh-cn",
model_revision="v2.0.4",
model="c:/Users/chizw/.cache/modelscope/hub/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-Common-vocab8404-pytorch",
# model="c:/Users/chizw/.cache/modelscope/hub/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-Common-vocab8404-pytorch",
# model_revision="v2.0.4",
vad_model="fsmn-vad",
# punc_model="ct-punc-c",
punc_model="ct-punc",
# spk_model="cam++",
spk_model="iic/speech_campplus_speaker-diarization_common",
spk_model_revision="v1.0.0",
spk_model="iic/speech_eres2net_sv_zh-cn_16k-common",
# spk_model="cam++",
# spk_model_revision="v1.0.0",
# spk_model="iic/speech_eres2net-large_speaker-diarization_common",
# openai_model="Whisper-large-v3",
ncpu=8,
ncpu=2,
device="cpu",
batch_size=1,
)
......@@ -32,9 +36,14 @@ consuming_start_time = time.perf_counter()
# res = model.generate(input="asr_example.wav", batch_size_s=300, hotword="魔搭")
# res = model.generate(input="123456.wav", batch_size_s=300, hotword="魔搭")
res = model.generate(
input="asr_train_example.mp3",
batch_size_s=300,
hotword="问界 80\n电瓶 100\n保修 100\n问界店 100\nM7\nM5\nM9",
input="https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/7cf068ad-2592-4033-93c0-02c9b2735189.mp3",
batch_size_s=1,
batch_size_threshold_s=60 * 60,
hotword="问界 100\n质保经理 100\n易损易耗件 100\n电瓶 100\nM5 100\nM7 100\nM9 100\n石子 100"
"\n橡胶棒 100\n电子助力泵 100\n电子真空助力泵 100\n充电桩 100\n密封圈 100\n4S店 100\n老化 100"
"\n打死 100\n油车 100\n电车 100\n备忘录 100\n自费 100\n胶套求成密封圈 100\n安信无忧 100"
"\n全车易损耗件 100\n厂家 100\n喷漆 100\n封釉 100\n雾化 100\n里程 100\n延保 100\n外地牌 100"
"\n轮胎 100\n胶条 100\n漆面 100\n充电接口 100\n车衣 100\n传动车身 100\n喜提新车 100",
)
print(f"res:{res}")
sentence_info = res[0]["sentence_info"]
......@@ -68,7 +77,6 @@ if content is not None:
res = funasr_service.fine_grained_transform_output(sentence_info)
print(res)
consuming_end_time = time.perf_counter()
print(
f"Function transform_file executed in {(consuming_end_time - consuming_start_time)} 秒"
......
......@@ -5,11 +5,11 @@ from funasr import AutoModel
# use vad, punc, spk or not as you need
model = AutoModel(
model="paraformer-zh",
vad_model="fsmn-vad",
punc_model="ct-punc-c",
spk_model="cam++",
# vad_model="fsmn-vad",
# punc_model="ct-punc-c",
# spk_model="cam++",
# openai_model="Whisper-large-v3",
ncpu=8,
# ncpu=8,
)
......@@ -20,6 +20,9 @@ def write_text(text):
consuming_start_time = time.perf_counter()
res = model.export(quantize=False)
print(res)
# res = model.generate(input="asr_example.wav", batch_size_s=300, hotword="魔搭")
# res = model.generate(input="123456.wav", batch_size_s=300, hotword="魔搭")
# res = model.generate(
......@@ -27,8 +30,8 @@ consuming_start_time = time.perf_counter()
# batch_size_s=300,
# hotword="问界 80\n电瓶 100\n保修 100\n问界店 100\nM7\nM5\nM9",
# )
res=model.export(input="北京店1-2024-02-29_14.58.11.MP3")
print(f"res:{res}")
# res=model.export(input="北京店1-2024-02-29_14.58.11.MP3")
# print(f"res:{res}")
# sentence_info = res[0]["sentence_info"]
# print(f"res_sentence_info:{sentence_info}")
# # print(res[0]["sentence_info"])
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!