{ "cells": [ { "cell_type": "code", "execution_count": 5, "id": "5c91e739", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import IPython.display as ipd\n", "\n", "import os\n", "import json\n", "import math\n", "import torch\n", "from torch import nn\n", "from torch.nn import functional as F\n", "from torch.utils.data import DataLoader\n", "\n", "import commons\n", "import utils\n", "from data_utils import TextAudioLoader, TextAudioCollate, TextAudioSpeakerLoader, TextAudioSpeakerCollate\n", "from models import SynthesizerTrn\n", "from text.symbols import symbols\n", "from text import text_to_sequence\n", "\n", "from scipy.io.wavfile import write\n", "\n", "\n", "def get_text(text, hps):\n", " text_norm = text_to_sequence(text, hps.data.text_cleaners)\n", " if hps.data.add_blank:\n", " text_norm = commons.intersperse(text_norm, 0)\n", " text_norm = torch.LongTensor(text_norm)\n", " return text_norm" ] }, { "cell_type": "code", "execution_count": 6, "id": "60dfb1c8", "metadata": {}, "outputs": [], "source": [ "hps = utils.get_hparams_from_file(\"./configs/jp_base.json\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "d532ee7e", "metadata": {}, "outputs": [], "source": [ "net_g = SynthesizerTrn(\n", " len(symbols),\n", " hps.data.filter_length // 2 + 1,\n", " hps.train.segment_size // hps.data.hop_length,\n", " **hps.model)\n", "_ = net_g.eval()\n", "\n", "_ = utils.load_checkpoint(\"logs/jp_base/G_495000.pth\", net_g, None)" ] }, { "cell_type": "code", "execution_count": 3, "id": "627c6b45", "metadata": {}, "outputs": [], "source": [ "# stn_tst = get_text(\"また、サイコロに姿を変えることもでき、転がると強力な魔力が発動し、出た目の数だけ死者が出る\", hps)\n", "stn_tst = get_text(\"真冬でも気温10度を下ることの滅多にないこの島では、温暖な風土を活かした農業が盛んですが、中でもサトウキビと米の栽培はその中心です。\", hps)\n", "with torch.no_grad():\n", " x_tst = stn_tst.unsqueeze(0)\n", " x_tst_lengths = torch.LongTensor([stn_tst.size(0)])\n", " audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.float().numpy()\n", "ipd.display(ipd.Audio(audio, 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.8.10" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false } }, "nbformat": 4, "nbformat_minor": 5 }