Commit bb849b4b by ‘chizw’

[+]脚本更新

1 parent fa38fc37
...@@ -4,11 +4,11 @@ import os ...@@ -4,11 +4,11 @@ import os
def extract_sys_param(param_name, default_value=None): def extract_sys_param(param_name, default_value=None):
env_index = None env_index = None
log.info(f"config init param:{sys.argv}")
for i, arg in enumerate(sys.argv): for i, arg in enumerate(sys.argv):
if arg == f"--{param_name}": if arg == f"--{param_name}":
env_index = i env_index = i
break break
if env_index is not None and env_index + 1 < len(sys.argv): if env_index is not None and env_index + 1 < len(sys.argv):
env_value = sys.argv[env_index + 1] env_value = sys.argv[env_index + 1]
print(f"Environment extract_param {param_name}: {env_value}") 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): ...@@ -130,26 +130,19 @@ def insert_funasr_mock_data(task_id: str, url: str, output_data: str):
def select_funasr_audio(created_date): def select_funasr_audio(created_date):
sql = ( 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` """select ibr.id,(LENGTH(aamr.output_data) - LENGTH(REPLACE(aamr.output_data, '"role": 2', ''))) / LENGTH('"role": 2') AS count,
#,LENGTH(aamr.output_data),LENGTH(REPLACE(aamr.output_data, '"role": 2', '')),LENGTH('"role": 2') icb.score,ibr.recording_duration/60 as recDura ,ibr.created_date ,ibr.recording_url ,ieb.`language`,
,aamr.created_by,aamr.output_data,ibr.recording_duration #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 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
-- date_format(ibr.created_date, '%Y-%m-%d')='2024-09-03' and aamr.output_data not like %s
# 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 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
# and icb.score>85
group by ibr.id order by ibr.created_date desc;""" 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 ...@@ -8,7 +8,15 @@ import shortuuid
import re import re
import json import json
import traceback 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/" folder = "quality/"
bucketName = 'glsk-oss' bucketName = 'glsk-oss'
...@@ -103,7 +111,8 @@ def crop_audio(offset, duration, audio_file_path, output_path, expand=0): ...@@ -103,7 +111,8 @@ def crop_audio(offset, duration, audio_file_path, output_path, expand=0):
'-i', audio_file_path, '-i', audio_file_path,
'-t', str((duration / 1000) + expand), '-t', str((duration / 1000) + expand),
'-c', 'copy', '-c', 'copy',
output_path output_path,
'-y', # 强制覆盖现有文件
] ]
subprocess.run(cmd, check=True) subprocess.run(cmd, check=True)
...@@ -177,34 +186,61 @@ def analysis_demo_list(version=None): ...@@ -177,34 +186,61 @@ def analysis_demo_list(version=None):
log.info("analysis_demo_list success") 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): def crop_audio_by_rule(output_duration: int):
append_sys_param("env", "release")
pattern = r"([一二三四五六七八九0-9]){6,}" 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 total_duration = 0
from mysql_service import funasr_db
data = funasr_db.select_funasr_audio('2024-08-01') data = funasr_db.select_funasr_audio('2024-08-01')
with open(f"{base_path}filter_txt", 'w', encoding='utf-8') as file:
for item in data: for item in data:
try: try:
duration = item["recording_duration"] duration = item["recording_duration"] * 1000
id = item["id"] id = item["id"]
recording_url = item["recording_url"] recording_url = item["recording_url"]
file_path = f"{output_path}{id}" down_file = f"{down_path}{id}.mp3"
download_audio(recording_url, file_path) output_file = f"{output_path}{id}.mp3"
download_audio(recording_url, down_file)
output_data = item["output_data"] output_data = item["output_data"]
jsonobj = json.loads(output_data) jsonobj = json.loads(output_data)
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):
crop_audio(obj.get("offset"), obj.get("duration"), file_path, file_path, 10) crop_audio(obj.get("offset"), obj.get("duration"), down_file, output_file, 10)
duration -= obj.get("duration") + (10 * 2) 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 total_duration += duration
if total_duration > output_duration: if total_duration > output_duration:
log.info(f"执行完成,文件总时长:{total_duration} ms")
return return
except Exception as e: except Exception as e:
print(f"crop_audio_by_rule error:{traceback.format_exc()}") print(f"crop_audio_by_rule error:{traceback.format_exc()}")
continue continue
pass log_text = f"执行完成,文件总时长:{total_duration / 1000 / 3600} hour"
log.info(log_text)
file.write(log_text)
list = [866, -430, 867, 870, 871, 872, 873] list = [866, -430, 867, 870, 871, 872, 873]
...@@ -213,9 +249,13 @@ for id in list: ...@@ -213,9 +249,13 @@ for id in list:
# voice_slicing(id) # voice_slicing(id)
pass pass
def upload_files(name, file_path): 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: 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): for index, line in enumerate(file, 1):
parts = line.split(' ') parts = line.split(' ')
name = parts[0] name = parts[0]
upload_file(f"{index}.wav", f"D:/software/python/project/funasr_web/dataset/temp/0830_{name}.wav") 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!