File size: 16,942 Bytes
f5ced3a |
1 |
{"cells":[{"cell_type":"markdown","metadata":{"id":"AvxXfBluyZvb"},"source":["## 1. κ΅¬κΈ λλΌμ΄λΈ λ§μ΄νΈ\n","\n","μμ±ν©μ±μ μν΄ νμ΅ν λͺ¨λΈμ΄ μλ κ΅¬κΈ λλΌμ΄λΈλ₯Ό λ§μ΄νΈν©λλ€. \n","λ§μ΄νΈν κ΅¬κΈ λλΌμ΄λΈ λ΄μ λ€μ νμΌλ€μ΄ μ‘΄μ¬νλμ§ κΌ νμΈν΄μ£ΌμΈμ.\n","\n","- `/Colab Notebooks/data/glowtts-v2/model_file.pth.tar`\n","- `/Colab Notebooks/data/glowtts-v2/config.json`\n","- `/Colab Notebooks/data/hifigan-v2/model_file.pth.tar`\n","- `/Colab Notebooks/data/hifigan-v2/config.json`\n","\n","\n","(μ‘΄μ¬νμ§ μλλ€λ©΄, [glowtts-v2.zip](https://drive.google.com/file/d/1DMKLdfZ_gzc_z0qDod6_G8fEXj0zCHvC/view?usp=sharing), [hifigan-v2.zip](https://drive.google.com/file/d/1vRxp1RH-U7gSzWgyxnKY4h_7pB3tjPmU/view?usp=sharing)μ λ΄λ €λ°μ μ€λΉν΄μ£ΌμΈμ.)\n","\n","λ§μ½ μλμ `Enter your authorization code:`κ³Ό κ°μ λ©μμ§κ° μΆλ ₯λ κ²½μ°, \n","κ°μ΄ μΆλ ₯λ λ§ν¬μ μ μνμ¬, λ§μ΄νΈν κ΅¬κΈ κ³μ μ μ ννμ ν, μΈμ¦ μ½λλ₯Ό 볡μ¬νμ¬ μ
λ ₯ν΄μ£ΌμΈμ."]},{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":230434,"status":"ok","timestamp":1707413202236,"user":{"displayName":"Cream Ice","userId":"02668969734157440879"},"user_tz":-540},"id":"4U2wrDOthrsF","outputId":"1a56442b-2686-468a-bb32-0ba7608ef988"},"outputs":[{"name":"stdout","output_type":"stream","text":["Mounted at /content/drive\n"]}],"source":["from google.colab import drive\n","drive.mount('/content/drive')"]},{"cell_type":"markdown","metadata":{"id":"8erClGSnzwge"},"source":["## 2. νμ λΌμ΄λΈλ¬λ¦¬ λ° ν¨μ λΆλ¬μ€κΈ°\n","\n","μ€νμ νμν λΌμ΄λΈλ¬λ¦¬ λ° ν¨μλ₯Ό λΆλ¬μ΅λλ€.\n","\n","μ΄ κ³Όμ μ μ½ 10λΆ μ λ μμλ μ μμ΅λλ€."]},{"cell_type":"code","execution_count":2,"metadata":{"executionInfo":{"elapsed":18,"status":"ok","timestamp":1707413202238,"user":{"displayName":"Cream Ice","userId":"02668969734157440879"},"user_tz":-540},"id":"jYCym6hXge2_"},"outputs":[],"source":["import os\n","import sys\n","from pathlib import Path"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"background_save":true,"base_uri":"https://localhost:8080/"},"id":"JkWG-L13gReB"},"outputs":[{"name":"stdout","output_type":"stream","text":["/content\n","fatal: destination path 'TTS' already exists and is not an empty directory.\n","fatal: destination path 'g2pK' already exists and is not an empty directory.\n","/content/TTS\n"," \u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n"," \n"," \u001b[31mΓ\u001b[0m \u001b[32mpip subprocess to install build dependencies\u001b[0m did not run successfully.\n"," \u001b[31mβ\u001b[0m exit code: \u001b[1;36m1\u001b[0m\n"," \u001b[31mβ°β\u003e\u001b[0m See above for output.\n"," \n"," \u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n"," Installing build dependencies ... \u001b[?25l\u001b[?25herror\n","\u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n","\n","\u001b[31mΓ\u001b[0m \u001b[32mpip subprocess to install build dependencies\u001b[0m did not run successfully.\n","\u001b[31mβ\u001b[0m exit code: \u001b[1;36m1\u001b[0m\n","\u001b[31mβ°β\u003e\u001b[0m See above for output.\n","\n","\u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n","/content/g2pK\n","\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m71.1/71.1 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n"]}],"source":["%cd /content\n","!git clone --depth 1 https://github.com/sce-tts/TTS.git -b sce-tts\n","!git clone --depth 1 https://github.com/sce-tts/g2pK.git\n","%cd /content/TTS\n","!pip install -q --no-cache-dir -e .\n","%cd /content/g2pK\n","!pip install -q --no-cache-dir \"pysbd\" \"konlpy\" \"jamo\" \"nltk\" \"python-mecab-ko\"\n","!pip install -q --no-cache-dir -e ."]},{"cell_type":"code","execution_count":4,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":2893,"status":"ok","timestamp":1707413252303,"user":{"displayName":"Cream Ice","userId":"02668969734157440879"},"user_tz":-540},"id":"FUD8SfIxSY8j","outputId":"3b984ef6-c788-4694-84b1-2675d82ed0c3"},"outputs":[{"name":"stdout","output_type":"stream","text":["/content/g2pK\n"]},{"name":"stderr","output_type":"stream","text":["[nltk_data] Downloading package cmudict to /root/nltk_data...\n","[nltk_data] Unzipping corpora/cmudict.zip.\n"]}],"source":["%cd /content/g2pK\n","import g2pk\n","g2p = g2pk.G2p()"]},{"cell_type":"code","execution_count":5,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":524},"executionInfo":{"elapsed":15,"status":"error","timestamp":1707413252303,"user":{"displayName":"Cream Ice","userId":"02668969734157440879"},"user_tz":-540},"id":"Lt9bLLZ8I4GH","outputId":"d0eba754-a986-47ee-d154-7233c2ef24c6"},"outputs":[{"name":"stdout","output_type":"stream","text":["/content/TTS\n"]},{"ename":"ModuleNotFoundError","evalue":"No module named 'pysbd'","output_type":"error","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)","\u001b[0;32m\u003cipython-input-5-73a1c4bbdabf\u003e\u001b[0m in \u001b[0;36m\u003ccell line: 7\u003e\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mIPython\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----\u003e 7\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mTTS\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msynthesizer\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mSynthesizer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mnormalize_text\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/content/TTS/TTS/utils/synthesizer.py\u001b[0m in \u001b[0;36m\u003cmodule\u003e\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----\u003e 5\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mpysbd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pysbd'","","\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n"]}],"source":["%cd /content/TTS\n","import re\n","import sys\n","from unicodedata import normalize\n","import IPython\n","\n","from TTS.utils.synthesizer import Synthesizer\n","\n","def normalize_text(text):\n"," text = text.strip()\n","\n"," for c in \",;:\":\n"," text = text.replace(c, \".\")\n"," text = remove_duplicated_punctuations(text)\n","\n"," text = jamo_text(text)\n","\n"," text = g2p.idioms(text)\n"," text = g2pk.english.convert_eng(text, g2p.cmu)\n"," text = g2pk.utils.annotate(text, g2p.mecab)\n"," text = g2pk.numerals.convert_num(text)\n"," text = re.sub(\"/[PJEB]\", \"\", text)\n","\n"," text = alphabet_text(text)\n","\n"," # remove unreadable characters\n"," text = normalize(\"NFD\", text)\n"," text = \"\".join(c for c in text if c in symbols)\n"," text = normalize(\"NFC\", text)\n","\n"," text = text.strip()\n"," if len(text) == 0:\n"," return \"\"\n","\n"," # only single punctuation\n"," if text in '.!?':\n"," return punctuation_text(text)\n","\n"," # append punctuation if there is no punctuation at the end of the text\n"," if text[-1] not in '.!?':\n"," text += '.'\n","\n"," return text\n","\n","\n","def remove_duplicated_punctuations(text):\n"," text = re.sub(r\"[.?!]+\\?\", \"?\", text)\n"," text = re.sub(r\"[.?!]+!\", \"!\", text)\n"," text = re.sub(r\"[.?!]+\\.\", \".\", text)\n"," return text\n","\n","\n","def split_text(text):\n"," text = remove_duplicated_punctuations(text)\n","\n"," texts = []\n"," for subtext in re.findall(r'[^.!?\\n]*[.!?\\n]', text):\n"," texts.append(subtext.strip())\n","\n"," return texts\n","\n","\n","def alphabet_text(text):\n"," text = re.sub(r\"(a|A)\", \"μμ΄\", text)\n"," text = re.sub(r\"(b|B)\", \"λΉ\", text)\n"," text = re.sub(r\"(c|C)\", \"μ¨\", text)\n"," text = re.sub(r\"(d|D)\", \"λ\", text)\n"," text = re.sub(r\"(e|E)\", \"μ΄\", text)\n"," text = re.sub(r\"(f|F)\", \"μν\", text)\n"," text = re.sub(r\"(g|G)\", \"μ₯\", text)\n"," text = re.sub(r\"(h|H)\", \"μμ΄μΉ\", text)\n"," text = re.sub(r\"(i|I)\", \"μμ΄\", text)\n"," text = re.sub(r\"(j|J)\", \"μ μ΄\", text)\n"," text = re.sub(r\"(k|K)\", \"μΌμ΄\", text)\n"," text = re.sub(r\"(l|L)\", \"μ\", text)\n"," text = re.sub(r\"(m|M)\", \"μ \", text)\n"," text = re.sub(r\"(n|N)\", \"μ\", text)\n"," text = re.sub(r\"(o|O)\", \"μ€\", text)\n"," text = re.sub(r\"(p|P)\", \"νΌ\", text)\n"," text = re.sub(r\"(q|Q)\", \"ν\", text)\n"," text = re.sub(r\"(r|R)\", \"μ\", text)\n"," text = re.sub(r\"(s|S)\", \"μμ€\", text)\n"," text = re.sub(r\"(t|T)\", \"ν°\", text)\n"," text = re.sub(r\"(u|U)\", \"μ \", text)\n"," text = re.sub(r\"(v|V)\", \"λΈμ΄\", text)\n"," text = re.sub(r\"(w|W)\", \"λλΈμ \", text)\n"," text = re.sub(r\"(x|X)\", \"μμ€\", text)\n"," text = re.sub(r\"(y|Y)\", \"μμ΄\", text)\n"," text = re.sub(r\"(z|Z)\", \"μ§\", text)\n","\n"," return text\n","\n","\n","def punctuation_text(text):\n"," # λ¬Έμ₯λΆνΈ\n"," text = re.sub(r\"!\", \"λλν\", text)\n"," text = re.sub(r\"\\?\", \"λ¬Όμν\", text)\n"," text = re.sub(r\"\\.\", \"λ§μΉ¨ν\", text)\n","\n"," return text\n","\n","\n","def jamo_text(text):\n"," # κΈ°λ³Έ μλͺ¨μ\n"," text = re.sub(r\"γ±\", \"κΈ°μ\", text)\n"," text = re.sub(r\"γ΄\", \"λμ\", text)\n"," text = re.sub(r\"γ·\", \"λκ·Ώ\", text)\n"," text = re.sub(r\"γΉ\", \"리μ\", text)\n"," text = re.sub(r\"γ
\", \"λ―Έμ\", text)\n"," text = re.sub(r\"γ
\", \"λΉμ\", text)\n"," text = re.sub(r\"γ
\", \"μμ·\", text)\n"," text = re.sub(r\"γ
\", \"μ΄μ\", text)\n"," text = re.sub(r\"γ
\", \"μ§μ\", text)\n"," text = re.sub(r\"γ
\", \"μΉμ\", text)\n"," text = re.sub(r\"γ
\", \"ν€μ\", text)\n"," text = re.sub(r\"γ
\", \"ν°μ\", text)\n"," text = re.sub(r\"γ
\", \"νΌμ\", text)\n"," text = re.sub(r\"γ
\", \"νμ\", text)\n"," text = re.sub(r\"γ²\", \"μκΈ°μ\", text)\n"," text = re.sub(r\"γΈ\", \"μλκ·Ώ\", text)\n"," text = re.sub(r\"γ
\", \"μλΉμ\", text)\n"," text = re.sub(r\"γ
\", \"μμμ·\", text)\n"," text = re.sub(r\"γ
\", \"μμ§μ\", text)\n"," text = re.sub(r\"γ³\", \"κΈ°μμμ·\", text)\n"," text = re.sub(r\"γ΅\", \"λμμ§μ\", text)\n"," text = re.sub(r\"γΆ\", \"λμνμ\", text)\n"," text = re.sub(r\"γΊ\", \"리μκΈ°μ\", text)\n"," text = re.sub(r\"γ»\", \"리μλ―Έμ\", text)\n"," text = re.sub(r\"γΌ\", \"리μλΉμ\", text)\n"," text = re.sub(r\"γ½\", \"리μμμ·\", text)\n"," text = re.sub(r\"γΎ\", \"리μν°μ\", text)\n"," text = re.sub(r\"γΏ\", \"리μνΌμ\", text)\n"," text = re.sub(r\"γ
\", \"리μνμ\", text)\n"," text = re.sub(r\"γ
\", \"λΉμμμ·\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μΌ\", text)\n"," text = re.sub(r\"γ
\", \"μ΄\", text)\n"," text = re.sub(r\"γ
\", \"μ¬\", text)\n"," text = re.sub(r\"γ
\", \"μ€\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μ°\", text)\n"," text = re.sub(r\"γ
\", \"μ \", text)\n"," text = re.sub(r\"γ
‘\", \"μΌ\", text)\n"," text = re.sub(r\"γ
£\", \"μ΄\", text)\n"," text = re.sub(r\"γ
\", \"μ \", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μΈ\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
\", \"μ¨\", text)\n"," text = re.sub(r\"γ
\", \"μ\", text)\n"," text = re.sub(r\"γ
’\", \"μ\", text)\n","\n"," return text\n","\n","\n","def normalize_multiline_text(long_text):\n"," texts = split_text(long_text)\n"," normalized_texts = [normalize_text(text).strip() for text in texts]\n"," return [text for text in normalized_texts if len(text) \u003e 0]\n","\n","def synthesize(text):\n"," wavs = synthesizer.tts(text, None, None)\n"," return wavs"]},{"cell_type":"markdown","metadata":{"id":"SbPRQfl8z28u"},"source":["## 3. νμ΅ν λͺ¨λΈ λΆλ¬μ€κΈ°\n","\n","νμ΅ν Glow-TTSμ HiFi-GAN λͺ¨λΈμ λΆλ¬μ΅λλ€.\n","\n","λ§μ½ λ€λ₯Έ 체ν¬ν¬μΈνΈμμ λΆλ¬μ€μλ €λ©΄ μλ μ½λμμ κ²½λ‘λ₯Ό μλμ κ°μ΄ μ μ νκ² μμ ν©λλ€.\n","\n","```python\n","synthesizer = Synthesizer(\n"," \"/content/drive/My Drive/Colab Notebooks/data/glowtts-v2/glowtts-v2-May-31-2021_08+17AM-d897f2e/best_model.pth.tar\",\n"," \"/content/drive/My Drive/Colab Notebooks/data/glowtts-v2/glowtts-v2-May-31-2021_08+17AM-d897f2e/config.json\",\n"," None,\n"," \"/content/drive/My Drive/Colab Notebooks/data/hifigan-v2/hifigan-v2-May-31-2021_08+26AM-d897f2e/checkpoint_300000.pth.tar\",\n"," \"/content/drive/My Drive/Colab Notebooks/data/hifigan-v2/hifigan-v2-May-31-2021_08+26AM-d897f2e/config.json\",\n"," None,\n"," None,\n"," False,\n",")\n","```"]},{"cell_type":"code","execution_count":null,"metadata":{"executionInfo":{"elapsed":10,"status":"aborted","timestamp":1707413252304,"user":{"displayName":"Cream Ice","userId":"02668969734157440879"},"user_tz":-540},"id":"zwROk8zUHgUn"},"outputs":[],"source":["synthesizer = Synthesizer(\n"," \"/content/drive/My Drive/Colab Notebooks/data/glowtts-v2/glowtts-v2-April-17-2022_04+46AM-3aa165a/best_model.pth.tar\",\n"," \"/content/drive/My Drive/Colab Notebooks/data/glowtts-v2/glowtts-v2-April-17-2022_04+46AM-3aa165a/config.json\",\n"," None,\n"," \"/content/drive/My Drive/Colab Notebooks/data/hifigan-v2/hifigan-v2-April-16-2022_11+57AM-3aa165a/best_model.pth.tar\",\n"," \"/content/drive/My Drive/Colab Notebooks/data/hifigan-v2/hifigan-v2-April-16-2022_11+57AM-3aa165a/config.json\",\n"," None,\n"," None,\n"," False,\n",")\n","symbols = synthesizer.tts_config.characters.characters"]},{"cell_type":"markdown","metadata":{"id":"tmjT_BrV0XYD"},"source":["## 4. μμ± ν©μ±\n","\n","μ€μ μμ± ν©μ±μ μνν©λλ€."]},{"cell_type":"code","execution_count":null,"metadata":{"executionInfo":{"elapsed":11,"status":"aborted","timestamp":1707413252305,"user":{"displayName":"Cream Ice","userId":"02668969734157440879"},"user_tz":-540},"id":"XSnF1D48F1tx"},"outputs":[],"source":["texts = \"\"\"\n","\n","\"\"\"\n","for text in normalize_multiline_text(texts):\n"," wav = synthesizer.tts(text, None, None)\n"," IPython.display.display(IPython.display.Audio(wav, rate=22050))"]}],"metadata":{"colab":{"collapsed_sections":["8erClGSnzwge"],"name":"","provenance":[{"file_id":"1YkxjzBz3V4eXoAaEgcFNEUg8ZyWV40x9","timestamp":1650109450650},{"file_id":"13pqat2mWsMha7Vn_-Q5_Ih8MDkvz3q5a","timestamp":1622375316346},{"file_id":"1IlZt42ETvNHthRFXfwNSSH-ftWthxzqr","timestamp":1596336131977},{"file_id":"1UinTd1Kp1ytwPQ4QWA610ZKOVfmPDdn5","timestamp":1596300568469}],"version":""},"kernelspec":{"display_name":"Python 3","name":"python3"}},"nbformat":4,"nbformat_minor":0} |