mirror of
https://github.com/wassname/TTS.git
synced 2026-08-21 11:11:30 +08:00
* Update model file ext to ```.pth``` * Update docs * Rename more * Find model files
9.3 KiB
9.3 KiB
In [ ]:
import os
import glob
import numpy as np
import umap
from TTS.utils.audio import AudioProcessor
from TTS.config import load_config
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import HoverTool, ColumnDataSource, BoxZoomTool, ResetTool, OpenURL, TapTool
from bokeh.transform import factor_cmap
from bokeh.palettes import Category10In [ ]:
output_notebook()In [ ]:
MODEL_RUN_PATH = "/media/erogol/data_ssd/Models/libri_tts/speaker_encoder/libritts_360-half-October-31-2019_04+54PM-19d2f5f/"
MODEL_PATH = MODEL_RUN_PATH + "best_model.pth"
CONFIG_PATH = MODEL_RUN_PATH + "config.json"
# My single speaker locations
#EMBED_PATH = "/home/neil/main/Projects/TTS3/embeddings/neil14/"
#AUDIO_PATH = "/home/neil/data/Projects/NeilTTS/neil14/wavs/"
# My multi speaker locations
EMBED_PATH = "/home/erogol/Data/Libri-TTS/train-clean-360-embed_128/"
AUDIO_PATH = "/home/erogol/Data/Libri-TTS/train-clean-360/"In [ ]:
!ls -1 $MODEL_RUN_PATHIn [ ]:
CONFIG = load_config(CONFIG_PATH)
ap = AudioProcessor(**CONFIG['audio'])In [ ]:
embed_files = glob.glob(EMBED_PATH+"/**/*.npy", recursive=True)
print(f'Embeddings found: {len(embed_files)}')In [ ]:
embed_files[0]In [ ]:
speaker_paths = list(set([os.path.dirname(os.path.dirname(embed_file)) for embed_file in embed_files]))
speaker_to_utter = {}
for embed_file in embed_files:
speaker_path = os.path.dirname(os.path.dirname(embed_file))
try:
speaker_to_utter[speaker_path].append(embed_file)
except:
speaker_to_utter[speaker_path]=[embed_file]
print(f'Speaker count: {len(speaker_paths)}')In [ ]:
embeds = []
labels = []
locations = []
# single speaker
#num_speakers = 1
#num_utters = 1000
# multi speaker
num_speakers = 10
num_utters = 20
speaker_idxs = np.random.choice(range(len(speaker_paths)), num_speakers, replace=False )
for speaker_num, speaker_idx in enumerate(speaker_idxs):
speaker_path = speaker_paths[speaker_idx]
speakers_utter = speaker_to_utter[speaker_path]
utter_idxs = np.random.randint(0, len(speakers_utter) , num_utters)
for utter_idx in utter_idxs:
embed_path = speaker_to_utter[speaker_path][utter_idx]
embed = np.load(embed_path)
embeds.append(embed)
labels.append(str(speaker_num))
locations.append(embed_path.replace(EMBED_PATH, '').replace('.npy','.wav'))
embeds = np.concatenate(embeds)In [ ]:
model = umap.UMAP()
projection = model.fit_transform(embeds)In [ ]:
source_wav_stems = ColumnDataSource(
data=dict(
x = projection.T[0].tolist(),
y = projection.T[1].tolist(),
desc=locations,
label=labels
)
)
hover = HoverTool(
tooltips=[
("file", "@desc"),
("speaker", "@label"),
]
)
# optionally consider adding these to the tooltips if you want additional detail
# for the coordinates: ("(x,y)", "($x, $y)"),
# for the index of the embedding / wav file: ("index", "$index"),
factors = list(set(labels))
pal_size = max(len(factors), 3)
pal = Category10[pal_size]
p = figure(plot_width=600, plot_height=400, tools=[hover,BoxZoomTool(), ResetTool(), TapTool()])
p.circle('x', 'y', source=source_wav_stems, color=factor_cmap('label', palette=pal, factors=factors),)
url = "http://localhost:8000/@desc"
taptool = p.select(type=TapTool)
taptool.callback = OpenURL(url=url)
show(p)In [ ]:
%cd $AUDIO_PATH
%pwd
!python -m http.server