diff --git a/notebooks/dataset_analysis/PhonemeCoverage.ipynb b/notebooks/dataset_analysis/PhonemeCoverage.ipynb index ef93144e..af00deaf 100644 --- a/notebooks/dataset_analysis/PhonemeCoverage.ipynb +++ b/notebooks/dataset_analysis/PhonemeCoverage.ipynb @@ -36,7 +36,7 @@ "source": [ "# set some vars\n", "# TTS_PATH = \"/home/thorsten/___dev/tts/mozilla/TTS\"\n", - "CONFIG_FILE = \"/home/erogol/Projects//TTS/TTS/tts/configs/config.json\"\n", + "CONFIG_FILE = \"/path/to/config/config.json\"\n", "CHARS_TO_REMOVE = \".,:!?'\"" ] }, @@ -54,6 +54,7 @@ "from TTS.tts.utils.text import phoneme_to_sequence, sequence_to_phoneme\n", "from tqdm import tqdm\n", "from matplotlib import pylab as plt\n", + "from multiprocessing import Pool, cpu_count\n", "\n", "# extra imports that might not be included in requirements.txt\n", "import collections\n", @@ -65,7 +66,8 @@ "cell_type": "code", "execution_count": null, "metadata": { - "Collapsed": "false" + "Collapsed": "false", + "tags": [] }, "outputs": [], "source": [ @@ -73,7 +75,8 @@ "CONFIG = load_config(CONFIG_FILE)\n", "\n", "# Load some properties from config.json\n", - "CONFIG_METADATA = load_meta_data(CONFIG.datasets)[0]\n", + "CONFIG_METADATA = sorted(load_meta_data(CONFIG.datasets)[0])\n", + "CONFIG_METADATA = CONFIG_METADATA\n", "CONFIG_DATASET = CONFIG.datasets[0]\n", "CONFIG_PHONEME_LANGUAGE = CONFIG.phoneme_language\n", "CONFIG_TEXT_CLEANER = CONFIG.text_cleaner\n", @@ -88,7 +91,8 @@ "cell_type": "code", "execution_count": null, "metadata": { - "Collapsed": "false" + "Collapsed": "false", + "tags": [] }, "outputs": [], "source": [ @@ -103,31 +107,46 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "Collapsed": "false" - }, + "metadata": {}, "outputs": [], "source": [ - "# Get phonemes from metadata\n", - "phonemes = []\n", - "\n", - "for phrase in tqdm(CONFIG_METADATA):\n", - " if len(phrase[0]) > 0:\n", - " tmpPhrase = phrase[0].rstrip('\\n')\n", - " for removeChar in CHARS_TO_REMOVE:\n", - " tmpPhrase = tmpPhrase.replace(removeChar,\"\")\n", - " \n", - " seq = phoneme_to_sequence(tmpPhrase, [CONFIG_TEXT_CLEANER], CONFIG_PHONEME_LANGUAGE, CONFIG_ENABLE_EOS_BOS_CHARS)\n", + "def get_phoneme_from_sequence(text):\n", + " temp_list = []\n", + " if len(text[0]) > 0:\n", + " temp_text = text[0].rstrip('\\n')\n", + " for rm_bad_chars in CHARS_TO_REMOVE:\n", + " temp_text = temp_text.replace(rm_bad_chars,\"\")\n", + " seq = phoneme_to_sequence(temp_text, [CONFIG_TEXT_CLEANER], CONFIG_PHONEME_LANGUAGE, CONFIG_ENABLE_EOS_BOS_CHARS)\n", " text = sequence_to_phoneme(seq)\n", " text = text.replace(\" \",\"\")\n", - " phonemes.append(text)" + " temp_list.append(text)\n", + " return temp_list" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "Collapsed": "false" + "Collapsed": "false", + "tags": [] + }, + "outputs": [], + "source": [ + "# Get phonemes from metadata\n", + "phonemes = []\n", + "\n", + "with Pool(cpu_count()-1) as p:\n", + " \n", + " phonemes = list(tqdm(p.imap(get_phoneme_from_sequence, CONFIG_METADATA), total=len(CONFIG_METADATA)))\n", + " phonemes = [i for sub in phonemes for i in sub]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "Collapsed": "false", + "tags": [] }, "outputs": [], "source": [ @@ -152,7 +171,8 @@ "cell_type": "code", "execution_count": null, "metadata": { - "Collapsed": "false" + "Collapsed": "false", + "tags": [] }, "outputs": [], "source": [ @@ -223,9 +243,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.6.9-final" } }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file