File size: 6,260 Bytes
21a0491 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import json
from collections import defaultdict
from pathlib import Path
import shutil
import pandas as pd
from gradio_client import Client, handle_file
from project_settings import project_path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--audio_dir",
default=(project_path / "data/analysis/pt-BR").as_posix(),
type=str
)
parser.add_argument(
"--output_file",
default=(project_path / "data/excel/pt-BR.jsonl").as_posix(),
type=str
)
args = parser.parse_args()
return args
def get_simulate_label(label: str):
splits = label.split("_and_")
if len(splits) != 2:
raise AssertionError(f"invalid label: {label}")
label0 = splits[0]
label1 = splits[1]
if label1 in ("not_connected", "not_connected2"):
if label0 in ("bell",):
result = "响铃"
elif label0 in ("mute",):
result = "静音"
elif label0 in ("out_of_service",
"busy", "unavailable",
"busy_or_disconnected_or_out_of_coverage",
"disconnected_or_out_of_service",
"unavailable_or_out_of_service", "blocked_or_cannot_receive_this_call", "invalid_number", "unable_to_complete_this_call"
):
result = "运营商提示音"
elif label0 in ("early_media_voicemail", "early_media_voicemail_is_full"):
result = "留言信箱"
else:
raise AssertionError(f"invalid label: {label}")
else:
if label1 in ("voicemail", "mute_1_second_then_voicemail", "di_then_mute", "mute_4_second_then_voicemail"):
result = "语音信箱"
elif label1 in ("mute",):
result = "静音"
elif label1 in ("voice",):
result = "真人"
elif label1 in ("noise_mute", "noise"):
result = "其它"
else:
raise AssertionError(f"invalid label: {label}")
return result
s3_kwargs1 = {
"client": "aliyun",
"bucket_endpoint": "https://aicc-sit.oss-ap-southeast-1.aliyuncs.com",
"endpoint": "https://oss-ap-southeast-1.aliyuncs.com",
"region": "oss-ap-southeast-1",
"secret_key": "o3qdtbZLSZQR6OWZPYsiOmb5Zza5LF",
"secret_id": "LTAI5tCWWqAE7TBPn9fwhkoS",
"bucket": "aicc-sit",
}
s3_kwargs = {
"client": "botocore_s3",
"bucket_endpoint": "https://aicc-dev.oss-ap-southeast-1.aliyuncs.com",
"endpoint": "https://oss-ap-southeast-1.aliyuncs.com",
"region": "oss-ap-southeast-1",
"bucket": "aicc-dev",
"secret_id": "LTAI5tDFukW5fEJw5ezXGp3d",
"secret_key": "hiPGyeco2IsY0FwBZBwAbCWXAFnggA"
}
def main():
args = get_args()
audio_dir = Path(args.audio_dir)
output_file = Path(args.output_file)
output_file.parent.mkdir(parents=True, exist_ok=True)
client = Client("http://127.0.0.1:7861/")
language = audio_dir.parts[-1]
call_id_to_wav_file_list = defaultdict(list)
for filename in audio_dir.glob("**/*.wav"):
splits = filename.stem.split("_")
call_id = splits[3]
language = splits[4]
scene_id = splits[5]
call_id_to_wav_file_list[call_id].append(filename)
print(f"count: {len(call_id_to_wav_file_list)}")
result = list()
with open(output_file.as_posix(), "a+", encoding="utf-8") as f:
for call_id, wav_file_list in call_id_to_wav_file_list.items():
print(call_id)
label = None
early_media_r_size = 0
active_media_r_size = 0
early_media_r_url = None
active_media_r_url = None
for wav_file in wav_file_list:
wav_file = Path(wav_file)
if wav_file.stem.startswith("early_media_r"):
label = wav_file.parts[-2]
early_media_r_size = wav_file.stat().st_size
url_path = f"audio_tag/20251114/{language}/{label}/{wav_file.name}"
js, message = client.predict(
filename=handle_file(wav_file.as_posix()),
url_path=url_path,
s3_kwargs=json.dumps(s3_kwargs),
api_name="/when_click_upload_to_s3"
)
if message == "success":
early_media_r_url = f'{s3_kwargs["bucket_endpoint"]}/{url_path}'
print(f"early_media_r_url: {early_media_r_url}, message: {message}")
if wav_file.stem.startswith("active_media_r"):
label = wav_file.parts[-2]
active_media_r_size = wav_file.stat().st_size
url_path = f"audio_tag/20251114/{language}/{label}/{wav_file.name}"
active_media_r_url, message = client.predict(
filename=handle_file(wav_file.as_posix()),
url_path=url_path,
s3_kwargs=json.dumps(s3_kwargs),
api_name="/when_click_upload_to_s3"
)
if message == "success":
active_media_r_url = f'{s3_kwargs["bucket_endpoint"]}/{url_path}'
print(f"active_media_r_url: {active_media_r_url}, message: {message}")
simulate_label = get_simulate_label(label)
row = {
"label": label,
"early_media_r_size": early_media_r_size,
"active_media_r_size": active_media_r_size,
"是否接通": "是" if active_media_r_size != 44 else "否",
"模拟类型": simulate_label,
"接通前URL": early_media_r_url,
"接通后URL": active_media_r_url,
}
row_ = json.dumps(row, ensure_ascii=False)
f.write(f"{row_}\n")
f.flush()
# result.append(row)
row_ = json.dumps(row, ensure_ascii=False, indent=4)
print(row_)
# result = pd.DataFrame(result)
# result.to_excel(output_file.as_posix(), index=False)
return
if __name__ == "__main__":
main()
|