Delete race_audio/.ipynb_checkpoints
Browse files- race_audio/.ipynb_checkpoints/filter-checkpoint.py +0 -197
- race_audio/.ipynb_checkpoints/race_benchmark-checkpoint.json +0 -0
- race_audio/.ipynb_checkpoints/race_benchmark_origin-checkpoint.json +0 -0
- race_audio/.ipynb_checkpoints/race_long_audio_search_results_270s-checkpoint.json +0 -14
- race_audio/.ipynb_checkpoints/race_results-checkpoint.json +0 -0
- race_audio/.ipynb_checkpoints/race_timing-checkpoint.json +0 -0
- race_audio/.ipynb_checkpoints/serch_audio-checkpoint.py +0 -191
race_audio/.ipynb_checkpoints/filter-checkpoint.py
DELETED
|
@@ -1,197 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
根据音频时长过滤race_benchmark.json,生成新的benchmark文件
|
| 4 |
-
仅保留音频时长在指定时间以上的QA对
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import json
|
| 8 |
-
import os
|
| 9 |
-
import librosa
|
| 10 |
-
import soundfile as sf
|
| 11 |
-
from collections import defaultdict
|
| 12 |
-
import argparse
|
| 13 |
-
|
| 14 |
-
def get_audio_duration(audio_path):
|
| 15 |
-
"""获取音频文件的时长(秒)"""
|
| 16 |
-
try:
|
| 17 |
-
# 使用librosa获取音频时长(更快,只读取header)
|
| 18 |
-
duration = librosa.get_duration(path=audio_path)
|
| 19 |
-
return duration
|
| 20 |
-
except Exception as e:
|
| 21 |
-
try:
|
| 22 |
-
# 备选方案:使用soundfile
|
| 23 |
-
info = sf.info(audio_path)
|
| 24 |
-
duration = info.frames / info.samplerate
|
| 25 |
-
return duration
|
| 26 |
-
except Exception as e2:
|
| 27 |
-
print(f"无法读取音频文件 {audio_path}: {e2}")
|
| 28 |
-
return 0
|
| 29 |
-
|
| 30 |
-
def format_duration(seconds):
|
| 31 |
-
"""将秒数格式化为分:秒的形式"""
|
| 32 |
-
minutes = int(seconds // 60)
|
| 33 |
-
secs = int(seconds % 60)
|
| 34 |
-
return f"{minutes}:{secs:02d}"
|
| 35 |
-
|
| 36 |
-
def filter_race_benchmark_by_duration(race_audio_dir, race_benchmark_path, min_duration_seconds=120):
|
| 37 |
-
"""
|
| 38 |
-
根据音频时长过滤race_benchmark.json,生成新的benchmark文件
|
| 39 |
-
|
| 40 |
-
Args:
|
| 41 |
-
race_audio_dir: race_audio目录路径
|
| 42 |
-
race_benchmark_path: race_benchmark.json文件路径
|
| 43 |
-
min_duration_seconds: 最小时长(秒),默认120秒=2分钟
|
| 44 |
-
"""
|
| 45 |
-
|
| 46 |
-
# 检查文件是否存在
|
| 47 |
-
if not os.path.exists(race_benchmark_path):
|
| 48 |
-
print(f"错误: 找不到benchmark文件: {race_benchmark_path}")
|
| 49 |
-
return
|
| 50 |
-
|
| 51 |
-
if not os.path.exists(race_audio_dir):
|
| 52 |
-
print(f"错误: 找不到音频目录: {race_audio_dir}")
|
| 53 |
-
return
|
| 54 |
-
|
| 55 |
-
# 加载benchmark JSON
|
| 56 |
-
print(f"加载benchmark文件: {race_benchmark_path}")
|
| 57 |
-
with open(race_benchmark_path, "r", encoding="utf-8") as f:
|
| 58 |
-
benchmark_data = json.load(f)
|
| 59 |
-
|
| 60 |
-
print(f"原始benchmark包含 {len(benchmark_data)} 个QA对")
|
| 61 |
-
|
| 62 |
-
# 获取所有唯一的音频文件路径并检查时长
|
| 63 |
-
audio_durations = {}
|
| 64 |
-
unique_audio_paths = set()
|
| 65 |
-
|
| 66 |
-
for item in benchmark_data:
|
| 67 |
-
audio_rel_path = item["audio_path"]
|
| 68 |
-
unique_audio_paths.add(audio_rel_path)
|
| 69 |
-
|
| 70 |
-
print(f"找到 {len(unique_audio_paths)} 个唯一音频文件")
|
| 71 |
-
print(f"开始检查音频文件时长(最小时长: {format_duration(min_duration_seconds)})...")
|
| 72 |
-
|
| 73 |
-
# 检查每个音频文件的时长
|
| 74 |
-
for i, audio_rel_path in enumerate(unique_audio_paths, 1):
|
| 75 |
-
audio_full_path = os.path.join(race_audio_dir, audio_rel_path)
|
| 76 |
-
|
| 77 |
-
if not os.path.exists(audio_full_path):
|
| 78 |
-
print(f"警告: 文件不存在 {audio_full_path}")
|
| 79 |
-
audio_durations[audio_rel_path] = 0 # 不存在的文件时长设为0
|
| 80 |
-
continue
|
| 81 |
-
|
| 82 |
-
# 获取音频时长
|
| 83 |
-
duration = get_audio_duration(audio_full_path)
|
| 84 |
-
audio_durations[audio_rel_path] = duration
|
| 85 |
-
|
| 86 |
-
# 每处理100个文件显示一次进度
|
| 87 |
-
if i % 100 == 0:
|
| 88 |
-
print(f"已处理 {i}/{len(unique_audio_paths)} 个音频文件")
|
| 89 |
-
|
| 90 |
-
# 过滤QA对,只保留音频时长满足要求的
|
| 91 |
-
filtered_benchmark_data = []
|
| 92 |
-
long_audio_count = 0
|
| 93 |
-
|
| 94 |
-
for item in benchmark_data:
|
| 95 |
-
audio_rel_path = item["audio_path"]
|
| 96 |
-
duration = audio_durations.get(audio_rel_path, 0)
|
| 97 |
-
|
| 98 |
-
if duration >= min_duration_seconds:
|
| 99 |
-
filtered_benchmark_data.append(item)
|
| 100 |
-
|
| 101 |
-
# 统计结果
|
| 102 |
-
long_audio_paths = set()
|
| 103 |
-
for item in filtered_benchmark_data:
|
| 104 |
-
long_audio_paths.add(item["audio_path"])
|
| 105 |
-
|
| 106 |
-
print(f"\n=== 过滤结果 ===")
|
| 107 |
-
print(f"原始QA对数量: {len(benchmark_data)}")
|
| 108 |
-
print(f"过滤后QA对数量: {len(filtered_benchmark_data)}")
|
| 109 |
-
print(f"保留的音频文件数: {len(long_audio_paths)}")
|
| 110 |
-
print(f"保留比例: {len(filtered_benchmark_data)/len(benchmark_data)*100:.1f}%")
|
| 111 |
-
|
| 112 |
-
# 显示保留的音频文件统计
|
| 113 |
-
long_audio_info = []
|
| 114 |
-
for audio_path in long_audio_paths:
|
| 115 |
-
duration = audio_durations[audio_path]
|
| 116 |
-
long_audio_info.append({
|
| 117 |
-
"audio_path": audio_path,
|
| 118 |
-
"duration_seconds": duration,
|
| 119 |
-
"duration_formatted": format_duration(duration),
|
| 120 |
-
"qa_count": sum(1 for item in filtered_benchmark_data if item["audio_path"] == audio_path)
|
| 121 |
-
})
|
| 122 |
-
|
| 123 |
-
# 按时长降序排序
|
| 124 |
-
long_audio_info.sort(key=lambda x: x["duration_seconds"], reverse=True)
|
| 125 |
-
|
| 126 |
-
print(f"\n保留的音频文件详情(按时长降序):")
|
| 127 |
-
for i, info in enumerate(long_audio_info[:10], 1): # 只显示前10个
|
| 128 |
-
print(f"{i:2d}. {info['audio_path']}")
|
| 129 |
-
print(f" 时长: {info['duration_formatted']} ({info['duration_seconds']:.1f}秒)")
|
| 130 |
-
print(f" QA对数量: {info['qa_count']}")
|
| 131 |
-
|
| 132 |
-
if len(long_audio_info) > 10:
|
| 133 |
-
print(f" ... 还有 {len(long_audio_info) - 10} 个音频文件")
|
| 134 |
-
|
| 135 |
-
# ��存过滤后的benchmark到新文件
|
| 136 |
-
output_file = f"race_benchmark_filtered_{min_duration_seconds}s.json"
|
| 137 |
-
with open(output_file, "w", encoding="utf-8") as f:
|
| 138 |
-
json.dump(filtered_benchmark_data, f, ensure_ascii=False, indent=2)
|
| 139 |
-
|
| 140 |
-
print(f"\n过滤后的benchmark已保存到: {output_file}")
|
| 141 |
-
|
| 142 |
-
# 统计信息
|
| 143 |
-
all_durations = list(audio_durations.values())
|
| 144 |
-
if all_durations:
|
| 145 |
-
avg_duration = sum(all_durations) / len(all_durations)
|
| 146 |
-
max_duration = max(all_durations)
|
| 147 |
-
min_duration = min(all_durations)
|
| 148 |
-
|
| 149 |
-
print(f"\n=== 统计信息 ===")
|
| 150 |
-
print(f"总音频文件数: {len(all_durations)}")
|
| 151 |
-
print(f"平均时长: {format_duration(avg_duration)} ({avg_duration:.1f}秒)")
|
| 152 |
-
print(f"最长时长: {format_duration(max_duration)} ({max_duration:.1f}秒)")
|
| 153 |
-
print(f"最短时长: {format_duration(min_duration)} ({min_duration:.1f}秒)")
|
| 154 |
-
print(f"长音频占比: {len(long_audio_paths)}/{len(all_durations)} ({len(long_audio_paths)/len(all_durations)*100:.1f}%)")
|
| 155 |
-
|
| 156 |
-
return filtered_benchmark_data
|
| 157 |
-
|
| 158 |
-
def main():
|
| 159 |
-
parser = argparse.ArgumentParser(description="根据音频时长过滤race_benchmark.json,生成新的benchmark文件")
|
| 160 |
-
parser.add_argument("--race_audio_dir", default="/root/autodl-tmp/project/Phi-4-multimodal-instruct/eval/test/race_audio",
|
| 161 |
-
help="race_audio目录路径 (默认: ./race_audio)")
|
| 162 |
-
parser.add_argument("--benchmark_json", default="./race_benchmark.json",
|
| 163 |
-
help="race_benchmark.json文件路径 (默认: ./race_benchmark.json)")
|
| 164 |
-
parser.add_argument("--min_duration", type=str, default="2:00",
|
| 165 |
-
help="最小时长,格式为 M:SS (默认: 2:00)")
|
| 166 |
-
|
| 167 |
-
args = parser.parse_args()
|
| 168 |
-
|
| 169 |
-
# 解析时长参数
|
| 170 |
-
try:
|
| 171 |
-
if ":" in args.min_duration:
|
| 172 |
-
parts = args.min_duration.split(":")
|
| 173 |
-
minutes = int(parts[0])
|
| 174 |
-
seconds = int(parts[1])
|
| 175 |
-
min_duration_seconds = minutes * 60 + seconds
|
| 176 |
-
else:
|
| 177 |
-
min_duration_seconds = int(args.min_duration)
|
| 178 |
-
except ValueError:
|
| 179 |
-
print(f"错误: 无效的时长格式 '{args.min_duration}'")
|
| 180 |
-
print("请使用格式 'M:SS' (如 2:00) 或直接输入秒数")
|
| 181 |
-
return
|
| 182 |
-
|
| 183 |
-
print(f"过滤条件:")
|
| 184 |
-
print(f" race_audio目录: {args.race_audio_dir}")
|
| 185 |
-
print(f" benchmark文件: {args.benchmark_json}")
|
| 186 |
-
print(f" 最小时长: {args.min_duration} ({min_duration_seconds}秒)")
|
| 187 |
-
print()
|
| 188 |
-
|
| 189 |
-
# 执行过滤
|
| 190 |
-
filter_race_benchmark_by_duration(
|
| 191 |
-
race_audio_dir=args.race_audio_dir,
|
| 192 |
-
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
race_audio/.ipynb_checkpoints/race_benchmark-checkpoint.json
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
race_audio/.ipynb_checkpoints/race_benchmark_origin-checkpoint.json
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
race_audio/.ipynb_checkpoints/race_long_audio_search_results_270s-checkpoint.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"search_criteria": {
|
| 3 |
-
"min_duration_seconds": 270,
|
| 4 |
-
"min_duration_formatted": "4:30"
|
| 5 |
-
},
|
| 6 |
-
"total_files_found": 0,
|
| 7 |
-
"long_audio_files": [],
|
| 8 |
-
"statistics": {
|
| 9 |
-
"total_audio_files": 1384,
|
| 10 |
-
"avg_duration_seconds": 94.15662933526019,
|
| 11 |
-
"max_duration_seconds": 253.125,
|
| 12 |
-
"min_duration_seconds": 27.425
|
| 13 |
-
}
|
| 14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
race_audio/.ipynb_checkpoints/race_results-checkpoint.json
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
race_audio/.ipynb_checkpoints/race_timing-checkpoint.json
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
race_audio/.ipynb_checkpoints/serch_audio-checkpoint.py
DELETED
|
@@ -1,191 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
搜索race_audio中时长大于等于4分30秒的音频文件
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import os
|
| 8 |
-
import librosa
|
| 9 |
-
import soundfile as sf
|
| 10 |
-
from collections import defaultdict
|
| 11 |
-
import argparse
|
| 12 |
-
|
| 13 |
-
def get_audio_duration(audio_path):
|
| 14 |
-
"""获取音频文件的时长(秒)"""
|
| 15 |
-
try:
|
| 16 |
-
# 使用librosa获取音频时长(更快,只读取header)
|
| 17 |
-
duration = librosa.get_duration(path=audio_path)
|
| 18 |
-
return duration
|
| 19 |
-
except Exception as e:
|
| 20 |
-
try:
|
| 21 |
-
# 备选方案:使用soundfile
|
| 22 |
-
info = sf.info(audio_path)
|
| 23 |
-
duration = info.frames / info.samplerate
|
| 24 |
-
return duration
|
| 25 |
-
except Exception as e2:
|
| 26 |
-
print(f"无法读取音频文件 {audio_path}: {e2}")
|
| 27 |
-
return 0
|
| 28 |
-
|
| 29 |
-
def format_duration(seconds):
|
| 30 |
-
"""将秒数格式化为分:秒的形式"""
|
| 31 |
-
minutes = int(seconds // 60)
|
| 32 |
-
secs = int(seconds % 60)
|
| 33 |
-
return f"{minutes}:{secs:02d}"
|
| 34 |
-
|
| 35 |
-
def search_long_audio_files(race_audio_dir, race_benchmark_path, min_duration_seconds=270):
|
| 36 |
-
"""
|
| 37 |
-
搜索时长大于等于指定时间的音频文件
|
| 38 |
-
|
| 39 |
-
Args:
|
| 40 |
-
race_audio_dir: race_audio目录路径
|
| 41 |
-
race_benchmark_path: race_benchmark.json文件路径
|
| 42 |
-
min_duration_seconds: 最小时长(秒),默认270秒=4分30秒
|
| 43 |
-
"""
|
| 44 |
-
|
| 45 |
-
# 检查文件是否存在
|
| 46 |
-
if not os.path.exists(race_benchmark_path):
|
| 47 |
-
print(f"错误: 找不到benchmark文件: {race_benchmark_path}")
|
| 48 |
-
return
|
| 49 |
-
|
| 50 |
-
if not os.path.exists(race_audio_dir):
|
| 51 |
-
print(f"错误: 找不到音频目录: {race_audio_dir}")
|
| 52 |
-
return
|
| 53 |
-
|
| 54 |
-
# 加载benchmark JSON
|
| 55 |
-
print(f"加载benchmark文件: {race_benchmark_path}")
|
| 56 |
-
with open(race_benchmark_path, "r", encoding="utf-8") as f:
|
| 57 |
-
benchmark_data = json.load(f)
|
| 58 |
-
|
| 59 |
-
print(f"benchmark包含 {len(benchmark_data)} 个条目")
|
| 60 |
-
|
| 61 |
-
# 获取所有唯一的音频文件路径
|
| 62 |
-
unique_audio_paths = set()
|
| 63 |
-
for item in benchmark_data:
|
| 64 |
-
audio_rel_path = item["audio_path"]
|
| 65 |
-
unique_audio_paths.add(audio_rel_path)
|
| 66 |
-
|
| 67 |
-
print(f"找到 {len(unique_audio_paths)} 个唯一音频文件")
|
| 68 |
-
|
| 69 |
-
# 检查每个音频文件的时长
|
| 70 |
-
long_audio_files = []
|
| 71 |
-
audio_durations = {}
|
| 72 |
-
|
| 73 |
-
print(f"\n开始检查音频文件时长(最小时长: {format_duration(min_duration_seconds)})...")
|
| 74 |
-
|
| 75 |
-
for i, audio_rel_path in enumerate(unique_audio_paths, 1):
|
| 76 |
-
audio_full_path = os.path.join(race_audio_dir, audio_rel_path)
|
| 77 |
-
|
| 78 |
-
if not os.path.exists(audio_full_path):
|
| 79 |
-
print(f"警告: 文件不存在 {audio_full_path}")
|
| 80 |
-
continue
|
| 81 |
-
|
| 82 |
-
# 获取音频时长
|
| 83 |
-
duration = get_audio_duration(audio_full_path)
|
| 84 |
-
audio_durations[audio_rel_path] = duration
|
| 85 |
-
|
| 86 |
-
# 检查是否满足时长要求
|
| 87 |
-
if duration >= min_duration_seconds:
|
| 88 |
-
long_audio_files.append({
|
| 89 |
-
"audio_path": audio_rel_path,
|
| 90 |
-
"full_path": audio_full_path,
|
| 91 |
-
"duration_seconds": duration,
|
| 92 |
-
"duration_formatted": format_duration(duration)
|
| 93 |
-
})
|
| 94 |
-
|
| 95 |
-
# 每处理100个文件显示一次进度
|
| 96 |
-
if i % 100 == 0:
|
| 97 |
-
print(f"已处理 {i}/{len(unique_audio_paths)} 个音频文件")
|
| 98 |
-
|
| 99 |
-
# 按时长降序排序
|
| 100 |
-
long_audio_files.sort(key=lambda x: x["duration_seconds"], reverse=True)
|
| 101 |
-
|
| 102 |
-
# 显示结果
|
| 103 |
-
print(f"\n=== 搜索结果 ===")
|
| 104 |
-
print(f"找到 {len(long_audio_files)} 个时长大于等于 {format_duration(min_duration_seconds)} 的音频文件:")
|
| 105 |
-
|
| 106 |
-
if long_audio_files:
|
| 107 |
-
print("\n详细列表(按时长降序排列):")
|
| 108 |
-
for i, audio_info in enumerate(long_audio_files, 1):
|
| 109 |
-
print(f"{i:2d}. {audio_info['audio_path']}")
|
| 110 |
-
print(f" 时长: {audio_info['duration_formatted']} ({audio_info['duration_seconds']:.1f}秒)")
|
| 111 |
-
print(f" 完整路径: {audio_info['full_path']}")
|
| 112 |
-
print()
|
| 113 |
-
|
| 114 |
-
# 统计信息
|
| 115 |
-
all_durations = list(audio_durations.values())
|
| 116 |
-
if all_durations:
|
| 117 |
-
avg_duration = sum(all_durations) / len(all_durations)
|
| 118 |
-
max_duration = max(all_durations)
|
| 119 |
-
min_duration = min(all_durations)
|
| 120 |
-
|
| 121 |
-
print(f"=== 统计信息 ===")
|
| 122 |
-
print(f"总音频文件数: {len(all_durations)}")
|
| 123 |
-
print(f"平均时长: {format_duration(avg_duration)} ({avg_duration:.1f}秒)")
|
| 124 |
-
print(f"最长时长: {format_duration(max_duration)} ({max_duration:.1f}秒)")
|
| 125 |
-
print(f"最短时长: {format_duration(min_duration)} ({min_duration:.1f}秒)")
|
| 126 |
-
print(f"长音频占比: {len(long_audio_files)}/{len(all_durations)} ({len(long_audio_files)/len(all_durations)*100:.1f}%)")
|
| 127 |
-
|
| 128 |
-
# 保存结果到JSON文件
|
| 129 |
-
result_data = {
|
| 130 |
-
"search_criteria": {
|
| 131 |
-
"min_duration_seconds": min_duration_seconds,
|
| 132 |
-
"min_duration_formatted": format_duration(min_duration_seconds)
|
| 133 |
-
},
|
| 134 |
-
"total_files_found": len(long_audio_files),
|
| 135 |
-
"long_audio_files": long_audio_files,
|
| 136 |
-
"statistics": {
|
| 137 |
-
"total_audio_files": len(all_durations),
|
| 138 |
-
"avg_duration_seconds": avg_duration if all_durations else 0,
|
| 139 |
-
"max_duration_seconds": max_duration if all_durations else 0,
|
| 140 |
-
"min_duration_seconds": min_duration if all_durations else 0
|
| 141 |
-
}
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
output_file = f"race_long_audio_search_results_{min_duration_seconds}s.json"
|
| 145 |
-
with open(output_file, "w", encoding="utf-8") as f:
|
| 146 |
-
json.dump(result_data, f, ensure_ascii=False, indent=2)
|
| 147 |
-
|
| 148 |
-
print(f"\n结果已保存到: {output_file}")
|
| 149 |
-
|
| 150 |
-
return long_audio_files
|
| 151 |
-
|
| 152 |
-
def main():
|
| 153 |
-
parser = argparse.ArgumentParser(description="搜索race_audio中时长大于等于指定时间的音频文件")
|
| 154 |
-
parser.add_argument("--race_audio_dir", default="/root/autodl-tmp/project/Phi-4-multimodal-instruct/eval/test/race_audio",
|
| 155 |
-
help="race_audio目录路径 (默认: ./race_audio)")
|
| 156 |
-
parser.add_argument("--benchmark_json", default="./race_benchmark.json",
|
| 157 |
-
help="race_benchmark.json文件路径 (默认: ./race_benchmark.json)")
|
| 158 |
-
parser.add_argument("--min_duration", type=str, default="2:00",
|
| 159 |
-
help="最小时长,格式为 M:SS (默认: 4:30)")
|
| 160 |
-
|
| 161 |
-
args = parser.parse_args()
|
| 162 |
-
|
| 163 |
-
# 解析时长参数
|
| 164 |
-
try:
|
| 165 |
-
if ":" in args.min_duration:
|
| 166 |
-
parts = args.min_duration.split(":")
|
| 167 |
-
minutes = int(parts[0])
|
| 168 |
-
seconds = int(parts[1])
|
| 169 |
-
min_duration_seconds = minutes * 60 + seconds
|
| 170 |
-
else:
|
| 171 |
-
min_duration_seconds = int(args.min_duration)
|
| 172 |
-
except ValueError:
|
| 173 |
-
print(f"错误: 无效的时长格式 '{args.min_duration}'")
|
| 174 |
-
print("请使用格式 'M:SS' (如 4:30) 或直接输入秒数")
|
| 175 |
-
return
|
| 176 |
-
|
| 177 |
-
print(f"搜索条件:")
|
| 178 |
-
print(f" race_audio目录: {args.race_audio_dir}")
|
| 179 |
-
print(f" benchmark文件: {args.benchmark_json}")
|
| 180 |
-
print(f" 最小时长: {args.min_duration} ({min_duration_seconds}秒)")
|
| 181 |
-
print()
|
| 182 |
-
|
| 183 |
-
# 执行搜索
|
| 184 |
-
search_long_audio_files(
|
| 185 |
-
race_audio_dir=args.race_audio_dir,
|
| 186 |
-
race_benchmark_path=args.benchmark_json,
|
| 187 |
-
min_duration_seconds=min_duration_seconds
|
| 188 |
-
)
|
| 189 |
-
|
| 190 |
-
if __name__ == "__main__":
|
| 191 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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