-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
98 lines (83 loc) · 3.34 KB
/
util.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import json
import subprocess
import sys
default_models = [
# {"fileId": "123", "path": "./models/female-1"},
# {"fileId": "456", "path": "./models/female-2"},
# {"fileId": "456", "path": "./models/female-3"},
# {"fileId": "456", "path": "./models/female-4"},
# {"fileId": "456", "path": "./models/male-1"},
# {"fileId": "456", "path": "./models/male-2"},
{"fileId": "1EhulXaigTfnjw3RTFUZsKVVhD7zyxwWC", "path": "./models/male-3"},
]
def get_models():
result = []
base_path = "./models"
# Iterate over each folder in the base directory
for folder_name in os.listdir(base_path):
folder_path = os.path.join(base_path, folder_name)
if os.path.isdir(folder_path):
config_path = os.path.join(folder_path, 'config.json')
if os.path.isfile(config_path):
# Read the config.json file
with open(config_path, 'r') as config_file:
config_data = json.load(config_file)
# Extract the key under the "spk" field
spk_key = list(config_data['spk'].keys())[0]
result.append((folder_name, spk_key))
return result
def get_speakers():
result = []
base_path = "./models"
# Iterate over each folder in the base directory
for folder_name in os.listdir(base_path):
folder_path = os.path.join(base_path, folder_name)
if os.path.isdir(folder_path):
config_path = os.path.join(folder_path, 'config.json')
if os.path.isfile(config_path):
# Read the config.json file
with open(config_path, 'r') as config_file:
config_data = json.load(config_file)
# Extract the key under the "spk" field
spk_key = list(config_data['spk'].keys())[0]
result.append(spk_key)
return result
def get_config():
with open('config.json', 'r') as file:
data = json.load(file)
return data
def check_config():
file_path = 'config.json'
required_fields = [
"cleanup",
"convolution_reverb_dry_wet",
"stereo_spread",
"drift",
"base_detune",
"detune_drift",
"detune_frequency",
"output_gain"
]
try:
config = get_config()
except FileNotFoundError:
raise Exception(f"The file {file_path} does not exist.")
except json.JSONDecodeError:
raise Exception(f"The file {file_path} is not a valid JSON file.")
missing_fields = [field for field in required_fields if field not in config]
if missing_fields:
raise Exception(f"The following required fields are missing in the config: {', '.join(missing_fields)}")
if config["detune_drift"] * 4 > config["base_detune"]:
raise Exception(f"detune_drift can't be more than 25% of base_detune")
return config
def run_command(command):
# Create a copy of the current environment
env = os.environ.copy()
# Update the PATH variable to include additional paths
env["PATH"] = f"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:{env['PATH']}"
process = subprocess.Popen(command, env=env)
process.wait()
if process.returncode != 0:
print(f"Command {command} failed with return code {process.returncode}")
sys.exit(process.returncode)