File size: 2,912 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 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
from collections import defaultdict
from pathlib import Path
import shutil
import pandas as pd
from project_settings import project_path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--audio_dir",
# default=(project_path / "data/analysis/hu-HU").as_posix(),
default=r"D:\Users\tianx\HuggingSpaces\cc_audio_8\data\make_analysis_excel\download_wav\20251204",
type=str
)
parser.add_argument(
"--output_dir",
# default=(project_path / "data/calling/52").as_posix(),
default=r"D:\Users\tianx\HuggingSpaces\cc_audio_8\data\make_analysis_excel\download_wav\20251204\52",
type=str
)
parser.add_argument(
"--output_file",
default=r"D:\Users\tianx\HuggingSpaces\cc_audio_8\data\make_analysis_excel\download_wav\20251204\52\readme.xlsx",
type=str
)
args = parser.parse_args()
return args
def main():
args = get_args()
audio_dir = Path(args.audio_dir)
output_dir = Path(args.output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
output_file = Path(args.output_file)
output_file.parent.mkdir(parents=True, exist_ok=True)
suffix_count = 0
call_id_to_wav_file_list = defaultdict(list)
for filename in audio_dir.glob("*.wav"):
splits = filename.stem.split("_")
# print(splits)
call_id = splits[2]
# language = splits[4]
# scene_id = splits[5]
print(f"call_id: {call_id}")
call_id_to_wav_file_list[call_id].append(filename)
print(f"count: {len(call_id_to_wav_file_list)}")
result = list()
for filename in audio_dir.glob("early_media_*.wav"):
splits = filename.stem.split("_")
# print(splits)
call_id = splits[2]
print(f"call_id: {call_id}")
suffix = f"{suffix_count:03}"
tgt_dir = output_dir / suffix
tgt_dir.mkdir(parents=True, exist_ok=True)
suffix_count += 1
wav_file_list = call_id_to_wav_file_list[call_id]
for wav_file in wav_file_list:
if wav_file.stem.startswith("active_media"):
tgt_filename = tgt_dir / f"active_media_{call_id}.wav"
elif wav_file.stem.startswith("early_media"):
tgt_filename = tgt_dir / f"early_media_{call_id}.wav"
elif wav_file.stem.startswith("active_media"):
continue
else:
raise AssertionError
shutil.copy(
wav_file.as_posix(),
tgt_filename.as_posix(),
)
result.append({
"suffix": suffix,
"call_id": call_id,
})
result = pd.DataFrame(result)
result.to_excel(
output_file.as_posix(),
index=False
)
return
if __name__ == "__main__":
main()
|