mirror of
https://github.com/storytold/torchscript-models.git
synced 2026-10-19 07:42:59 +00:00
rename glow-tts-2 to glow-tts (removing git submodule)
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%matplotlib inline\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import IPython.display as ipd\n",
|
||||
"\n",
|
||||
"import sys\n",
|
||||
"sys.path.append('./waveglow/')\n",
|
||||
"\n",
|
||||
"import librosa\n",
|
||||
"import numpy as np\n",
|
||||
"import os\n",
|
||||
"import glob\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"import torch\n",
|
||||
"from text import text_to_sequence, cmudict\n",
|
||||
"from text.symbols import symbols\n",
|
||||
"import commons\n",
|
||||
"import attentions\n",
|
||||
"import modules\n",
|
||||
"import models\n",
|
||||
"import utils\n",
|
||||
"\n",
|
||||
"# load waveglow\n",
|
||||
"waveglow_path = './waveglow/waveglow_256channels_ljs_v3.pt'\n",
|
||||
"waveglow = torch.load(waveglow_path)['model']\n",
|
||||
"waveglow = waveglow.remove_weightnorm(waveglow)\n",
|
||||
"_ = waveglow.cuda().eval()\n",
|
||||
"from apex import amp\n",
|
||||
"waveglow, _ = amp.initialize(waveglow, [], opt_level=\"O3\") # Try if you want to boost up synthesis speed."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model_dir = \"./logs/base/\"\n",
|
||||
"hps = utils.get_hparams_from_dir(model_dir)\n",
|
||||
"model = models.FlowGenerator(\n",
|
||||
" len(symbols),\n",
|
||||
" out_channels=hps.data.n_mel_channels,\n",
|
||||
" **hps.model).to(\"cuda\")\n",
|
||||
"\n",
|
||||
"checkpoint_path = utils.latest_checkpoint_path(model_dir)\n",
|
||||
"utils.load_checkpoint(checkpoint_path, model)\n",
|
||||
"model.decoder.store_inverse() # do not calcuate jacobians for fast decoding\n",
|
||||
"_ = model.eval()\n",
|
||||
"\n",
|
||||
"cmu_dict = cmudict.CMUDict(hps.data.cmudict_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tst_stn = \" Glow TTS is really awesome ! \" # Adding spaces at the beginning and the end of utterance improves quality\n",
|
||||
"sequence = np.array(text_to_sequence(tst_stn, ['english_cleaners'], cmu_dict))[None, :]\n",
|
||||
"print(\"\".join([symbols[c] for c in sequence[0]]))\n",
|
||||
"x_tst = torch.autograd.Variable(torch.from_numpy(sequence)).cuda().long()\n",
|
||||
"x_tst_lengths = torch.tensor([x_tst.shape[1]]).cuda()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"with torch.no_grad():\n",
|
||||
" noise_scale = .667\n",
|
||||
" length_scale = 1.0\n",
|
||||
" (y_gen_tst, *r), attn_gen, *_ = model(x_tst, x_tst_lengths, gen=True, noise_scale=noise_scale, length_scale=length_scale)\n",
|
||||
" try:\n",
|
||||
" audio = waveglow.infer(y_gen_tst.half(), sigma=.666)\n",
|
||||
" except:\n",
|
||||
" audio = waveglow.infer(y_gen_tst, sigma=.666)\n",
|
||||
"ipd.Audio(audio[0].clamp(-1,1).data.cpu().float().numpy(), rate=hps.data.sampling_rate)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user