mirror of https://github.com/coqui-ai/TTS.git
10 KiB
10 KiB
None
<html lang="en">
<head>
</head>
</html>
In [ ]:
%load_ext autoreload %autoreload 2 import os import sys import io import torch import time import numpy as np from collections import OrderedDict from matplotlib import pylab as plt %pylab inline rcParams["figure.figsize"] = (16,5) sys.path.append('/home/erogol/projects/') import librosa import librosa.display from TTS.models.tacotron import Tacotron from TTS.layers import * from TTS.utils.data import * from TTS.utils.audio import AudioProcessor from TTS.utils.generic_utils import load_config from TTS.utils.text import text_to_sequence import IPython from IPython.display import Audio from utils import *
In [ ]:
def tts(model, text, CONFIG, use_cuda, ap, figures=True): t_1 = time.time() waveform, alignment, spectrogram, stop_tokens = create_speech(model, text, CONFIG, use_cuda, ap) print(" > Run-time: {}".format(time.time() - t_1)) if figures: visualize(alignment, spectrogram, stop_tokens, CONFIG) IPython.display.display(Audio(waveform, rate=CONFIG.sample_rate)) out_path = 'benchmark_samples/' os.makedirs(out_path, exist_ok=True) file_name = text.replace(" ", "_").replace(".","") + ".wav" out_path = os.path.join(out_path, file_name) ap.save_wav(waveform, out_path) return alignment, spectrogram, stop_tokens
In [ ]:
# Set constants ROOT_PATH = '/data/shared/erogol_models/May-22-2018_03:24PM-loc-sen-attn-e6112f7/' MODEL_PATH = ROOT_PATH + '/checkpoint_272976.pth.tar' CONFIG_PATH = ROOT_PATH + '/config.json' OUT_FOLDER = ROOT_PATH + '/test/' CONFIG = load_config(CONFIG_PATH) use_cuda = True
In [ ]:
# load the model model = Tacotron(CONFIG.embedding_size, CONFIG.num_freq, CONFIG.num_mels, CONFIG.r) # load the audio processor ap = AudioProcessor(CONFIG.sample_rate, CONFIG.num_mels, CONFIG.min_level_db, CONFIG.frame_shift_ms, CONFIG.frame_length_ms, CONFIG.preemphasis, CONFIG.ref_level_db, CONFIG.num_freq, CONFIG.power, griffin_lim_iters=30) # load model state if use_cuda: cp = torch.load(MODEL_PATH) else: cp = torch.load(MODEL_PATH, map_location=lambda storage, loc: storage) # load the model model.load_state_dict(cp['model']) if use_cuda: model.cuda() model.eval()
EXAMPLES FROM TRAINING SET¶
In [ ]:
import pandas as pd df = pd.read_csv('/data/shared/KeithIto/LJSpeech-1.0/metadata_val.csv', delimiter='|')
In [ ]:
sentence = df.iloc[175, 1] print(sentence) model.decoder.max_decoder_steps = 250 align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
Comparision with https://mycroft.ai/blog/available-voices/¶
In [ ]:
sentence = "It took me quite a long time to develop a voice, and now that I have it I'm not going to be silent." model.decoder.max_decoder_steps = 250 align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap, figures=True)
In [ ]:
sentence = "Be a voice,not an echo." # 'echo' is not in training set. align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "The human voice is the most perfect instrument of all." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "I'm sorry Dave. I'm afraid I can't do that." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "This cake is great. It's so delicious and moist." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
Comparison with https://keithito.github.io/audio-samples/¶
In [ ]:
sentence = "Generative adversarial network or variational auto-encoder." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "Scientists at the CERN laboratory say they have discovered a new particle." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "Here’s a way to measure the acute emotional intelligence that has never gone out of style." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "President Trump met with other leaders at the Group of 20 conference." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "The buses aren't the problem, they actually provide a solution." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "Generative adversarial network or variational auto-encoder." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "Basilar membrane and otolaryngology are not auto-correlations." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "He has read the whole thing." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "He reads books." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "Thisss isrealy awhsome." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "This is your internet browser, Firefox." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "This is your internet browser Firefox." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "The quick brown fox jumps over the lazy dog." align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
sentence = "Does the quick brown fox jump over the lazy dog?" align, spec, stop_tokens = tts(model, sentence, CONFIG, use_cuda, ap)
In [ ]:
!zip benchmark_samples/samples.zip benchmark_samples/*