mirror of
https://github.com/wassname/TTS.git
synced 2026-09-11 12:00:24 +08:00
reformatting and styling
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
# visualisation tools for mimic2
|
||||
import matplotlib.pyplot as plt
|
||||
from statistics import stdev, mode, mean, median
|
||||
from statistics import StatisticsError
|
||||
import argparse
|
||||
import os
|
||||
import csv
|
||||
import seaborn as sns
|
||||
import os
|
||||
import random
|
||||
from statistics import StatisticsError, mean, median, mode, stdev
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
from text.cmudict import CMUDict
|
||||
|
||||
|
||||
def get_audio_seconds(frames):
|
||||
return (frames*12.5)/1000
|
||||
return (frames * 12.5) / 1000
|
||||
|
||||
|
||||
def append_data_statistics(meta_data):
|
||||
@@ -27,9 +28,7 @@ def append_data_statistics(meta_data):
|
||||
median_audio_len = median(audio_len_list)
|
||||
|
||||
try:
|
||||
std = stdev(
|
||||
d["audio_len"] for d in data
|
||||
)
|
||||
std = stdev(d["audio_len"] for d in data)
|
||||
except StatisticsError:
|
||||
std = 0
|
||||
|
||||
@@ -44,24 +43,22 @@ def process_meta_data(path):
|
||||
meta_data = {}
|
||||
|
||||
# load meta data
|
||||
with open(path, 'r') as f:
|
||||
data = csv.reader(f, delimiter='|')
|
||||
with open(path, "r") as f:
|
||||
data = csv.reader(f, delimiter="|")
|
||||
for row in data:
|
||||
frames = int(row[2])
|
||||
utt = row[3]
|
||||
audio_len = get_audio_seconds(frames)
|
||||
char_count = len(utt)
|
||||
if not meta_data.get(char_count):
|
||||
meta_data[char_count] = {
|
||||
"data": []
|
||||
}
|
||||
meta_data[char_count] = {"data": []}
|
||||
|
||||
meta_data[char_count]["data"].append(
|
||||
{
|
||||
"utt": utt,
|
||||
"frames": frames,
|
||||
"audio_len": audio_len,
|
||||
"row": "{}|{}|{}|{}".format(row[0], row[1], row[2], row[3])
|
||||
"row": "{}|{}|{}|{}".format(row[0], row[1], row[2], row[3]),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -72,30 +69,30 @@ def process_meta_data(path):
|
||||
|
||||
def get_data_points(meta_data):
|
||||
x = meta_data
|
||||
y_avg = [meta_data[d]['mean'] for d in meta_data]
|
||||
y_mode = [meta_data[d]['mode'] for d in meta_data]
|
||||
y_median = [meta_data[d]['median'] for d in meta_data]
|
||||
y_std = [meta_data[d]['std'] for d in meta_data]
|
||||
y_num_samples = [len(meta_data[d]['data']) for d in meta_data]
|
||||
y_avg = [meta_data[d]["mean"] for d in meta_data]
|
||||
y_mode = [meta_data[d]["mode"] for d in meta_data]
|
||||
y_median = [meta_data[d]["median"] for d in meta_data]
|
||||
y_std = [meta_data[d]["std"] for d in meta_data]
|
||||
y_num_samples = [len(meta_data[d]["data"]) for d in meta_data]
|
||||
return {
|
||||
"x": x,
|
||||
"y_avg": y_avg,
|
||||
"y_mode": y_mode,
|
||||
"y_median": y_median,
|
||||
"y_std": y_std,
|
||||
"y_num_samples": y_num_samples
|
||||
"y_num_samples": y_num_samples,
|
||||
}
|
||||
|
||||
|
||||
def save_training(file_path, meta_data):
|
||||
rows = []
|
||||
for char_cnt in meta_data:
|
||||
data = meta_data[char_cnt]['data']
|
||||
data = meta_data[char_cnt]["data"]
|
||||
for d in data:
|
||||
rows.append(d['row'] + "\n")
|
||||
rows.append(d["row"] + "\n")
|
||||
|
||||
random.shuffle(rows)
|
||||
with open(file_path, 'w+') as f:
|
||||
with open(file_path, "w+") as f:
|
||||
for row in rows:
|
||||
f.write(row)
|
||||
|
||||
@@ -106,15 +103,15 @@ def plot(meta_data, save_path=None):
|
||||
save = True
|
||||
|
||||
graph_data = get_data_points(meta_data)
|
||||
x = graph_data['x']
|
||||
y_avg = graph_data['y_avg']
|
||||
y_std = graph_data['y_std']
|
||||
y_mode = graph_data['y_mode']
|
||||
y_median = graph_data['y_median']
|
||||
y_num_samples = graph_data['y_num_samples']
|
||||
x = graph_data["x"]
|
||||
y_avg = graph_data["y_avg"]
|
||||
y_std = graph_data["y_std"]
|
||||
y_mode = graph_data["y_mode"]
|
||||
y_median = graph_data["y_median"]
|
||||
y_num_samples = graph_data["y_num_samples"]
|
||||
|
||||
plt.figure()
|
||||
plt.plot(x, y_avg, 'ro')
|
||||
plt.plot(x, y_avg, "ro")
|
||||
plt.xlabel("character lengths", fontsize=30)
|
||||
plt.ylabel("avg seconds", fontsize=30)
|
||||
if save:
|
||||
@@ -122,7 +119,7 @@ def plot(meta_data, save_path=None):
|
||||
plt.savefig(os.path.join(save_path, name))
|
||||
|
||||
plt.figure()
|
||||
plt.plot(x, y_mode, 'ro')
|
||||
plt.plot(x, y_mode, "ro")
|
||||
plt.xlabel("character lengths", fontsize=30)
|
||||
plt.ylabel("mode seconds", fontsize=30)
|
||||
if save:
|
||||
@@ -130,7 +127,7 @@ def plot(meta_data, save_path=None):
|
||||
plt.savefig(os.path.join(save_path, name))
|
||||
|
||||
plt.figure()
|
||||
plt.plot(x, y_median, 'ro')
|
||||
plt.plot(x, y_median, "ro")
|
||||
plt.xlabel("character lengths", fontsize=30)
|
||||
plt.ylabel("median seconds", fontsize=30)
|
||||
if save:
|
||||
@@ -138,7 +135,7 @@ def plot(meta_data, save_path=None):
|
||||
plt.savefig(os.path.join(save_path, name))
|
||||
|
||||
plt.figure()
|
||||
plt.plot(x, y_std, 'ro')
|
||||
plt.plot(x, y_std, "ro")
|
||||
plt.xlabel("character lengths", fontsize=30)
|
||||
plt.ylabel("standard deviation", fontsize=30)
|
||||
if save:
|
||||
@@ -146,7 +143,7 @@ def plot(meta_data, save_path=None):
|
||||
plt.savefig(os.path.join(save_path, name))
|
||||
|
||||
plt.figure()
|
||||
plt.plot(x, y_num_samples, 'ro')
|
||||
plt.plot(x, y_num_samples, "ro")
|
||||
plt.xlabel("character lengths", fontsize=30)
|
||||
plt.ylabel("number of samples", fontsize=30)
|
||||
if save:
|
||||
@@ -159,8 +156,8 @@ def plot_phonemes(train_path, cmu_dict_path, save_path):
|
||||
|
||||
phonemes = {}
|
||||
|
||||
with open(train_path, 'r') as f:
|
||||
data = csv.reader(f, delimiter='|')
|
||||
with open(train_path, "r") as f:
|
||||
data = csv.reader(f, delimiter="|")
|
||||
phonemes["None"] = 0
|
||||
for row in data:
|
||||
words = row[3].split()
|
||||
@@ -192,15 +189,12 @@ def plot_phonemes(train_path, cmu_dict_path, save_path):
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--train_file_path', required=True,
|
||||
help='this is the path to the train.txt file that the preprocess.py script creates'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--save_to', help='path to save charts of data to'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--cmu_dict_path', help='give cmudict-0.7b to see phoneme distribution'
|
||||
"--train_file_path",
|
||||
required=True,
|
||||
help="this is the path to the train.txt file that the preprocess.py script creates",
|
||||
)
|
||||
parser.add_argument("--save_to", help="path to save charts of data to")
|
||||
parser.add_argument("--cmu_dict_path", help="give cmudict-0.7b to see phoneme distribution")
|
||||
args = parser.parse_args()
|
||||
meta_data = process_meta_data(args.train_file_path)
|
||||
plt.rcParams["figure.figsize"] = (10, 5)
|
||||
@@ -211,5 +205,6 @@ def main():
|
||||
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user