jerpint commited on
Commit
618e8fc
·
1 Parent(s): 3c13b6c

add logic to create metadata-valid.csv file

Browse files
Files changed (1) hide show
  1. create_json.py +85 -24
create_json.py CHANGED
@@ -1,31 +1,92 @@
1
- """Create a JSON file mapping of available audio files to the TTS models that generated them.
2
-
3
- The output JSON has the following structure:
4
- {
5
- "path1.mp3": [
6
- "model1",
7
- "model2",
8
- ...
9
- ],
10
- "path2.mp3": [
11
- "model1",
12
- ...
13
- ],
14
- ...
15
- }
16
- """
17
  from collections import defaultdict
18
  import json
19
  import os
20
  import pandas as pd
21
 
22
- df = pd.read_csv("metadata-balanced.csv")
23
- models = ["commonvoice", "metavoice", "playht", "stylettsv2", "xttsv2"]
24
- ds = defaultdict(list)
25
- for path in df.path:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  for model in models:
27
- if os.path.exists(os.path.join(model, path)):
28
- ds[path].append(model)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- with open("files.json", "w") as json_file:
31
- json.dump(ds, json_file, indent=4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from collections import defaultdict
2
  import json
3
  import os
4
  import pandas as pd
5
 
6
+
7
+ def create_json(df, models, output_json):
8
+ """Create a dictionary file mapping of available audio files to the TTS models that generated them.
9
+
10
+ The output JSON has the following structure:
11
+ {
12
+ "path1.mp3": [
13
+ "model1",
14
+ "model2",
15
+ ...
16
+ ],
17
+ "path2.mp3": [
18
+ "model1",
19
+ ...
20
+ ],
21
+ ...
22
+ }
23
+ """
24
+
25
+ data = defaultdict(list)
26
+
27
+ # For each path, add the model if the file exists
28
+ for path in df.path:
29
+ for model in models:
30
+ if os.path.exists(os.path.join(model, path)):
31
+ data[path].append(model)
32
+
33
+ # Save to JSON file (Currently used in gradio app, keep it for now)
34
+ with open(output_json, "w") as json_file:
35
+ json.dump(data, json_file, indent=4)
36
+ return data
37
+
38
+
39
+ if __name__ == "__main__":
40
+
41
+ output_json = "files.json"
42
+ output_csv = "metadata-valid.csv"
43
+ metadata_csv = "metadata-balanced.csv"
44
+ models = ["commonvoice", "metavoice", "playht", "stylettsv2", "xttsv2"]
45
+
46
+ # Load the metadata
47
+ df = pd.read_csv(metadata_csv)
48
+
49
+ # Create the JSON file
50
+ data = create_json(df, models, output_json)
51
+
52
+ # Get paths that are only available for all models
53
+ valid_paths = [path for path in data if len(data[path]) == len(models)]
54
+
55
+ # Filter dataframe to only include valid paths
56
+ valid_df = df[df.path.isin(valid_paths)]
57
+
58
+ # Create an entry for each model in csv
59
+ all_dfs = []
60
  for model in models:
61
+ valid_df_model = valid_df.copy()
62
+ valid_df_model["source"] = model
63
+ all_dfs.append(valid_df_model)
64
+
65
+ # Add is_cloned_voice column
66
+ is_cloned_voice = model != "commonvoice"
67
+ valid_df_model["is_cloned_voice"] = is_cloned_voice
68
+
69
+ # Add fname column
70
+ valid_df_model["fname"] = valid_df_model["path"]
71
+
72
+ # Add path column
73
+ valid_df_model["path"] = valid_df_model["path"].apply(
74
+ lambda path: os.path.join(model, path)
75
+ )
76
+
77
+ all_df = pd.concat(all_dfs, ignore_index=True)
78
+ all_df.to_csv(output_csv, index=False)
79
+
80
+ print("Statistics:")
81
+ print("Number of original voices: ", len(all_df[all_df.is_cloned_voice == False]))
82
+ print("Number of cloned voices: ", len(all_df[all_df.is_cloned_voice == True]))
83
+ print("Number of TOTAL voices: ", len(all_df))
84
+ print()
85
+
86
+ print("Gender distribution (total):")
87
+ print(all_df.gender.value_counts())
88
+ print()
89
 
90
+ print("Gender distribution (not cloned):")
91
+ print(all_df[all_df.is_cloned_voice == False].gender.value_counts())
92
+ print()