Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
funasr_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e9116d9a
authored
Dec 05, 2025
by
蔡茜
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
automodel单例
1 parent
6bc7a7cc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
29 deletions
config/config.py
funasr_service.py
funasr_train_test/test01.py
funasr_train_test/test03.py
mysql_service/funasr_db.py
config/config.py
View file @
e9116d9
...
...
@@ -67,4 +67,4 @@ class ConfigInfo:
kafka_consumer_auto_offset_reset
=
Config
.
kafka_consumer_auto_offset_reset
kafka_consumer_analysis_topic
=
Config
.
kafka_consumer_analysis_topic
charset
=
Config
.
charset
subprocess_count
=
Config
.
charse
t
subprocess_count
=
Config
.
subprocess_coun
t
funasr_service.py
View file @
e9116d9
...
...
@@ -17,6 +17,8 @@ from urllib.parse import urlparse, urlunparse
# paraformer-zh is a multi-functional asr model
# use vad, punc, spk or not as you need
_funasr_model
=
None
_model_lock
=
threading
.
Lock
()
def
timeit
(
func
):
def
wrapper
(
*
args
,
**
kwargs
):
...
...
@@ -37,8 +39,28 @@ class FunasrService(object):
@timeit
def
transform
(
self
):
global
_funasr_model
,
_model_lock
with
_model_lock
:
if
_funasr_model
is
None
:
log
.
info
(
f
"[{multiprocessing.current_process().name}] 正在加载FunASR模型..."
)
_funasr_model
=
self
.
_create_model
()
log
.
info
(
f
"[{multiprocessing.current_process().name}] FunASR模型加载成功"
)
res
=
_funasr_model
.
generate
(
input
=
self
.
path
,
batch_size_s
=
300
,
batch_size_threshold_s
=
60
,
hotword
=
"问界 100
\n
质保经理 100
\n
易损易耗件 100
\n
电瓶 100
\n
M5 100
\n
M7 100
\n
M9 100
\n
石子 100"
"橡胶棒 100
\n
电子助力泵 100
\n
电子真空助力泵 100
\n
充电桩 100
\n
密封圈 100
\n
4S店 100
\n
老化 100"
"打死 100
\n
油车 100
\n
电车 100
\n
备忘录 100
\n
自费 100
\n
胶套求成密封圈 100
\n
安信无忧 100"
"全车易损耗件 100
\n
厂家 100
\n
喷漆 100
\n
封釉 100
\n
雾化 100
\n
里程 100
\n
延保 100
\n
外地牌 100"
"轮胎 100
\n
胶条 100
\n
漆面 100
\n
充电接口 100
\n
传动车身 100
\n
喜提新车 100"
"估计 100
\n
安心包 100
\n
定损金额 100
\n
定损 100
\n
车价 100
\n
换新车 100
\n
轮胎补偿 100"
"更换轮胎 100
\n
保养 100
\n
漆面封釉 100
\n
车衣 100
\n
车内 100
\n
杀菌 100"
)
# print(res)
return
res
def
_create_model
(
self
):
if
ConfigInfo
.
env
is
None
or
ConfigInfo
.
env
==
'dev'
:
model
=
AutoModel
(
return
AutoModel
(
# model='iic/speech_UniASR_asr_2pass-cantonese-CHS-16k-common-vocab1468-tensorflow1-online',
# model='iic/speech_UniASR_asr_2pass-cantonese-CHS-16k-common-vocab1468-tensorflow1-offline',
# model="damo/speech_UniASR_asr_2pass-cantonese-CHS-16k-common-vocab1468-tensorflow1-online",
...
...
@@ -46,8 +68,8 @@ class FunasrService(object):
# model_revision="v2.0.4",
# model="dengcunqin/speech_seaco_paraformer_large_asr_nat-zh-cantonese-en-16k-common-vocab11666-pytorch",
# model="iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
#
model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch", #官方
model
=
"D:
\
software
\
python
\
model
\
modelscope
\
hub
\
iic
\
paraformer-temp"
,
model
=
"iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch"
,
#官方
#
model="D:\software\python\model\modelscope\hub\iic\paraformer-temp",
# model="D:\software\python\model\modelscope\hub\iic\SenseVoiceSmall",
# model="iic/speech_paraformer-large-vad-punc-spk_asr_nat-zh-cn",
# vad_model="fsmn-vad",
...
...
@@ -79,7 +101,7 @@ class FunasrService(object):
spk_model
=
"iic/speech_campplus_sv_zh-cn_16k-common"
,
)
else
:
model
=
AutoModel
(
return
AutoModel
(
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"
,
vad_kwargs
=
{
"max_single_segment_time"
:
60000
},
...
...
@@ -94,19 +116,6 @@ class FunasrService(object):
batch_size
=
1
,
disable_update
=
True
,
)
res
=
model
.
generate
(
input
=
self
.
path
,
batch_size_s
=
300
,
batch_size_threshold_s
=
60
,
hotword
=
"问界 100
\n
质保经理 100
\n
易损易耗件 100
\n
电瓶 100
\n
M5 100
\n
M7 100
\n
M9 100
\n
石子 100"
"橡胶棒 100
\n
电子助力泵 100
\n
电子真空助力泵 100
\n
充电桩 100
\n
密封圈 100
\n
4S店 100
\n
老化 100"
"打死 100
\n
油车 100
\n
电车 100
\n
备忘录 100
\n
自费 100
\n
胶套求成密封圈 100
\n
安信无忧 100"
"全车易损耗件 100
\n
厂家 100
\n
喷漆 100
\n
封釉 100
\n
雾化 100
\n
里程 100
\n
延保 100
\n
外地牌 100"
"轮胎 100
\n
胶条 100
\n
漆面 100
\n
充电接口 100
\n
传动车身 100
\n
喜提新车 100"
"估计 100
\n
安心包 100
\n
定损金额 100
\n
定损 100
\n
车价 100
\n
换新车 100
\n
轮胎补偿 100"
"更换轮胎 100
\n
保养 100
\n
漆面封釉 100
\n
车衣 100
\n
车内 100
\n
杀菌 100"
)
# print(res)
return
res
class
model_output
():
def
__init__
(
self
,
role
,
offset
,
duration
,
content
):
...
...
@@ -189,6 +198,8 @@ def deal_worker(task_id: str):
log
.
info
(
"output_res:
%
s"
%
output_res
)
funasr_db
.
update_ali_asr_model_res
(
task_id
,
str
(
output_res
),
0
)
return
if
"sentence_info"
not
in
output_res
[
0
]:
log
.
info
(
f
"{task_id} sentence_info 不存在 output_res:{output_res}"
)
sentence_info
=
output_res
[
0
][
"sentence_info"
]
json_output
=
fine_grained_transform_output
(
sentence_info
)
# log.info("json_output: %s" % json_output)
...
...
funasr_train_test/test01.py
View file @
e9116d9
...
...
@@ -10,7 +10,8 @@ model = AutoModel(
# model="paraformer-zh",
# model="paraformer-zh-spk",
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
=
"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"
,
...
...
funasr_train_test/test03.py
View file @
e9116d9
...
...
@@ -24,35 +24,35 @@ parser.add_argument("--port", type=int, default=8000, required=False, help="serv
parser
.
add_argument
(
"--asr_model"
,
type
=
str
,
#
default="paraformer-zh",
default
=
"/soft/FunASR/model/speech_paraformer-large-vad-punc-spk_asr_nat-zh-cn"
,
default
=
"paraformer-zh"
,
#
default="/soft/FunASR/model/speech_paraformer-large-vad-punc-spk_asr_nat-zh-cn",
help
=
"asr model from https://github.com/alibaba-damo-academy/FunASR?tab=readme-ov-file#model-zoo"
,
)
parser
.
add_argument
(
"--asr_model_revision"
,
type
=
str
,
default
=
"v2.0.4"
,
help
=
""
)
parser
.
add_argument
(
"--vad_model"
,
type
=
str
,
#
default="fsmn-vad",
default
=
"/soft/FunASR/model/speech_fsmn_vad_zh-cn-16k-common-pytorch/"
,
default
=
"fsmn-vad"
,
#
default="/soft/FunASR/model/speech_fsmn_vad_zh-cn-16k-common-pytorch/",
help
=
"vad model from https://github.com/alibaba-damo-academy/FunASR?tab=readme-ov-file#model-zoo"
,
)
parser
.
add_argument
(
"--vad_model_revision"
,
type
=
str
,
default
=
"v2.0.4"
,
help
=
""
)
parser
.
add_argument
(
"--punc_model"
,
type
=
str
,
#
default="ct-punc-c",
default
=
"/soft/FunASR/model/punc_ct-transformer_cn-en-common-vocab471067-large/"
,
default
=
"ct-punc-c"
,
#
default="/soft/FunASR/model/punc_ct-transformer_cn-en-common-vocab471067-large/",
help
=
"model from https://github.com/alibaba-damo-academy/FunASR?tab=readme-ov-file#model-zoo"
,
)
parser
.
add_argument
(
"--punc_model_revision"
,
type
=
str
,
default
=
"v2.0.4"
,
help
=
""
)
# 说话人识别/分割
parser
.
add_argument
(
"--spk_model_revision"
,
type
=
str
,
default
=
"v2.0.
4
"
,
help
=
""
)
parser
.
add_argument
(
"--spk_model_revision"
,
type
=
str
,
default
=
"v2.0.
2
"
,
help
=
""
)
parser
.
add_argument
(
"--spk_model"
,
type
=
str
,
#
default="cam++",
default
=
"/soft/FunASR/model/speech_campplus_sv_zh-cn_16k-common/"
,
default
=
"cam++"
,
#
default="/soft/FunASR/model/speech_campplus_sv_zh-cn_16k-common/",
help
=
"model from https://github.com/alibaba-damo-academy/FunASR?tab=readme-ov-file#model-zoo"
,
)
...
...
mysql_service/funasr_db.py
View file @
e9116d9
...
...
@@ -41,7 +41,7 @@ def update_ali_asr_model_res_fail(task_id: str, exception_msg: str, exception: s
"t.exception_msg =
%
s, t.exception_log =
%
s, "
"t.task_status = case when exception_limit >=
%
s then 2 else 0 end "
"where t.task_id =
%
s and del_flag = 0;"
)
return
pool
.
update_one
(
update_sql
,
(
EXCEPTION_LIMIT
,
exception_msg
,
exception
,
task_id
,))
return
pool
.
update_one
(
update_sql
,
(
exception_msg
,
exception
,
EXCEPTION_LIMIT
,
task_id
,))
def
update_ali_asr_model_res_skip
(
task_id
:
str
):
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment