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 67bad952
authored
Jul 11, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]输出脚本
1 parent
1d261528
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
30 deletions
funasr_service.py
kafka_service/test01.py
test_model.py
funasr_service.py
View file @
67bad95
import
datetime
import
multiprocessing
import
threading
import
time
...
...
@@ -19,24 +20,28 @@ model = AutoModel(
# decoding_model="offline",
# model_revision="v2.0.4",
# model="dengcunqin/speech_seaco_paraformer_large_asr_nat-zh-cantonese-en-16k-common-vocab11666-pytorch",
model_revision
=
"master"
,
model
=
"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
=
"iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch"
,
#官方
# model="D:\software\python\model\modelscope\hub\iic\SenseVoiceSmall", #官方
# model="iic/speech_paraformer-large-vad-punc-spk_asr_nat-zh-cn",
# model_revision='v1.0.1',
vad_model
=
"fsmn-vad"
,
punc_model
=
"ct-punc-c"
,
spk_model
=
"cam++"
,
# spk_model="iic/speech_campplus_speaker-diarization_common",
# spk_model="damo/speech_campplus_speaker-diarization_common",
# spk_model="iic/speech_campplus_sv_zh-cn_16k-common",
vad_model_revision
=
"master"
,
punc_model_revision
=
"master"
,
spk_model_revision
=
"master"
,
# spk_model_revision="v2.0.2",
spk_model
=
"damo/speech_campplus_sv_zh-cn_16k-common"
,
spk_model_revision
=
"v2.0.2"
,
# spk_model="iic/speech_eres2netv2w24s4ep4_sv_zh-cn_16k-common",
# spk_model="damo/speech_eres2net_sv_zh-cn_16k-common",
# spk_model_revision="v1.0.5",
# spk_model="iic/speech_eres2net_sv_zh-cn_16k-common",
# spk_model="damo/speech_campplus-transformer_scl_zh-cn_16k-common",
# spk_model_revision="v1.0.0",
model_revision
=
'v2.0.4'
,
vad_model_revision
=
'v2.0.4'
,
punc_model_revision
=
'v2.0.4'
,
ncpu
=
4
,
ngpu
=
0
,
device
=
"cpu"
,
batch_size
=
1
,
# thr=0.18,
# 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",
...
...
@@ -63,13 +68,14 @@ class FunasrService(object):
@timeit
def
transform
(
self
):
res
=
model
.
generate
(
input
=
self
.
path
,
batch_size_s
=
1
,
batch_size_threshold_s
=
60
*
60
,
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"
"
\n
橡胶棒 100
\n
电子助力泵 100
\n
电子真空助力泵 100
\n
充电桩 100
\n
密封圈 100
\n
4S店 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
\n
喜提新车 100"
"
\n
估计 100"
)
# print(res)
return
res
...
...
@@ -197,6 +203,22 @@ def merge_spk_transform_output(sentence_info):
json_output
=
json
.
dumps
(
output
,
ensure_ascii
=
False
)
return
json_output
def
add_milliseconds_to_time
(
dt
,
milliseconds
):
"""将毫秒数添加到datetime对象上"""
return
dt
+
datetime
.
timedelta
(
milliseconds
=
milliseconds
)
def
test_comparison_transform_output
(
sentence_info
):
initial_time
=
datetime
.
datetime
(
1
,
1
,
1
,
0
,
0
,
0
,
0
)
output
=
[]
for
one
in
sentence_info
:
time
=
add_milliseconds_to_time
(
initial_time
,
one
[
"start"
])
.
strftime
(
"
%
H:
%
M:
%
S"
)
spk
=
str
(
one
[
"spk"
])
text
=
one
[
"text"
]
# output.append(f"[{time}] {spk}:{text}")
print
(
f
"[{time}] {spk}:{text}"
)
return
output
def
task_compensate_send
():
try
:
...
...
kafka_service/test01.py
View file @
67bad95
from
kafka
import
KafkaConsumer
import
funasr_service
from
mysql_service
import
funasr_db
from
funasr
import
AutoModel
# 创建Kafka消费者
# consumer = KafkaConsumer(
...
...
@@ -16,7 +17,11 @@ from mysql_service import funasr_db
# value = message.value
# print(f"Key: {key}, Value: {value}")
datas
=
[
'88d4ac0e-11ea-11ef-8a60-b083fec01e48'
]
wav_root_url
=
"https://www.modelscope.cn/api/v1/models/dengcunqin/speech_seaco_paraformer_large_asr_nat-zh-cantonese-en-16k-common-vocab11666-pytorch/repo?Revision=master&FilePath="
desk_path
=
"C:
\\
Users
\\
chizw
\\
Desktop
\\
"
datas
=
[
"C:
\\
Users
\\
chizw
\\
Desktop
\\
zhanggy202407100001.wav"
]
def
not_insert_run
():
...
...
@@ -28,6 +33,7 @@ def not_insert_run():
sql_res
=
funasr_db
.
select_ali_asr_model_res
(
task_id
)
url
=
sql_res
[
0
][
"file_url"
]
output_res
=
funasr_service
.
FunasrService
(
url
)
.
transform
()
print
(
f
"output_res:{str(output_res)}"
)
res
=
funasr_service
.
simple_transform_output
(
output_res
[
0
][
"sentence_info"
])
print
(
res
)
...
...
@@ -37,11 +43,25 @@ def insert_run():
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
def
run
(
url
):
if
url
is
None
:
url
=
'C:
\\
Users
\\
chizw
\\
Desktop
\\
zhanggy202407100001.wav'
res
=
funasr_service
.
FunasrService
(
url
)
.
transform
()
print
(
f
"res:{str(res)}"
)
funasr_service
.
test_comparison_transform_output
(
res
[
0
][
"sentence_info"
])
# print(f"sentence_info:{funasr_service.fine_grained_transform_output(res[0]['sentence_info'])}")
def
test_paraformer
():
model
=
AutoModel
(
model
=
"dengcunqin/speech_seaco_paraformer_large_asr_nat-zh-cantonese-en-16k-common-vocab11666-pytorch"
,
model_revision
=
"master"
)
res
=
model
.
generate
(
input
=
"https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_17161083134331716107368353.mp3"
,
hotword
=
wav_root_url
+
"example/hotword.txt"
,
)
print
(
res
)
insert_run
()
run
(
desk_path
+
"zhaoshl20240711-nfvolume230003.mp3"
)
run
(
desk_path
+
"zhaoshl20240711-nfvolume15-230003(1).mp3"
)
test_model.py
View file @
67bad95
# 版本要求 modelscope version 升级至最新版本 funasr 升级至最新版本
import
datetime
from
modelscope.pipelines
import
pipeline
sd_pipeline
=
pipeline
(
task
=
"speaker-diarization"
,
model
=
"damo/speech_campplus_speaker-diarization_common"
,
model_revision
=
"v1.0.0"
,
)
input_wav
=
"https://modelscope.cn/api/v1/models/damo/speech_campplus_speaker-diarization_common/repo?Revision=master&FilePath=examples/2speakers_example.wav"
result
=
sd_pipeline
(
input_wav
)
print
(
result
)
# 如果有先验信息,输入实际的说话人数,会得到更准确的预测结果
result
=
sd_pipeline
(
input_wav
,
oracle_num
=
2
)
print
(
result
)
def
test_01
():
sd_pipeline
=
pipeline
(
task
=
"speaker-diarization"
,
model
=
"damo/speech_campplus_speaker-diarization_common"
,
model_revision
=
"v1.0.0"
,
)
input_wav
=
"https://modelscope.cn/api/v1/models/damo/speech_campplus_speaker-diarization_common/repo?Revision=master&FilePath=examples/2speakers_example.wav"
result
=
sd_pipeline
(
input_wav
)
print
(
result
)
# 如果有先验信息,输入实际的说话人数,会得到更准确的预测结果
result
=
sd_pipeline
(
input_wav
,
oracle_num
=
2
)
print
(
result
)
def
test_02
():
initial_time
=
datetime
.
datetime
(
1
,
1
,
1
,
0
,
0
,
0
,
0
)
timestamp
=
0
print
(
datetime
.
datetime
.
fromtimestamp
(
timestamp
)
.
strftime
(
"
%
H:
%
M:
%
S"
))
print
(
initial_time
.
strftime
(
"
%
H:
%
M:
%
S"
))
print
(
initial_time
.
strftime
(
"
%
H:
%
M:
%
S"
)[:
-
3
])
# print(add_milliseconds_to_time(initial_time, 1000))
pass
test_02
()
\ No newline at end of file
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