|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
row_ = json.dumps(row, ensure_ascii=False, indent=4) |
|
|
print(row_) |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|