-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_personalisations.py
80 lines (62 loc) · 2.7 KB
/
generate_personalisations.py
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
import os
from bark import preload_models
from distutils.dir_util import copy_tree
from utilities import (
create_or_reuse_csv_with_all_data,
generate_sound_file,
get_all_files_to_edit_manually,
find_csvs,
get_data,
insert_value_in_column,
get_value_from_column,
play_sound_and_get_feedback_from_human,
)
os.system("cls")
name = input("What name do you want to generate? ").lower().strip()
file_dir = os.path.join("createdPersonalisations", name)
# Copy personalisations to a new folder
copy_tree("personalisationTemplate", file_dir)
csv_files = find_csvs(file_dir)
# Combine all csv data into one list of tuples, each tuple is (path, text)
data = [item for csv_file in csv_files for item in get_data(csv_file)]
all_data_path = os.path.join(file_dir, "all_data.csvfile")
create_or_reuse_csv_with_all_data(data, all_data_path)
# Download and load all voice models
print("Loading voice models...")
preload_models()
for entry in data:
satisfied = False
while not satisfied:
already_approved = get_value_from_column(all_data_path, entry[0], 3)
if already_approved is not None:
print(f"Skipping {entry[0]} because it is already approved with value: {already_approved}")
break
phrase = f"{entry[1]} {name}"
wave_obj = generate_sound_file(entry[0], phrase)
# Ask the user if they are satisfied with the sound
user_input = play_sound_and_get_feedback_from_human(phrase, wave_obj)
while user_input == 'r':
print("Re-playing...")
user_input = play_sound_and_get_feedback_from_human(phrase, wave_obj)
if user_input == 'y':
insert_value_in_column(all_data_path, entry[0], user_input, 3)
satisfied = True
elif user_input == 'e':
insert_value_in_column(all_data_path, entry[0], user_input, 3)
satisfied = True
else:
print("Re-generating...")
# Get all files marked as 'e' in all_data.csvfile
files_to_edit_manually = get_all_files_to_edit_manually(all_data_path)
#Write all files marked as 'e' to a file
files_to_edit_path = os.path.join(file_dir, "files_to_edit_manually.txt")
with open(files_to_edit_path, "w") as myfile:
for f in files_to_edit_manually:
myfile.write(f"{f}\n")
# Remove all csv files from the folder tree, they cause problems in crew chief
for csv_file in csv_files:
os.remove(csv_file)
print("\n-------------------------------------------\n")
print(f"All done! The files are located in:\n{os.path.abspath(file_dir)}"
f"\n\nYou need to manually edit the files listed in: \n{os.path.abspath(files_to_edit_path)} to make them sound good")
print("\n-------------------------------------------\n")