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 ac5a4b1d
authored
May 15, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]异常处理优化
1 parent
328d38d0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
9 deletions
funasr_service.py
kafka_service/test01.py
test05.py
test_model.py
funasr_service.py
View file @
ac5a4b1
...
...
@@ -12,10 +12,13 @@ from mysql_service import funasr_db
# use vad, punc, spk or not as you need
model
=
AutoModel
(
model
=
"paraformer-zh"
,
model
=
"iic/speech_paraformer-large-vad-punc-spk_asr_nat-zh-cn"
,
model_revision
=
"v2.0.4"
,
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",
ncpu
=
2
,
device
=
"cpu"
,
batch_size
=
1
,
...
...
@@ -99,11 +102,12 @@ def deal_worker(task_id: str):
if
output_data
is
not
None
:
return
exception_msg
=
sql_res
[
0
][
"exception_msg"
]
if
exception_msg
is
not
None
or
exception_msg
==
"list index out of range"
\
or
exception_msg
==
"Unspecified internal error."
\
or
exception_msg
==
"local variable 'raw_text' referenced before assignment"
:
funasr_db
.
update_ali_asr_model_res_skip
(
task_id
)
return
if
exception_msg
is
not
None
:
if
exception_msg
==
"list index out of range"
\
or
exception_msg
==
"Unspecified internal error."
\
or
exception_msg
==
"local variable 'raw_text' referenced before assignment"
:
funasr_db
.
update_ali_asr_model_res_skip
(
task_id
)
return
funasr_db
.
update_process_task
(
task_id
,
str
(
multiprocessing
.
current_process
()
.
name
))
url
=
sql_res
[
0
][
"file_url"
]
if
url
==
""
or
len
(
url
)
<
1
or
not
url
.
startswith
(
"http"
):
...
...
@@ -143,6 +147,15 @@ def fine_grained_transform_output(sentence_info):
return
json_output
def
simple_transform_output
(
sentence_info
):
output
=
[]
for
one
in
sentence_info
:
output
.
append
((
str
(
one
[
"spk"
])
+
":"
+
one
[
"text"
]
+
'
\n
'
))
json_output
=
json
.
dumps
(
output
,
ensure_ascii
=
False
)
json_output
=
json_output
.
replace
(
" m 五"
,
"M5"
)
.
replace
(
" m 七"
,
"M7"
)
.
replace
(
" m 九"
,
"M9"
)
return
json_output
def
merge_spk_transform_output
(
sentence_info
):
output
=
[]
content
=
""
...
...
kafka_service/test01.py
View file @
ac5a4b1
...
...
@@ -16,8 +16,7 @@ from mysql_service import funasr_db
# value = message.value
# print(f"Key: {key}, Value: {value}")
datas
=
[
'50457010-0625-11ef-bfcc-b083fec01e48'
,
'5049b706-0625-11ef-bfcc-b083fec01e48'
]
datas
=
[
'88d4ac0e-11ea-11ef-8a60-b083fec01e48'
]
def
not_insert_run
():
...
...
@@ -29,7 +28,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
()
res
=
funasr_service
.
fine_grained
_transform_output
(
output_res
[
0
][
"sentence_info"
])
res
=
funasr_service
.
simple
_transform_output
(
output_res
[
0
][
"sentence_info"
])
print
(
res
)
...
...
test05.py
0 → 100644
View file @
ac5a4b1
import
time
from
funasr
import
AutoModel
import
funasr_service
# paraformer-zh is a multi-functional asr model
# use vad, punc, spk or not as you need
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"
,
vad_model
=
"fsmn-vad"
,
# punc_model="ct-punc-c",
punc_model
=
"ct-punc"
,
spk_model
=
"cam++"
,
# spk_model="iic/speech_eres2net_sv_zh-cn_16k-common",
# spk_model="iic/speech_campplus_speaker-diarization_common",
# spk_model_revision="v1.0.0",
# spk_model="iic/speech_eres2net-large_speaker-diarization_common",
# openai_model="Whisper-large-v3",
ncpu
=
8
,
)
def
write_text
(
text
):
with
open
(
"audio.txt"
,
"a+"
,
encoding
=
"utf8"
)
as
fw
:
fw
.
write
(
text
.
strip
())
fw
.
write
(
"
\n
"
)
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
\n
M7
\n
M5
\n
M9"
,
)
print
(
f
"res:{res}"
)
sentence_info
=
res
[
0
][
"sentence_info"
]
print
(
f
"res_sentence_info:{sentence_info}"
)
# print(res[0]["sentence_info"])
spk
=
0
total_time
=
0
content
=
""
for
one
in
sentence_info
:
# print(one)
# print(one["end"] - one["start"])
# print(one["text"])
# print(one["spk"])
# print(f'{one["end"] - one["start"]}; {one["text"]}; {one["spk"]}')
total_time
=
total_time
+
(
one
[
"end"
]
-
one
[
"start"
])
if
spk
==
one
[
"spk"
]:
content
=
content
+
one
[
"text"
]
else
:
text
=
f
"角色{spk + 1} : {content} -- 时长:{total_time}ms"
print
(
text
)
write_text
(
text
)
total_time
=
0
content
=
one
[
"text"
]
spk
=
one
[
"spk"
]
if
content
is
not
None
:
text
=
f
"角色{spk + 1} : {content} -- 时长:{total_time}ms"
print
(
text
)
write_text
(
text
)
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)} 秒"
)
test_model.py
0 → 100644
View file @
ac5a4b1
# 版本要求 modelscope version 升级至最新版本 funasr 升级至最新版本
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
)
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