2019-06-26 10:59:14 +00:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
2019-08-29 09:49:53 +00:00
|
|
|
from TTS.datasets.preprocess import get_preprocessor_by_name
|
2019-07-10 16:38:55 +00:00
|
|
|
|
2019-06-26 10:59:14 +00:00
|
|
|
|
|
|
|
def make_speakers_json_path(out_path):
|
|
|
|
"""Returns conventional speakers.json location."""
|
|
|
|
return os.path.join(out_path, "speakers.json")
|
|
|
|
|
|
|
|
|
|
|
|
def load_speaker_mapping(out_path):
|
|
|
|
"""Loads speaker mapping if already present."""
|
|
|
|
try:
|
|
|
|
with open(make_speakers_json_path(out_path)) as f:
|
|
|
|
return json.load(f)
|
|
|
|
except FileNotFoundError:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
def save_speaker_mapping(out_path, speaker_mapping):
|
|
|
|
"""Saves speaker mapping if not yet present."""
|
|
|
|
speakers_json_path = make_speakers_json_path(out_path)
|
|
|
|
with open(speakers_json_path, "w") as f:
|
|
|
|
json.dump(speaker_mapping, f, indent=4)
|
|
|
|
|
|
|
|
|
2019-10-04 16:20:30 +00:00
|
|
|
def get_speakers(items):
|
2019-07-10 16:38:55 +00:00
|
|
|
"""Returns a sorted, unique list of speakers in a given dataset."""
|
|
|
|
speakers = {e[2] for e in items}
|
|
|
|
return sorted(speakers)
|