Commit bb849b4b by ‘chizw’

[+]脚本更新

1 parent fa38fc37
......@@ -4,11 +4,11 @@ import os
def extract_sys_param(param_name, default_value=None):
env_index = None
log.info(f"config init param:{sys.argv}")
for i, arg in enumerate(sys.argv):
if arg == f"--{param_name}":
env_index = i
break
if env_index is not None and env_index + 1 < len(sys.argv):
env_value = sys.argv[env_index + 1]
print(f"Environment extract_param {param_name}: {env_value}")
......
......@@ -130,26 +130,19 @@ def insert_funasr_mock_data(task_id: str, url: str, output_data: str):
def select_funasr_audio(created_date):
sql = (
"""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`
#,LENGTH(aamr.output_data),LENGTH(REPLACE(aamr.output_data, '"role": 2', '')),LENGTH('"role": 2')
,aamr.created_by,aamr.output_data,ibr.recording_duration
"""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`,
#LENGTH(aamr.output_data),LENGTH(REPLACE(aamr.output_data, '"role": 2', '')),LENGTH('"role": 2'),
aamr.created_by,aamr.output_data,ibr.recording_duration
from inspection_badge_recordings ibr
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_employee_badge ieb on ieb.badge_id=ibr.badge_id
where ibr.deleted_flag = 'N'
and ibr.created_date >= %s
-- date_format(ibr.created_date, '%Y-%m-%d')='2024-09-03'
# date_format(ibr.recording_start_time , '%Y-%m-%d')='2024-09-03'
# date_format(ibr.created_date, '%Y-%m')='2024-08'
# and ibr.created_date<'2024-07-23 23:59:59'
and aamr.output_data not like '%"role": 2%'
# and icb.score>50 and icb.score<70
# and ibr.badge_id='pad20240321001'
-- and ibr.id not in ()
and aamr.output_data not like %s
and ibr.recording_duration/60>20 and ibr.recording_duration/60<31
and ieb.`language` !=1
# and icb.score>85
group by ibr.id order by ibr.created_date desc;"""
)
return pool.select_all(sql, created_date)
return pool.select_all(sql, (created_date,'%"role": 2%'))
......@@ -8,7 +8,15 @@ import shortuuid
import re
import json
import traceback
from mysql_service import funasr_db
import sys
import shutil
def append_sys_param(param_name, default_value=None):
sys.argv.append(f"--{param_name}")
sys.argv.append(f"{default_value}")
log.info(f"append_sys_param success sys.argv:{sys.argv}")
folder = "quality/"
bucketName = 'glsk-oss'
......@@ -103,7 +111,8 @@ def crop_audio(offset, duration, audio_file_path, output_path, expand=0):
'-i', audio_file_path,
'-t', str((duration / 1000) + expand),
'-c', 'copy',
output_path
output_path,
'-y', # 强制覆盖现有文件
]
subprocess.run(cmd, check=True)
......@@ -177,34 +186,61 @@ def analysis_demo_list(version=None):
log.info("analysis_demo_list success")
def copy_and_overwrite(source_file_path, target_file_path):
try:
# 如果目标文件已存在,删除它
if os.path.exists(target_file_path):
os.remove(target_file_path)
# 复制文件
shutil.copy2(source_file_path, target_file_path)
print(f"文件 {source_file_path} 已覆盖到 {target_file_path}")
except FileNotFoundError:
print(f"源文件 {source_file_path} 不存在")
except IOError as e:
print(f"文件操作错误: {e}")
except Exception as e:
print(f"未知错误: {e}")
def crop_audio_by_rule(output_duration: int):
append_sys_param("env", "release")
pattern = r"([一二三四五六七八九0-9]){6,}"
output_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_audio/'
down_path = f'{base_path}down_audio/'
filter_text = ""
total_duration = 0
from mysql_service import funasr_db
data = funasr_db.select_funasr_audio('2024-08-01')
for item in data:
try:
duration = item["recording_duration"]
id = item["id"]
recording_url = item["recording_url"]
file_path = f"{output_path}{id}"
download_audio(recording_url, file_path)
output_data = item["output_data"]
jsonobj = json.loads(output_data)
for obj in jsonobj:
content = obj.get("content", "")
match = re.search(pattern, content)
if bool(match):
crop_audio(obj.get("offset"), obj.get("duration"), file_path, file_path, 10)
duration -= obj.get("duration") + (10 * 2)
total_duration += duration
if total_duration > output_duration:
log.info(f"执行完成,文件总时长:{total_duration} ms")
return
except Exception as e:
print(f"crop_audio_by_rule error:{traceback.format_exc()}")
continue
pass
with open(f"{base_path}filter_txt", 'w', encoding='utf-8') as file:
for item in data:
try:
duration = item["recording_duration"] * 1000
id = item["id"]
recording_url = item["recording_url"]
down_file = f"{down_path}{id}.mp3"
output_file = f"{output_path}{id}.mp3"
download_audio(recording_url, down_file)
output_data = item["output_data"]
jsonobj = json.loads(output_data)
for obj in jsonobj:
content = obj.get("content", "")
match = re.search(pattern, content)
if bool(match):
crop_audio(obj.get("offset"), obj.get("duration"), down_file, output_file, 10)
copy_and_overwrite(output_file, down_file)
duration -= obj.get("duration") + (10 * 2 * 1000)
filter_text += f"{id}:{content}\n"
file.write(filter_text)
total_duration += duration
if total_duration > output_duration:
return
except Exception as e:
print(f"crop_audio_by_rule error:{traceback.format_exc()}")
continue
log_text = f"执行完成,文件总时长:{total_duration / 1000 / 3600} hour"
log.info(log_text)
file.write(log_text)
list = [866, -430, 867, 870, 871, 872, 873]
......@@ -213,9 +249,13 @@ for id in list:
# voice_slicing(id)
pass
def upload_files(name, file_path):
with open("D:/software/python/project/funasr_web/dataset/temp/train/train_text.txt", 'r', encoding='gbk') as file:
for index, line in enumerate(file, 1):
parts = line.split(' ')
name = parts[0]
upload_file(f"{index}.wav", f"D:/software/python/project/funasr_web/dataset/temp/0830_{name}.wav")
crop_audio_by_rule(550 * 1000 * 3600)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!