File size: 4,056 Bytes
b8184f0
 
 
 
 
 
 
 
88c5e5a
b8184f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import random
import pandas as pd
import shutil
import uuid


# Provided file folder addresses (replace with actual paths)
common_dir = "vitsGPT/vits/"
# Add the new gt_wav folder
gt_wav_folder = f"{common_dir}DUMMY5/gt_test_wav/"  # Replace 'path_to_gt_wav' with your actual path
folders = [
    f"{common_dir}DUMMY5/gt_test_wav/",
    f"{common_dir}ori_vits/logs/emovdb_base_pretrained16/G_100000/model_test_wav/",
    f"{common_dir}emo_vits/logs/emovdb_emo_add_ave_pretrained16/G_100000/model_test_wav/",
    f"{common_dir}emo_vits/logs/emovdb_emo_add_bert_cls_pretrained16/G_100000/model_test_wav/",
    f"{common_dir}sem_vits/logs/emovdb_sem_mat_text_pretrained16/G_100000/model_test_wav/",
    f"{common_dir}sem_vits/logs/emovdb_sem_mat_phone_pretrained16/G_100000/model_test_wav/",
    f"{common_dir}sem_vits/logs/emovdb_sem_mat_bert_text_pretrained16/G_100000/model_test_wav/",
    f"{common_dir}sem_vits/logs/emovdb_sem_mat_bert_phone_pretrained16/G_100000/model_test_wav/",
]

num_extracted_files = 50

# 0. Create human_mos directory if it doesn't exist
human_smos_dir = os.path.join(common_dir, "human_evaluation_emovdb/human_esmos_wavs")
if not os.path.exists(human_smos_dir):
    os.makedirs(human_smos_dir)
    
# 1. Check if every folder has the same number and names of files
reference_files = set(os.listdir(folders[0]))
consistent = all(set(os.listdir(folder)) == reference_files for folder in folders)
if not consistent:
    raise ValueError("Folders do not have consistent file names or counts.")

# Checking if the gt_wav folder has the same files as the reference
if not set(os.listdir(gt_wav_folder)) == reference_files:
    raise ValueError("gt_wav folder does not have consistent file names or counts with the reference.")

# 2. Extract, rename, and copy files from each folder
sample_files = random.sample(list(reference_files), num_extracted_files)
# Generate a shuffled list of numbers for renaming
numbers = list(range(len(sample_files) * len(folders)))
random.shuffle(numbers)

renamed_files_paths = {}
for orig in sample_files:
    for folder in folders:
        # new_name = f"{len(renamed_files_paths)}.wav"
        
        # Use UUID to generate a random file name
        # new_name = f"{uuid.uuid4().hex}.wav"
        
        # Use shuffled number for renaming
        new_name = f"{numbers.pop()}.wav"
        
        src = os.path.join(folder, orig)
        dst = os.path.join(human_smos_dir, new_name)
        shutil.copy(src, dst)
        renamed_files_paths[src] = new_name
        
        # Handling the paired file from gt_wav_folder
        gt_src = os.path.join(gt_wav_folder, orig)
        gt_dst = os.path.join(human_smos_dir, new_name.split('.')[0] + '_gt.wav')
        shutil.copy(gt_src, gt_dst)
        
df_named_score = pd.DataFrame({
    "original_file_path": list(renamed_files_paths.keys()),
    "innominated_file_path": list(renamed_files_paths.values())
})

# 3. Create innominated_score.xlsx
df_innominated_score = pd.DataFrame({
    "file_name": list(renamed_files_paths.values()),
    "Emo/Not": "",
    "SMOS_score": "",
})

# Save to excel
df_combined = pd.concat([df_innominated_score])
df_named_score.to_excel("emovdb_named_smos_score.xlsx", index=False)
df_combined.to_excel("emovdb_innominated_smos_score.xlsx", index=False)

"Files created and copied successfully."





# 把输出的excel表格整理一下,按顺序写音频编号,方便annotator录入
# Load the original innominated_score.xlsx
df_to_sort = pd.read_excel("emovdb_innominated_smos_score.xlsx")
# Extract the number from the filename for each row
df_to_sort['sort_key'] = df_to_sort['file_name'].str.extract('(\d+)').astype(int)
# Sort the dataframe by this new column
df_sorted = df_to_sort.sort_values(by="sort_key")
# Drop the 'sort_key' column as it's no longer needed
df_sorted = df_sorted.drop(columns=['sort_key'])
# Save the sorted dataframe as scoring.xlsx
df_sorted.to_excel("emovdb_smos_scoring.xlsx", index=False)
print("File 'emovdb_smos_scoring.xlsx' created and sorted successfully.")