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 6beeae95
authored
Sep 24, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]脚本更新
1 parent
fc02cfa4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
15 deletions
mysql_service/funasr_db.py
utils/ali/test_03_car.py
utils/finetune.py
mysql_service/funasr_db.py
View file @
6beeae9
...
@@ -133,16 +133,18 @@ def select_funasr_audio(created_date):
...
@@ -133,16 +133,18 @@ def select_funasr_audio(created_date):
"""select ibr.id,(LENGTH(aamr.output_data) - LENGTH(REPLACE(aamr.output_data, '"role": 2', ''))) / LENGTH('"role": 2') AS count,
"""select ibr.id,(LENGTH(aamr.output_data) - LENGTH(REPLACE(aamr.output_data, '"role": 2', ''))) / LENGTH('"role": 2') AS count,
icb.score,ibr.recording_duration/60 as recDura ,ibr.created_date ,ibr.recording_url ,ieb.`language`,
icb.score,ibr.recording_duration/60 as recDura ,ibr.created_date ,ibr.recording_url ,ieb.`language`,
#LENGTH(aamr.output_data),LENGTH(REPLACE(aamr.output_data, '"role": 2', '')),LENGTH('"role": 2'),
#LENGTH(aamr.output_data),LENGTH(REPLACE(aamr.output_data, '"role": 2', '')),LENGTH('"role": 2'),
aamr.created_by,aamr.output_data,ibr.recording_duration
aamr.created_by,aamr.output_data,ibr.recording_duration
,aamr.task_id
from inspection_badge_recordings ibr
from inspection_badge_recordings ibr
left join ali_asr_model_res aamr on aamr.task_id=ibr.process_task_id
left join ali_asr_model_res aamr on aamr.task_id=ibr.process_task_id
left join inspection_conversation_batch icb on icb.record_id=ibr.id
left join inspection_conversation_batch icb on icb.record_id=ibr.id
left join inspection_employee_badge ieb on ieb.badge_id=ibr.badge_id
left join inspection_employee_badge ieb on ieb.badge_id=ibr.badge_id
where ibr.deleted_flag = 'N'
where ibr.deleted_flag = 'N'
and ibr.created_date >=
%
s
and ibr.created_date >=
%
s
and aamr.output_data not like
%
s
#
and aamr.output_data not like
%
s
and ibr.recording_duration/60>20 and ibr.recording_duration/60<31
and ibr.recording_duration/60>20 and ibr.recording_duration/60<31
and ieb.`language` !=1
and ieb.`language` !=1
group by ibr.id order by ibr.created_date desc;"""
and aamr.output_data is not null
and aamr.task_id = '1acddf88-69c8-11ef-b08a-00163e14f7ff'
group by ibr.id order by ibr.created_date desc"""
)
)
return
pool
.
select_all
(
sql
,
(
created_date
,
'
%
"role": 2
%
'
))
return
pool
.
select_all
(
sql
,
(
created_date
,
'
%
"role": 2
%
'
))
utils/ali/test_03_car.py
View file @
6beeae9
...
@@ -205,4 +205,4 @@ def run_simple(fileUrl, name=None):
...
@@ -205,4 +205,4 @@ def run_simple(fileUrl, name=None):
text_list
=
dealTaskResult
(
taskId
)
text_list
=
dealTaskResult
(
taskId
)
write_file
(
text_list
,
f
"{base_path}{name}.txt"
)
write_file
(
text_list
,
f
"{base_path}{name}.txt"
)
run_simple
(
"https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/1715688494984merged_17153238831671715320257955.mp3"
,
name
=
"test1"
)
\ No newline at end of file
\ No newline at end of file
run_simple
(
"https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_172612704155017261137765681.mp3"
,
name
=
"merged_172612704155017261137765681"
)
\ No newline at end of file
\ No newline at end of file
utils/finetune.py
View file @
6beeae9
import
datetime
from
log.logger
import
log
from
log.logger
import
log
import
os
import
os
import
subprocess
import
subprocess
...
@@ -118,17 +120,16 @@ def crop_audio(offset, duration, audio_file_path, output_path, expand=0):
...
@@ -118,17 +120,16 @@ def crop_audio(offset, duration, audio_file_path, output_path, expand=0):
]
]
subprocess
.
run
(
cmd
,
check
=
True
)
subprocess
.
run
(
cmd
,
check
=
True
)
def
cut_audio
(
input_file
,
output_remaining_file
,
start_time_ms
,
duration_ms
):
def
cut_audio
(
input_file
,
output_remaining_file
,
start_time_ms
,
duration_ms
):
try
:
try
:
# 加载音频文件
# 加载音频文件
audio
=
AudioSegment
.
from_file
(
input_file
)
audio
=
AudioSegment
.
from_file
(
input_file
)
# 将秒转换为毫秒
end_time_ms
=
int
((
start_time_ms
+
duration_ms
))
end_time_ms
=
int
((
start_time_ms
+
duration_ms
))
# 剪切指定部分
# 剪切指定部分
#
cut_part = audio[start_time_ms:end_time_ms]
cut_part
=
audio
[
start_time_ms
:
end_time_ms
]
# cut_part.export(output_cut_file
, format="mp3")
cut_part
.
export
(
output_remaining_file
+
"_cut"
,
format
=
"mp3"
)
# 提取剩余部分
# 提取剩余部分
if
start_time_ms
==
0
:
if
start_time_ms
==
0
:
...
@@ -137,7 +138,7 @@ def cut_audio(input_file, output_remaining_file, start_time_ms, duration_ms):
...
@@ -137,7 +138,7 @@ def cut_audio(input_file, output_remaining_file, start_time_ms, duration_ms):
remaining_part
=
audio
[:
start_time_ms
]
+
audio
[
end_time_ms
:]
remaining_part
=
audio
[:
start_time_ms
]
+
audio
[
end_time_ms
:]
remaining_part
.
export
(
output_remaining_file
,
format
=
"mp3"
)
remaining_part
.
export
(
output_remaining_file
,
format
=
"mp3"
)
print
(
"
剪切完成
!"
)
print
(
"
cut success
!"
)
except
CouldntDecodeError
:
except
CouldntDecodeError
:
print
(
f
"无法解析文件:{input_file}"
)
print
(
f
"无法解析文件:{input_file}"
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -231,15 +232,14 @@ def copy_and_overwrite(source_file_path, target_file_path):
...
@@ -231,15 +232,14 @@ def copy_and_overwrite(source_file_path, target_file_path):
def
crop_audio_by_rule
(
output_duration
:
int
):
def
crop_audio_by_rule
(
output_duration
:
int
):
append_sys_param
(
"env"
,
"release"
)
append_sys_param
(
"env"
,
"release"
)
pattern
=
r"(
[一二三四五六七八九0-9]
){6,}"
pattern
=
r"(
?:[零幺一二三四五六七八九0-9].*
){6,}"
base_path
=
"D:/software/python/project/funasr_web/audios/train_audio/"
base_path
=
"D:/software/python/project/funasr_web/audios/train_audio/"
output_path
=
f
'{base_path}final_audio1/'
output_path
=
f
'{base_path}final_audio/'
down_path
=
f
'{base_path}down_audio1/'
down_path
=
f
'{base_path}down_text/'
filter_text
=
""
total_duration
=
0
total_duration
=
0
expand
=
0
from
mysql_service
import
funasr_db
from
mysql_service
import
funasr_db
data
=
funasr_db
.
select_funasr_audio
(
'2024-08-01'
)
data
=
funasr_db
.
select_funasr_audio
(
'2024-08-01'
)
# data = funasr_db.select_ali_asr_model_res('1acddf88-69c8-11ef-b08a-00163e14f7ff')
with
open
(
f
"{base_path}filter.txt"
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
with
open
(
f
"{base_path}filter.txt"
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
for
item
in
data
:
for
item
in
data
:
try
:
try
:
...
@@ -253,11 +253,13 @@ def crop_audio_by_rule(output_duration: int):
...
@@ -253,11 +253,13 @@ def crop_audio_by_rule(output_duration: int):
if
output_data
is
None
:
if
output_data
is
None
:
continue
continue
jsonobj
=
json
.
loads
(
output_data
)
jsonobj
=
json
.
loads
(
output_data
)
cut_duration
=
0
for
obj
in
jsonobj
:
for
obj
in
jsonobj
:
content
=
obj
.
get
(
"content"
,
""
)
content
=
obj
.
get
(
"content"
,
""
)
match
=
re
.
search
(
pattern
,
content
)
match
=
re
.
search
(
pattern
,
content
)
if
bool
(
match
):
if
bool
(
match
):
cut_audio
(
down_file
,
output_file
,
obj
.
get
(
"offset"
),
obj
.
get
(
"duration"
),)
cut_audio
(
down_file
,
output_file
,
obj
.
get
(
"offset"
)
-
cut_duration
,
obj
.
get
(
"duration"
),
)
cut_duration
+=
obj
.
get
(
"duration"
)
copy_and_overwrite
(
output_file
,
down_file
)
copy_and_overwrite
(
output_file
,
down_file
)
duration
-=
obj
.
get
(
"duration"
)
duration
-=
obj
.
get
(
"duration"
)
file
.
write
(
f
"{task_id}:{content}
\n
"
)
file
.
write
(
f
"{task_id}:{content}
\n
"
)
...
@@ -290,3 +292,67 @@ def upload_files(name, file_path):
...
@@ -290,3 +292,67 @@ def upload_files(name, file_path):
crop_audio_by_rule
(
500
*
1000
*
3600
)
crop_audio_by_rule
(
500
*
1000
*
3600
)
def
adjust_time_with_milliseconds
(
offset_milliseconds
,
duration_milliseconds
):
# 创建一个基于当天00:00:00的时间点
base_time
=
datetime
.
datetime
.
now
()
.
replace
(
hour
=
0
,
minute
=
0
,
second
=
0
,
microsecond
=
0
)
# 将毫秒转换为秒
offset_seconds
=
int
(
offset_milliseconds
/
1000.0
)
duration_seconds
=
int
(
duration_milliseconds
/
1000.0
)
# 计算偏移时间和持续时间
offset_time
=
datetime
.
timedelta
(
seconds
=
offset_seconds
)
duration_time
=
datetime
.
timedelta
(
seconds
=
duration_seconds
)
# 应用偏移时间
adjusted_time
=
base_time
+
offset_time
# 应用持续时间
end_time
=
adjusted_time
+
duration_time
formatted_start_time
=
adjusted_time
.
strftime
(
'
%
M:
%
S'
)
formatted_end_time
=
end_time
.
strftime
(
'
%
H:
%
M:
%
S'
)
# 检查是否跨越了午夜
if
end_time
.
day
>
base_time
.
day
:
end_time
=
datetime
.
datetime
.
combine
(
base_time
.
date
()
+
datetime
.
timedelta
(
days
=
1
),
end_time
.
time
())
formatted_end_time
=
end_time
.
strftime
(
'
%
M:
%
S'
)
return
formatted_start_time
,
formatted_end_time
def
format_audio_and_text
():
audio_path
=
f
'D:/software/python/project/funasr_web/audios/train_audio/down_audio/'
text_path
=
f
'D:/software/python/project/funasr_web/audios/train_audio/upload_text.txt'
output_path
=
f
'D:/software/python/project/funasr_web/audios/train_audio/result.txt'
filter_path
=
f
'D:/software/python/project/funasr_web/audios/train_audio/filter.txt'
append_sys_param
(
"env"
,
"release"
)
from
mysql_service
import
funasr_db
task_set
=
set
()
index
=
0
with
open
(
filter_path
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
for
line
in
file
:
index
+=
1
if
index
%
6
!=
0
:
continue
# 去除行尾的换行符
line
=
line
.
strip
()
# 使用逗号分隔键和值
parts
=
line
.
split
(
':'
,
1
)
task_set
.
add
(
parts
[
0
])
if
len
(
task_set
)
==
100
:
break
# list = list(task_set)[:100]
with
open
(
f
"{output_path}"
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
for
task_id
in
task_set
:
file_path
=
f
"{audio_path}{task_id}.mp3"
data
=
funasr_db
.
select_ali_asr_model_res
(
task_id
)
output_data
=
data
[
0
]
.
get
(
"output_data"
,
""
)
json_output
=
json
.
loads
(
output_data
)
with
open
(
text_path
,
'w'
,
encoding
=
'gbk'
)
as
text_file
:
for
item
in
json_output
:
start_time
,
end_time
=
adjust_time_with_milliseconds
(
item
.
get
(
"offset"
),
item
.
get
(
"duration"
))
role
=
item
.
get
(
"role"
)
content
=
item
.
get
(
"content"
)
text_file
.
write
(
f
"{start_time}-{end_time} 角色{role}:{content}
\n
"
)
text_file
.
close
()
audio_url
=
upload_file
(
f
"{task_id}.mp3"
,
file_path
)
text_url
=
upload_file
(
f
"{task_id}.txt"
,
text_path
)
result
=
f
"{task_id}:{audio_url}:{text_url}
\n
"
file
.
write
(
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