{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f37f4e3b-f764-4502-a6a2-6417bd9bfab9",
   "metadata": {},
   "source": [
    "# Matcha-TTS: A fast TTS architecture with conditional flow matching\n",
    "---\n",
    "[Shivam Mehta](https://www.kth.se/profile/smehta), [Ruibo Tu](https://www.kth.se/profile/ruibo), [Jonas Beskow](https://www.kth.se/profile/beskow), [Éva Székely](https://www.kth.se/profile/szekely), and [Gustav Eje Henter](https://people.kth.se/~ghe/)\n",
    "\n",
    "We introduce Matcha-TTS, a new encoder-decoder architecture for speedy TTS acoustic modelling, trained using optimal-transport conditional flow matching (OT-CFM). This yields an ODE-based decoder capable of high output quality in fewer synthesis steps than models trained using score matching. Careful design choices additionally ensure each synthesis step is fast to run. The method is probabilistic, non-autoregressive, and learns to speak from scratch without external alignments. Compared to strong pre-trained baseline models, the Matcha-TTS system has the smallest memory footprint, rivals the speed of the fastest models on long utterances, and attains the highest mean opinion score in a listening test.\n",
    "\n",
    "Demo Page: https://shivammehta25.github.io/Matcha-TTS \\\n",
    "Code: https://github.com/shivammehta25/Matcha-TTS\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "148f4bc0-c28e-4670-9a5e-4c7928ab8992",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "env: CUDA_VISIBLE_DEVICES=0\n"
     ]
    }
   ],
   "source": [
    "%env CUDA_VISIBLE_DEVICES=0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8d5876c0-b47e-4c80-9e9c-62550f81b64e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime as dt\n",
    "from pathlib import Path\n",
    "\n",
    "import IPython.display as ipd\n",
    "import numpy as np\n",
    "import soundfile as sf\n",
    "import torch\n",
    "import random\n",
    "from tqdm.auto import tqdm\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from lightning import seed_everything\n",
    "\n",
    "# Hifigan imports\n",
    "from matcha.hifigan.config import v1\n",
    "from matcha.hifigan.denoiser import Denoiser\n",
    "from matcha.hifigan.env import AttrDict\n",
    "from matcha.hifigan.models import Generator as HiFiGAN\n",
    "# Matcha imports\n",
    "from matcha.models.matcha_tts import MatchaTTS\n",
    "from matcha.text import sequence_to_text, text_to_sequence\n",
    "from matcha.utils.model import denormalize\n",
    "from matcha.utils.utils import get_user_data_dir, intersperse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b1a30306-588c-4f22-8d9b-e2676880b0e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "# This allows for real time code changes being reflected in the notebook, no need to restart the kernel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a312856b-01a9-4d75-a4c8-4666dffa0692",
   "metadata": {},
   "outputs": [],
   "source": [
    "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88f3b3c3-d014-443b-84eb-e143cdec3e21",
   "metadata": {},
   "source": [
    "## Filepaths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7640a4c1-44ce-447c-a8ff-45012fb7bddd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# MATCHA_CHECKPOINT = \"logs/train/tsg2_stoc_dur/runs/2024-01-05_12-35-07/checkpoints/last.ckpt\"\n",
    "# MATCHA_CHECKPOINT = \"logs/train/lj_stoc/runs/2024-01-12_12-03-19/checkpoints/checkpoint_epoch=3299.ckpt\"\n",
    "MATCHA_CHECKPOINT = \"logs/train/joe_stoc_dur/runs/2024-02-20_14-01-53/checkpoints/last.ckpt\"\n",
    "HIFIGAN_CHECKPOINT = get_user_data_dir() / \"hifigan_univ_v1\"\n",
    "OUTPUT_FOLDER = \"cormac_fm_output2\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6477a3a9-71f2-4d2f-bb86-bdf3e31c2461",
   "metadata": {},
   "source": [
    "## Load Matcha-TTS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "26a16230-04ba-4825-a844-2fb5ab945e24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model loaded! Parameter count: 18,336,545\n"
     ]
    }
   ],
   "source": [
    "def load_model(checkpoint_path):\n",
    "    model = MatchaTTS.load_from_checkpoint(checkpoint_path, map_location=device)\n",
    "    model.eval()\n",
    "    return model\n",
    "count_params = lambda x: f\"{sum(p.numel() for p in x.parameters()):,}\"\n",
    "\n",
    "\n",
    "model = load_model(MATCHA_CHECKPOINT)\n",
    "print(f\"Model loaded! Parameter count: {count_params(model)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3077b84b-e3b6-42e1-a84b-2f7084b13f92",
   "metadata": {},
   "source": [
    "## Load HiFi-GAN (Vocoder)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f6b68184-968d-4868-9029-f0c40e9e68af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Removing weight norm...\n"
     ]
    }
   ],
   "source": [
    "def load_vocoder(checkpoint_path):\n",
    "    h = AttrDict(v1)\n",
    "    hifigan = HiFiGAN(h).to(device)\n",
    "    hifigan.load_state_dict(torch.load(checkpoint_path, map_location=device)['generator'])\n",
    "    _ = hifigan.eval()\n",
    "    hifigan.remove_weight_norm()\n",
    "    return hifigan\n",
    "\n",
    "vocoder = load_vocoder(HIFIGAN_CHECKPOINT)\n",
    "denoiser = Denoiser(vocoder, mode='zeros')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cbc2ba0-09ff-40e2-9e60-6b77b534f9fb",
   "metadata": {},
   "source": [
    "### Helper functions to synthesise"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "880a1879-24fd-4757-849c-850339120796",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "@torch.inference_mode()\n",
    "def process_text(text: str):\n",
    "    x = torch.tensor(intersperse(text_to_sequence(text, ['english_cleaners2']), 0),dtype=torch.long, device=device)[None]\n",
    "    x_lengths = torch.tensor([x.shape[-1]],dtype=torch.long, device=device)\n",
    "    x_phones = sequence_to_text(x.squeeze(0).tolist())\n",
    "    return {\n",
    "        'x_orig': text,\n",
    "        'x': x,\n",
    "        'x_lengths': x_lengths,\n",
    "        'x_phones': x_phones\n",
    "    }\n",
    "\n",
    "\n",
    "@torch.inference_mode()\n",
    "def synthesise(text, spks=None):\n",
    "    text_processed = process_text(text)\n",
    "    start_t = dt.datetime.now()\n",
    "    output = model.synthesise(\n",
    "        text_processed['x'], \n",
    "        text_processed['x_lengths'],\n",
    "        n_timesteps=n_timesteps,\n",
    "        temperature=temperature,\n",
    "        spks=spks,\n",
    "        length_scale=length_scale\n",
    "    )\n",
    "    # merge everything to one dict    \n",
    "    output.update({'start_t': start_t, **text_processed})\n",
    "    return output\n",
    "\n",
    "@torch.inference_mode()\n",
    "def to_waveform(mel, vocoder):\n",
    "    audio = vocoder(mel).clamp(-1, 1)\n",
    "    audio = denoiser(audio.squeeze(0), strength=0.00025).cpu().squeeze()\n",
    "    return audio.cpu().squeeze()\n",
    "    \n",
    "def save_to_folder(filename: str, output: dict, folder: str):\n",
    "    folder = Path(folder)\n",
    "    folder.mkdir(exist_ok=True, parents=True)\n",
    "    np.save(folder / f'{filename}', output['mel'].cpu().numpy())\n",
    "    sf.write(folder / f'{filename}.wav', output['waveform'], 22050, 'PCM_24')\n",
    "    if \"duration_json\" in output:\n",
    "        with open(folder / f'{filename}.json', 'w', encoding='utf-8') as f:\n",
    "            json.dump(output['duration_json'], f, indent=4, ensure_ascii=False)\n",
    "\n",
    "def plot_spectrogram(spectrogram):\n",
    "    fig, ax = plt.subplots(figsize=(12, 3))\n",
    "    im = ax.imshow(spectrogram.squeeze().cpu().numpy(), aspect=\"auto\", origin=\"lower\", interpolation=\"none\")\n",
    "    plt.colorbar(im, ax=ax)\n",
    "    plt.xlabel(\"Frames\")\n",
    "    plt.ylabel(\"Channels\")\n",
    "    plt.title(\"Synthesised Mel-Spectrogram\")\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78f857e3-2ef7-4c86-b776-596c4d3cf875",
   "metadata": {},
   "source": [
    "## Setup text to synthesise"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "2e0a9acd-0845-4192-ba09-b9683e28a3ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "texts = [\n",
    "    \"; What I used to do this is crazy I was destroying my skin, ; in the mornings because I used to hate sweating, because that would make my skin oily; and that will block my pores and that will give me more spots.\",\n",
    "    \"; What I used to do this is crazy I was destroying my skin, ; in the mornings because I used to hate sweating, because that would make my skin oily; and that will block my pores and that will give me more spots.\",\n",
    "    \"; What I used to do this is crazy I was destroying my skin, ; in the mornings because I used to hate sweating, because that would make my skin oily; and that will block my pores and that will give me more spots.\",\n",
    "    \"; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\",\n",
    "    \"; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\",\n",
    "    \"; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\",\n",
    "    \"; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\",\n",
    "    \"that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\",\n",
    "    \"that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\",\n",
    "    \"that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\",\n",
    "    \"that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\",\n",
    "    \n",
    "    # \"Optionally, the ONNIX exporter accepts vocoder-name and vocoder-checkpoint arguments, This enables you to embed the vocoder in the exported graph and generate waveforms in a single run, (similar to end-to-end TTS systems).\",\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f58e82fa-0ae0-43f2-a021-97efc6041793",
   "metadata": {},
   "outputs": [],
   "source": [
    "texts = [\n",
    "    \"If, you know, it works as well as we would expect, it would change our, like, understanding of the world.\",\n",
    "    \"If, you know, it works as well as we would expect, it would change our, like, understanding of the world.\",\n",
    "    \"; If, you know, it works as well as we would expect, it would change our, like, understanding of the world.\",\n",
    "    \"; If, you know, it works as well as we would expect, it would change our, like, understanding of the world.\",\n",
    "    \"We've, uh, been working on this project where, you know, I think is interesting, just, you know, really cool.\",\n",
    "    \"We've, uh, been working on this project where, you know, I think is interesting, just, you know, really cool.\",\n",
    "    \"; We've, uh, been working on this project where, you know, I think is interesting, just, you know, really cool.\",\n",
    "    \"; We've, uh, been working on this project where, you know, I think is interesting, just, you know, really cool.\",\n",
    "    \"I heard about this thing called, uhm, big wave surfing, where these guys tackle waves of over 20 metres, just insane.\",\n",
    "    \"I heard about this thing called, uhm, big wave surfing, where these guys tackle waves of over 20 metres, just insane.\",\n",
    "    \"; I heard about this thing called, uhm, big wave surfing, where these guys tackle waves of over 20 metres, just insane.\",\n",
    "    \"; I heard about this thing called, uhm, big wave surfing, where these guys tackle waves of over 20 metres, just insane.\",\n",
    "    \"I need to go to this, uhm, mandatory work seminar that I really don't want to attend.\",\n",
    "    \"I need to go to this, uhm, mandatory work seminar that I really don't want to attend.\",\n",
    "    \"; I need to go to this, uhm, mandatory work seminar that I really don't want to attend.\",\n",
    "    \"; I need to go to this, uhm, mandatory work seminar that I really don't want to attend.\",\n",
    "    \n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "38aff9af-420f-4ab8-a9b1-7d12fc5bcb57",
   "metadata": {},
   "outputs": [],
   "source": [
    "texts = [\n",
    "    \"So, yesterday I went to the zoo, and, you know, it was such an incredible experience ; I mean, like, absolutely breathtaking!\",\n",
    "    \"I wasn't quite sure what to expect, but, you know, it turned out to be really, really fun ; like, surprisingly enjoyable.\",\n",
    "    \"Oh, I saw so many amazing animals ; lions, tigers, elephants, you name it ; it was like a wildlife paradise!\",\n",
    "    \"At first, I thought it might be crowded, but, fortunately, it wasn't too bad ; I guess I got lucky.\",\n",
    "    \"You know, I'm not usually a fan of large crowds, but somehow, I managed to enjoy myself ; it was quite the adventure.\",\n",
    "    \"So, when I got there, the first thing I did was head straight to the monkey exhibit ; those little guys are just so fascinating, you know?\",\n",
    "    \"Ah, I'm absolutely fascinated by monkeys ; they're so lively and entertaining to watch ; I could spend hours just observing them.\",\n",
    "    \"I spent quite a bit of time there, just admiring their playful antics and interactions with each other.\",\n",
    "    \"But eventually, I decided to tear myself away and, like, explore the rest of the zoo ; there was just so much more to see!\",\n",
    "    \"Oh, I stumbled upon the giraffe enclosure next ; those majestic creatures are truly a sight to behold, don't you think?\",\n",
    "    \"I took a ton of pictures of them, but, none of them really did justice to their beauty ; they're just so graceful and magnificent.\",\n",
    "    \"You know, I'm not exactly the best photographer, but I tried my best to capture their elegance and grandeur.\",\n",
    "    \"So, after spending some time with the giraffes, I decided to take a little break and, like, grab a snack.\",\n",
    "    \"Ah, I'm a bit of a sucker for zoo food ; it may not be the healthiest, but, it's definitely delicious ; I just couldn't resist.\",\n",
    "    \"I indulged in some popcorn and, a soda, and just, you know, sat down for a while, soaking in the vibrant atmosphere around me.\",\n",
    "    \"But soon enough, I felt re-energized and ready to, like, embark on the next leg of my zoo adventure ; there was still so much to explore!\",\n",
    "    \"Oh, I stumbled upon the reptile house next ; now that, that was an experience, let me tell you!\",\n",
    "    \"I have to admit, I'm not exactly fond of snakes, but, I braved my fears and ventured in anyway ; it was quite the adrenaline rush.\",\n",
    "    \"You know, I'm not entirely sure why I did that to myself, but, it definitely made for an interesting experience, to say the least.\",\n",
    "    \"So, I cautiously made my way through the exhibit, trying not to, like, jump at every sudden movement or slithering motion ; it was quite the challenge.\",\n",
    "    \"Ah, I'm proud of myself for confronting my fears head-on, but, you know, I don't think I'll be rushing back to the reptile house anytime soon ; once was probably enough for me.\",\n",
    "    \"After that rather nerve-wracking experience, I felt the need for something a little more uplifting, so I, like, headed straight for the penguin exhibit.\",\n",
    "    \"I absolutely adore penguins ; they're just so adorable and, comical, especially when they waddle around on land ; it's simply delightful to watch.\",\n",
    "    \"I spent a good amount of time there, just enjoying their playful antics and quirky personalities ; they never fail to bring a smile to my face.\",\n",
    "    \"But eventually, I tore myself away and, like, continued on with my zoo adventure ; there were still so many more exhibits to explore!\",\n",
    "    \"Oh, I stumbled upon the big cat area next ; now that, that was an exhilarating experience, let me tell you!\",\n",
    "    \"I have to admit, I was both excited and a little nervous to see the lions and tigers up close ; they're such majestic and powerful creatures.\",\n",
    "    \"I kept a safe distance, of course, but, just being in their presence filled me with a sense of awe and wonder.\",\n",
    "    \"But, as the day started to draw to a close, I realized that my time at the zoo was coming to an end ; it was bittersweet, to say the least.\",\n",
    "    \"Oh, I hadn't realized how quickly the hours had flown by ; I guess I was just having too much fun!\",\n",
    "    \"So, I reluctantly made my way towards the exit, but not before promising myself that I'd, like, come back again soon ; there was still so much more to see and explore!\",\n",
    "    \"I felt a profound sense of gratitude for the incredible experience I'd had at the zoo ; it was truly unforgettable, and I couldn't wait to, like, do it all over again!\",\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "3d503650-3347-41ce-9d1b-177183a28db8",
   "metadata": {},
   "outputs": [],
   "source": [
    "texts = [\" I will have to, uh, make sure to charge my camera battery ; I don't want it dying on me while we're out.\",\n",
    " \" I heard there's a, a sort of farmers' market on the weekends ; so we might, uh, we might swing by that, uh, just to see, you know?\",\n",
    " \" I'm not really, uh, sure what to expect from this shopping center ; but I've heard good things from friends who've been there already.\",\n",
    " ' I will have to, uh, remind my sister to, uh, wear comfortable shoes ; last time she insisted on heels and regretted it halfway through the day.',\n",
    " \" I've been saving up for a, uh, new phone case, so I will, uh, definitely check out the, uh, tech accessory store.\",\n",
    " \" my family, we like to, uh, make a day of it ; you know, shopping together, eating together, it's, uh, it's nice.\",\n",
    " \"; , And I've got to, uh, look for some new headphones ; mine just broke and, uh, I can't go to the gym without them, you know?\",\n",
    " \"; , My dad, he wants to check out the, uh, the hardware store ; he's always looking for tools and, uh, stuff like that.\",\n",
    " 'But, as the day started to draw to a close, I realized that my time at the zoo was coming to an end ; it was bittersweet, to say the least.',\n",
    " 'So, after spending some time with the giraffes, I decided to take a little break and, like, grab a snack.',\n",
    " 'But eventually, I tore myself away and, like, continued on with my zoo adventure ; there were still so many more exhibits to explore!',\n",
    " \"Oh, I hadn't realized how quickly the hours had flown by ; I guess I was just having too much fun!\",\n",
    " \"Ah, I'm a bit of a sucker for zoo food ; it may not be the healthiest, but, it's definitely delicious ; I just couldn't resist.\",\n",
    " \" I will probably, uh, get distracted by all the, uh, sales and promotions ; I'm a sucker for a good deal.\",\n",
    " \"; , Uhm, my cousin, the one who's, uh, into photography ; he's, uh, he's going to look for a new, uh, camera lens at the, the camera store.\",\n",
    " \"; And, uh, there's this, uh, arcade area that I'm kinda, uh, interested in ; I used to love playing those games when I was younger.\",\n",
    " \"You know, I'm not usually a fan of large crowds, but somehow, I managed to enjoy myself ; it was quite the adventure.\",\n",
    " \"; , And, uh, my mom's been talking about this, uh, new recipe book she wants to get ; so she's on the lookout for it.\",\n",
    " \"Ah, I'm proud of myself for confronting my fears head-on, but, you know, I don't think I'll be rushing back to the reptile house anytime soon ; once was probably enough for me.\",\n",
    " \"; I think my dad's, uh, really excited about the, uh, electronics section ; he's been talking about upgrading his gadgets for a while now.\",\n",
    " \" there's this, uh, chocolate shop that gives out free samples ; and, uh, you know, who can say no to, uh, free chocolate?\",\n",
    " \"; , Uhm, they've got an indoor, uh, mini-golf place ; which could be a, uh, fun way to take a break from all the shopping.\",\n",
    " '; , So the plan is to, uhm, meet up at, like, the central plaza ; after everyone is done with their, uh, their own shopping and stuff.',\n",
    " \"; , And, uh, my aunt, she's big on, uhm, organic stuff ; so she's excited about the, the natural skincare shop that's, uh, that's there.\",\n",
    " 'But eventually, I decided to tear myself away and, like, explore the rest of the zoo ; there was just so much more to see!',\n",
    " \" I will probably, uh, end up carrying most of the shopping bags ; it's just easier for me since I'm used to it.\",\n",
    " \"; , And, uh, my mom's been talking about this, uh, new fitness craze she wants to try ; so she's looking for workout gear.\",\n",
    " ' I will have to, uh, make sure to bring my reusable shopping bags ; you know, to reduce waste and all that.',\n",
    " \"; , Uhm, my family, we're not, you know, super outdoorsy ; but there's an outdoor goods store, so maybe we'll, uh, we'll take a look, just in case, you know?\",\n",
    " 'Oh, I saw so many amazing animals ; lions, tigers, elephants, you name it ; it was like a wildlife paradise!',\n",
    " ' I will need to, uh, make a list of things I want to buy beforehand ; otherwise, I will end up forgetting.',\n",
    " \"; They have this, uh, loyalty program thing ; so I'm gonna sign up, you know, to get, uh, points or whatever, which is, uhm, pretty neat.\",\n",
    " \"; My dad, he's, uh, not that into shopping, right? ; But there's an electronics store, so he'll, he'll probably just, uh, hang out there while we, um, do our thing.\",\n",
    " \" I will probably, uh, take a lot of photos while we're there ; you know, just to capture the memories of our family outing.\",\n",
    " \"; So, we were thinking of going to, uh, that new shopping center, you know, the one that just opened up last month ; and I'm actually, I'm kind of excited about it.\",\n",
    " 'I spent quite a bit of time there, just admiring their playful antics and interactions with each other.',\n",
    " '; , And, uh, I might, uh, grab a snack from one of those, uh, food kiosks ; you know, just to keep my energy up while we shop.',\n",
    " \" I'm kind of excited to try the, the virtual reality experience ; I've never done that before, and, uh, it looks, uh, looks really cool.\",\n",
    " \"; My brother's, uh, he's looking forward to the, the gaming lounge ; they have, like, tournaments and stuff, which is, uhm, pretty cool, I think.\",\n",
    " \"; The kids, they have this, uhm, face painting thing ; so my niece, she's gonna love that, she's, uh, always asking for it.\",\n",
    " \" parking is, uh, it's free for the first two hours, which is, uh, nice ; but I'm sure we'll, we'll be there longer than that, so, uh, we'll see how it goes.\",\n",
    " \" I'm curious about the, the bookstore's cafe ; I've heard they make a, a mean latte, and, uh, you know, I love my coffee.\",\n",
    " 'I spent a good amount of time there, just enjoying their playful antics and quirky personalities ; they never fail to bring a smile to my face.',\n",
    " \"; , I'm not much for clothes shopping, but, uh, I do need some new jeans ; so, uh, I will be on the lookout for a good, uh, denim place.\",\n",
    " \"; , And, uh, my sister's been talking about this, uh, new fashion trend she wants to try ; so she's looking for specific clothing items.\",\n",
    " \"; I think my brother's, uh, planning to splurge on some, uh, collector's items ; there's a store that sells rare memorabilia that he's into.\",\n",
    " 'I indulged in some popcorn and, a soda, and just, you know, sat down for a while, soaking in the vibrant atmosphere around me.',\n",
    " \"; Well, I heard, uh, there's supposed to be some sort of event happening ; a, a raffle, or, uh, giveaway? I'm not totally sure but it, it sounds, uh, sounds fun.\",\n",
    " \"; , And, uh, my dad's been talking about this, uh, new barbecue grill he wants to get ; so I'm sure we'll end up at the home improvement store.\",\n",
    " \"; , And, uh, my mom mentioned something about a sale at, uh, her favorite clothing store ; so I bet we'll, we'll end up there for, like, I don't know, an hour, or something.\",\n",
    " \"; , Oh, and, uh, my sister's been talking about redecorating her room ; so she's looking for new bedding and decor.\",\n",
    " \" there's a, a pet store that, uh, lets you, you know, play with the puppies ; and, uh, my little brother, he's, he's definitely looking forward to that.\",\n",
    " \"; , Oh, and, uh, my sister's been talking about this, uh, new restaurant she wants to try ; so we might end up eating there.\",\n",
    " \"; , Oh, and, uh, my cousin, she's been talking about this, uh, new diet she's trying out ; so she's interested in checking out the health food store.\",\n",
    " \"; I'm hoping to, uh, find a nice gift for my mom's birthday ; there's a, uh, specialty shop that sells handmade items, so that might be perfect.\",\n",
    " \"; , And, uh, my little sister, she's all about, uh, the trendy fashion ; so we'll probably, you know, end up browsing those stores longer than expected.\",\n",
    " \"I felt a profound sense of gratitude for the incredible experience I'd had at the zoo ; it was truly unforgettable, and I couldn't wait to, like, do it all over again!\",\n",
    " \"Oh, I stumbled upon the giraffe enclosure next ; those majestic creatures are truly a sight to behold, don't you think?\",\n",
    " 'So, I cautiously made my way through the exhibit, trying not to, like, jump at every sudden movement or slithering motion ; it was quite the challenge.',\n",
    " \"; , And, uh, the shopping center, it's got, like, this, uh, huge LED screen ; they show sports and, uh, movies on it, which is, uhm, pretty cool.\",\n",
    " \"; , And, uh, my dad's been talking about this, uh, new recipe he wants to try out for dinner ; so he's looking for ingredients.\",\n",
    " \"; , And, uh, my aunt's been raving about this, uh, new skincare brand ; so she's eager to see if the store carries it.\",\n",
    " \"I took a ton of pictures of them, but, none of them really did justice to their beauty ; they're just so graceful and magnificent.\",\n",
    " 'After that rather nerve-wracking experience, I felt the need for something a little more uplifting, so I, like, headed straight for the penguin exhibit.',\n",
    " \"; , My grandma, she's always, uh, asking for new kitchen gadgets ; so we'll probably swing by the, uh, culinary store for her.\",\n",
    " \"; Uh, my sister, yeah, she's already, like, made a list of all the stores she wants to hit ; and she's, um, she's determined to find those, those boots she saw online, you know?\",\n",
    " \" I'm just hoping I can, you know, find some good deals ; maybe on, uh, clothes or, uhm, shoes? I, I could use some new sneakers, honestly.\",\n",
    " \"; , Uhm, I need to, uh, remember to, uh, pick up a gift for my friend's, uh, birthday ; so I will be, you know, on the lookout for something special.\",\n",
    " \" I'm kinda hoping we can find a good, uh, spot to sit and relax ; you know, when, uh, when our feet start hurting from all the walking around.\",\n",
    " '; I will have to, uh, remember to charge my phone before we go ; last time it died on me while we were shopping, which was, uh, inconvenient.',\n",
    " \"; , Oh, and, uh, I heard there's a, a rooftop garden with a nice view ; so we might take a break up there and enjoy the scenery.\",\n",
    " \"; , Oh, and, uh, my dad's been wanting to upgrade our, uh, home entertainment system ; so he's looking for a new TV.\",\n",
    " \"; And, uh, there's supposed to be this, this art exhibit ; in the, uhm, the central atrium, so that'll be, uh, that'll be something to see.\",\n",
    " \" I will probably, you know, look for some new books ; because they've got that, that big bookstore, and, uh, I could spend, like, hours in there, honestly.\",\n",
    " \"; , Oh, and, uh, my sister wants to try out this, uh, new makeup trend she saw online ; so she's looking for specific products.\",\n",
    " \"I have to admit, I was both excited and a little nervous to see the lions and tigers up close ; they're such majestic and powerful creatures.\",\n",
    " \"Ah, I'm absolutely fascinated by monkeys ; they're so lively and entertaining to watch ; I could spend hours just observing them.\",\n",
    " \"; , And, uh, I've heard there's a, a live music performance happening later in the evening ; so we might stick around for that if we're not too tired.\",\n",
    " \"; , Uh, last time we went shopping as a family, it was, uhm, quite the, the adventure ; so, uh, I'm expecting, you know, more of the same today.\",\n",
    " \" I will probably, uh, forget where we parked the car ; I'm terrible with remembering those things.\",\n",
    " \"At first, I thought it might be crowded, but, fortunately, it wasn't too bad ; I guess I got lucky.\",\n",
    " \" I'm thinking of, uh, treating myself to a, a massage at the, uh, spa center ; they have some pretty good deals going on right now.\",\n",
    " \"; , So, uh, yeah, after shopping we're, um, planning to grab dinner ; maybe try out that new, that new Italian place? I've heard, uhm, good things about it.\",\n",
    " 'So, yesterday I went to the zoo, and, you know, it was such an incredible experience ; I mean, like, absolutely breathtaking!',\n",
    " 'So, when I got there, the first thing I did was head straight to the monkey exhibit ; those little guys are just so fascinating, you know?',\n",
    " \"You know, I'm not exactly the best photographer, but I tried my best to capture their elegance and grandeur.\",\n",
    " \" I will need to, uh, check the store directory when we get there ; I'm not familiar with the layout of the shopping center.\",\n",
    " \"; We're, uh, probably going to start with the, the food court because, uhm, my brother, he gets, uh, he gets real cranky if he doesn't eat ; and there's supposed to be a, a new sushi place.\",\n",
    " \"; My family, they tend to, uh, split up and, uh, meet back at a certain time ; so we're, uh, probably gonna do that, you know?\",\n",
    " \"; And, uh, there's a, a bookstore signing event ; some author my brother likes, so, uh, we'll probably, you know, check that out.\",\n",
    " \"; , Uhm, the weather's supposed to be good, so we'll, uh, probably take a break outside ; they've got benches and, uh, fountains and stuff.\",\n",
    " \"I wasn't quite sure what to expect, but, you know, it turned out to be really, really fun ; like, surprisingly enjoyable.\",\n",
    " \" I'm not sure if I mentioned this, but, uh, my aunt, she's got this, uh, thing about, uh, finding unique home decor pieces ; so we might, you know, spend a bit of time there.\",\n",
    " ' the plan is to, uh, get there early, because, you know, parking can be crazy, and, uh, my dad, he, uh, he hates looking for parking spots for too long.',\n",
    " \" I've been meaning to, uh, buy some new workout gear ; so I will definitely be browsing the, uh, sports apparel stores.\",\n",
    " \" I think my brother's, uh, interested in checking out the, uh, car accessories store ; he's been talking about upgrading his car stereo.\",\n",
    " 'Oh, I stumbled upon the reptile house next ; now that, that was an experience, let me tell you!',\n",
    " \"; Oh, and, uh, my mom, she wants to check out the new, what's it, the home goods store ; because she's, uh, redecorating the living room, or something like that.\",\n",
    " \" my mom's been talking about this, this scarf she saw online ; and, uh, if we find the store, she's, uh, she's definitely buying it.\",\n",
    " \"You know, I'm not entirely sure why I did that to myself, but, it definitely made for an interesting experience, to say the least.\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9da9e2d-99b9-4c6f-8a08-c828e2cba121",
   "metadata": {},
   "source": [
    "### Hyperparameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "f0d216e5-4895-4da8-9d24-9e61021d2556",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Number of ODE Solver steps\n",
    "n_timesteps = 10\n",
    "\n",
    "## Changes to the speaking rate\n",
    "length_scale=1.0\n",
    "\n",
    "## Sampling temperature\n",
    "temperature = 0.667"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "443d515d-4a1d-4943-845e-9d60c9bb012a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from math import ceil\n",
    "\n",
    "\n",
    "def save_phoneme_durations(output):\n",
    "    durations = output['attn'].squeeze().sum(1)\n",
    "    phones = output['x_phones'][1::2]\n",
    "    prev = durations[0]\n",
    "    merged_durations = []\n",
    "    # Convolve with stride 2\n",
    "    for i in range(1, len(durations), 2):\n",
    "        if i == len(durations) - 2:\n",
    "            # if it is last take full value\n",
    "            next_half = durations[i+1]\n",
    "        else:\n",
    "            next_half = ceil(durations[i+1] /2)\n",
    "\n",
    "        curr = prev + durations[i] + next_half\n",
    "        prev = durations[i+1] - next_half\n",
    "        # print(durations[i-1:i+2], curr, next_half, prev)\n",
    "        merged_durations.append(curr)\n",
    "\n",
    "    assert len(phones) == len(merged_durations)\n",
    "    assert len(merged_durations) == (len(durations) - 1) // 2\n",
    "\n",
    "\n",
    "    merged_durations = torch.cumsum(torch.tensor(merged_durations), 0, dtype=torch.long)\n",
    "    start = torch.tensor(0)\n",
    "    duration_json = []\n",
    "    for i, duration in enumerate(merged_durations):\n",
    "        duration_json.append({\n",
    "            phones[i]: {\n",
    "                \"starttime\": start.item(),\n",
    "                \"endtime\": duration.item(),\n",
    "                \"duration\": duration.item() - start.item()\n",
    "            }\n",
    "        })\n",
    "        start = duration\n",
    "    assert list(duration_json[-1].values())[0]['endtime'] == output['decoder_outputs'].shape[-1], f\"{list(duration_json[-1].values())[0]['endtime'],  output['decoder_outputs'].shape[-1]}\"\n",
    "    return duration_json"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b93aac89-c7f8-4975-8510-4e763c9689f4",
   "metadata": {},
   "source": [
    "## Synthesis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a227963-aa12-43b9-a706-1168b6fc0ba5",
   "metadata": {},
   "outputs": [],
   "source": [
    "OUTPUT_FOLDER_TEMP = \"joe_fm_output_{}\"\n",
    "for name in range(6):\n",
    "    OUTPUT_FOLDER = OUTPUT_FOLDER_TEMP.format(name)\n",
    "    print(OUTPUT_FOLDER)\n",
    "    outputs, rtfs = [], []\n",
    "    rtfs_w = []\n",
    "    for i, text in enumerate(tqdm(texts)):\n",
    "        seed_everything(random.randint(1, 10000))\n",
    "        output = synthesise(text) #, torch.tensor([15], device=device, dtype=torch.long).unsqueeze(0))\n",
    "        output['waveform'] = to_waveform(output['mel'], vocoder)\n",
    "        output['duration_json'] = save_phoneme_durations(output)\n",
    "        # Compute Real Time Factor (RTF) with HiFi-GAN\n",
    "        t = (dt.datetime.now() - output['start_t']).total_seconds()\n",
    "        rtf_w = t * 22050 / (output['waveform'].shape[-1])\n",
    "    \n",
    "        ## Pretty print\n",
    "        print(f\"{'*' * 53}\")\n",
    "        print(f\"Input text - {i}\")\n",
    "        print(f\"{'-' * 53}\")\n",
    "        print(output['x_orig'])\n",
    "        print(f\"{'*' * 53}\")\n",
    "        print(f\"Phonetised text - {i}\")\n",
    "        print(f\"{'-' * 53}\")\n",
    "        print(output['x_phones'])\n",
    "        print(f\"{'*' * 53}\")\n",
    "        print(f\"RTF:\\t\\t{output['rtf']:.6f}\")\n",
    "        print(f\"RTF Waveform:\\t{rtf_w:.6f}\")\n",
    "        rtfs.append(output['rtf'])\n",
    "        rtfs_w.append(rtf_w)\n",
    "    \n",
    "        ## Display the synthesised waveform\n",
    "        # plot_spectrogram(output['mel'])\n",
    "        # ipd.display(ipd.Audio(output['waveform'], rate=22050))\n",
    "    \n",
    "        ## Save the generated waveform\n",
    "        save_to_folder(i, output, OUTPUT_FOLDER)\n",
    "    \n",
    "    print(f\"Number of ODE steps: {n_timesteps}\")\n",
    "    print(f\"Mean RTF:\\t\\t\\t\\t{np.mean(rtfs):.6f} ± {np.std(rtfs):.6f}\")\n",
    "    print(f\"Mean RTF Waveform (incl. vocoder):\\t{np.mean(rtfs_w):.6f} ± {np.std(rtfs_w):.6f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "107ff003-8a32-4a11-9294-31622b07fc3e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd1f24e3-0fc8-487f-a478-46cda7ebaec9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d95afbb4-d0ae-4562-bbdf-e27fd99200cd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "840cf38d-978b-4114-b5bb-8963a8a97517",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "41a1a18ac6aa4f39beab630b1767ad37",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "  0%|          | 0/11 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 1483\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 1.,  1.,  7.,  5.,  3.,  1.,  5.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  4.,  3.,  2.,  4.,  3.,  2.,  4.,  1.,  1.,  2.,  2.,\n",
      "           4.,  1.,  2., 11.,  2.,  5.,  4.,  1.,  1.,  1.,  1.,  1.,  4.,  1.,\n",
      "           1.,  3.,  1.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           3.,  4.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,\n",
      "           2.,  1.,  2.,  2.,  3.,  4.,  3.,  1.,  3.,  1.,  2.,  4.,  2.,  2.,\n",
      "           1.,  2.,  2.,  2.,  2.,  1.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,\n",
      "           1.,  1.,  3.,  1.,  1.,  1.,  2.,  2.,  3.,  1.,  4.,  3.,  4., 15.,\n",
      "          25.,  3.,  9., 14.,  5.,  1.,  3.,  1.,  2.,  4.,  1.,  1.,  2.,  1.,\n",
      "           1.,  3.,  1.,  1.,  3.,  2.,  1.,  3.,  1.,  2.,  1.,  3.,  2.,  3.,\n",
      "           4.,  3.,  2.,  3.,  1.,  2.,  6.,  1.,  4.,  1.,  4.,  1.,  3.,  1.,\n",
      "           4.,  1.,  7.,  3.,  3.,  5.,  3.,  4.,  1.,  1.,  2.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  4.,  1.,  1.,  1.,  2.,  3.,\n",
      "           2.,  2.,  1.,  1.,  1.,  2.,  4.,  5.,  5.,  1.,  1.,  2.,  3.,  3.,\n",
      "           2.,  3.,  5.,  2.,  2.,  6.,  3.,  2.,  7.,  6.,  9.,  1.,  1.,  3.,\n",
      "           1.,  1.,  2.,  1.,  1.,  4.,  2.,  2.,  2.,  2.,  1.,  1.,  1.,  3.,\n",
      "           1.,  1.,  1.,  2.,  3.,  2.,  1.,  1.,  1.,  2.,  1.,  3.,  1.,  1.,\n",
      "           2.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  3.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  2.,  2.,  1.,\n",
      "           1.,  1.,  4.,  2.,  2.,  2.,  3.,  2.,  3.,  4.,  4.,  1.,  5.,  4.,\n",
      "           6.,  2.,  2.,  3.,  3.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2.,  2.,  1.,  2.,  1.,  1.,  5.,  1.,  1.,  2.,\n",
      "           2.,  2.,  1.,  1.,  2.,  1.,  2.,  1.,  3.,  1.,  4.,  4.,  1.,  3.,\n",
      "           2.,  3.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  3.,  1.,  1.,  3.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  1.,  2.,  2.,  2.,  1.,  1.,  1.,  3.,  2.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  2.,  2.,\n",
      "           1.,  3.,  1.,  1.,  3.,  3.,  1.,  1.,  3.,  1.,  1.,  5.,  7.,  4.,\n",
      "           4.,  1.,  2.,  1.,  3.,  3.,  2.,  2.,  1.]]], device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 0\n",
      "-----------------------------------------------------\n",
      "; What I used to do this is crazy I was destroying my skin, ; in the mornings because I used to hate sweating, because that would make my skin oily; and that will block my pores and that will give me more spots.\n",
      "*****************************************************\n",
      "Phonetised text - 0\n",
      "-----------------------------------------------------\n",
      "_;_ _w_ˌ_ʌ_t_ _ˈ_a_ɪ_ _j_ˈ_u_ː_z_d_ _t_ə_ _d_ˈ_u_ː_ _ð_ɪ_s_ _ɪ_z_ _k_ɹ_ˈ_e_ɪ_z_i_ _ˈ_a_ɪ_ _w_ʌ_z_ _d_ᵻ_s_t_ɹ_ˈ_ɔ_ɪ_ɪ_ŋ_ _m_a_ɪ_ _s_k_ˈ_ɪ_n_,_ _;_ _ɪ_n_ð_ə_ _m_ˈ_ɔ_ː_ɹ_n_ɪ_ŋ_z_ _b_ɪ_k_ˈ_ʌ_z_ _ˈ_a_ɪ_ _j_ˈ_u_ː_z_d_ _t_ə_ _h_ˈ_e_ɪ_t_ _s_w_ˈ_ɛ_ɾ_ɪ_ŋ_,_ _b_ɪ_k_ˈ_ʌ_z_ _ð_æ_t_ _w_ʊ_d_ _m_ˌ_e_ɪ_k_ _m_a_ɪ_ _s_k_ˈ_ɪ_n_ _ˈ_ɔ_ɪ_l_i_;_ _æ_n_d_ _ð_æ_t_ _w_ɪ_l_ _b_l_ˈ_ɑ_ː_k_ _m_a_ɪ_ _p_ˈ_o_ː_ɹ_z_ _æ_n_d_ _ð_æ_t_ _w_ɪ_l_ _ɡ_ˈ_ɪ_v_ _m_ˌ_i_ː_ _m_ˈ_o_ː_ɹ_ _s_p_ˈ_ɑ_ː_t_s_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.015652\n",
      "RTF Waveform:\t0.019757\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 172752 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 619240 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 2243\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 3.,  3.,  1.,  2.,  1.,  1.,  2.,  7.,  2.,  1.,  1.,  1.,  2.,  1.,\n",
      "           3.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  2.,  6.,  2.,  3., 13.,  1.,  2.,  2.,  1.,  1.,  3.,  1.,\n",
      "           5., 15.,  1.,  5.,  1.,  3.,  2.,  1.,  1.,  1.,  1.,  2.,  3.,  1.,\n",
      "           1.,  2.,  1.,  2.,  3.,  2.,  1.,  2.,  4.,  1.,  2.,  1.,  3.,  4.,\n",
      "           1.,  3.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  2.,  2.,  3.,  6.,  2.,  2.,  2.,  1.,  2.,  2.,  5.,  2.,\n",
      "           1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  2.,  1.,  1.,  1.,  2.,  3.,  1.,  3.,  7.,  5.,  5., 10.,\n",
      "          26.,  5.,  7.,  7.,  7.,  2.,  2.,  1.,  1.,  1.,  3.,  1.,  2.,  1.,\n",
      "           1.,  3.,  1.,  1.,  2.,  1.,  3.,  1.,  3.,  2.,  2.,  1.,  1.,  2.,\n",
      "           3.,  2.,  3.,  4.,  2.,  1.,  3.,  1.,  3.,  1.,  4.,  1.,  3.,  2.,\n",
      "           3.,  3., 38.,  3.,  3.,  6.,  2.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  2.,  2.,\n",
      "           1.,  3.,  1.,  2.,  1.,  3.,  7.,  2.,  3.,  2.,  2.,  2.,  3.,  2.,\n",
      "           1.,  3.,  2.,  1.,  2.,  3.,  2.,  2., 10.,  6., 34.,  1.,  1.,  4.,\n",
      "           2.,  1.,  2.,  2.,  2.,  4.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  3.,\n",
      "           2.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  1.,  1.,  1.,  2.,  1.,  2.,  3.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  2.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  3.,\n",
      "           1.,  1.,  2.,  3.,  1.,  2.,  3.,  1.,  1.,  6.,  3.,  2.,  9., 12.,\n",
      "           4.,  2.,  2.,  3.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           2.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  4.,  1.,  1.,  1.,\n",
      "           1.,  2.,  2.,  1.,  1.,  1.,  3.,  1.,  2.,  1.,  5.,  3.,  1.,  2.,\n",
      "           1.,  3.,  1.,  1.,  1.,  1.,  3.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  1.,  3.,  3.,  1.,  1.,\n",
      "           1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,\n",
      "           2.,  4.,  1.,  1.,  2.,  4.,  1.,  1.,  3.,  1.,  1.,  2.,  5.,  2.,\n",
      "           2.,  2.,  2.,  1.,  5.,  7.,  2.,  1.,  2.]]], device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 1\n",
      "-----------------------------------------------------\n",
      "; What I used to do this is crazy I was destroying my skin, ; in the mornings because I used to hate sweating, because that would make my skin oily; and that will block my pores and that will give me more spots.\n",
      "*****************************************************\n",
      "Phonetised text - 1\n",
      "-----------------------------------------------------\n",
      "_;_ _w_ˌ_ʌ_t_ _ˈ_a_ɪ_ _j_ˈ_u_ː_z_d_ _t_ə_ _d_ˈ_u_ː_ _ð_ɪ_s_ _ɪ_z_ _k_ɹ_ˈ_e_ɪ_z_i_ _ˈ_a_ɪ_ _w_ʌ_z_ _d_ᵻ_s_t_ɹ_ˈ_ɔ_ɪ_ɪ_ŋ_ _m_a_ɪ_ _s_k_ˈ_ɪ_n_,_ _;_ _ɪ_n_ð_ə_ _m_ˈ_ɔ_ː_ɹ_n_ɪ_ŋ_z_ _b_ɪ_k_ˈ_ʌ_z_ _ˈ_a_ɪ_ _j_ˈ_u_ː_z_d_ _t_ə_ _h_ˈ_e_ɪ_t_ _s_w_ˈ_ɛ_ɾ_ɪ_ŋ_,_ _b_ɪ_k_ˈ_ʌ_z_ _ð_æ_t_ _w_ʊ_d_ _m_ˌ_e_ɪ_k_ _m_a_ɪ_ _s_k_ˈ_ɪ_n_ _ˈ_ɔ_ɪ_l_i_;_ _æ_n_d_ _ð_æ_t_ _w_ɪ_l_ _b_l_ˈ_ɑ_ː_k_ _m_a_ɪ_ _p_ˈ_o_ː_ɹ_z_ _æ_n_d_ _ð_æ_t_ _w_ɪ_l_ _ɡ_ˈ_ɪ_v_ _m_ˌ_i_ː_ _m_ˈ_o_ː_ɹ_ _s_p_ˈ_ɑ_ː_t_s_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.014977\n",
      "RTF Waveform:\t0.024358\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 172764 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 648592 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 7277\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 6.,  1.,  5., 13., 16.,  3.,  2.,  5.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  4.,  1.,\n",
      "           2.,  1.,  2.,  1.,  3.,  3.,  5.,  5.,  2.,  3.,  1.,  2.,  2.,  1.,\n",
      "           2.,  1.,  1.,  4.,  3.,  1.,  2.,  1.,  2.,  3.,  1.,  4.,  3.,  1.,\n",
      "           1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  2.,  2.,  4.,  7.,  6.,  1.,  2.,  1.,  3.,  2.,  5.,  1.,\n",
      "           2.,  1.,  2.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  2.,  1.,  1.,  1.,  5.,  2.,  2.,  3.,  3., 15., 25.,\n",
      "          12.,  4.,  8., 26.,  1.,  1.,  1.,  1.,  1.,  2.,  2.,  2.,  2.,  1.,\n",
      "           2.,  3.,  1.,  1.,  2.,  1.,  2.,  1.,  3.,  1.,  4.,  1.,  2.,  2.,\n",
      "           3.,  2.,  2.,  2.,  1.,  2.,  4.,  1.,  3.,  1.,  4.,  1.,  3.,  1.,\n",
      "           2.,  3.,  6.,  6.,  3.,  3.,  3.,  5.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,\n",
      "           1.,  2.,  1.,  2.,  2.,  3.,  5.,  2.,  2.,  2.,  1.,  1.,  3.,  2.,\n",
      "           2.,  2.,  5.,  2.,  2.,  2.,  4.,  4.,  3.,  5.,  1.,  1.,  2.,  5.,\n",
      "           1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,  2.,  1.,  2.,  1.,  3.,\n",
      "           1.,  1.,  2.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,\n",
      "           1.,  1.,  2.,  3.,  1.,  1.,  2.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  6.,  1.,  2.,  1.,  1.,  2.,  2.,  3.,  1.,  3.,\n",
      "           1.,  2.,  2.,  3.,  1.,  2.,  2.,  2.,  3.,  5.,  3.,  2.,  6.,  9.,\n",
      "           3.,  3.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  2.,  1.,  1.,  2.,  1.,  2.,  2.,  1.,  1.,  1.,\n",
      "           2.,  1.,  2.,  1.,  1.,  2.,  2.,  1.,  4.,  1.,  4.,  3.,  2.,  2.,\n",
      "           2.,  2.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  3.,  2.,  1.,  1.,\n",
      "           1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  2.,\n",
      "           2.,  1.,  1.,  1.,  2.,  3.,  2.,  1.,  4.,  1.,  1.,  4.,  5.,  4.,\n",
      "           3.,  4.,  2.,  2.,  4.,  2.,  3.,  1.,  3.]]], device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 2\n",
      "-----------------------------------------------------\n",
      "; What I used to do this is crazy I was destroying my skin, ; in the mornings because I used to hate sweating, because that would make my skin oily; and that will block my pores and that will give me more spots.\n",
      "*****************************************************\n",
      "Phonetised text - 2\n",
      "-----------------------------------------------------\n",
      "_;_ _w_ˌ_ʌ_t_ _ˈ_a_ɪ_ _j_ˈ_u_ː_z_d_ _t_ə_ _d_ˈ_u_ː_ _ð_ɪ_s_ _ɪ_z_ _k_ɹ_ˈ_e_ɪ_z_i_ _ˈ_a_ɪ_ _w_ʌ_z_ _d_ᵻ_s_t_ɹ_ˈ_ɔ_ɪ_ɪ_ŋ_ _m_a_ɪ_ _s_k_ˈ_ɪ_n_,_ _;_ _ɪ_n_ð_ə_ _m_ˈ_ɔ_ː_ɹ_n_ɪ_ŋ_z_ _b_ɪ_k_ˈ_ʌ_z_ _ˈ_a_ɪ_ _j_ˈ_u_ː_z_d_ _t_ə_ _h_ˈ_e_ɪ_t_ _s_w_ˈ_ɛ_ɾ_ɪ_ŋ_,_ _b_ɪ_k_ˈ_ʌ_z_ _ð_æ_t_ _w_ʊ_d_ _m_ˌ_e_ɪ_k_ _m_a_ɪ_ _s_k_ˈ_ɪ_n_ _ˈ_ɔ_ɪ_l_i_;_ _æ_n_d_ _ð_æ_t_ _w_ɪ_l_ _b_l_ˈ_ɑ_ː_k_ _m_a_ɪ_ _p_ˈ_o_ː_ɹ_z_ _æ_n_d_ _ð_æ_t_ _w_ɪ_l_ _ɡ_ˈ_ɪ_v_ _m_ˌ_i_ː_ _m_ˈ_o_ː_ɹ_ _s_p_ˈ_ɑ_ː_t_s_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.015723\n",
      "RTF Waveform:\t0.025196\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 171340 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 617872 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 3959\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 3., 11.,  1.,  1.,  3.,  4.,  4.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  1.,  2.,\n",
      "           1.,  2.,  2.,  1.,  1.,  1.,  2.,  5.,  1.,  2.,  2.,  7.,  8.,  3.,\n",
      "           2.,  4., 11.,  5.,  1.,  4.,  1.,  1.,  2.,  3.,  3.,  1.,  1.,  3.,\n",
      "           7.,  3.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  4.,  1.,  1.,  1.,\n",
      "           2.,  3.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  3.,\n",
      "           2.,  3.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  2.,  2.,  1.,\n",
      "           1.,  1.,  2.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  3.,  4.,  5.,  4.,\n",
      "           4.,  3.,  5.,  2.,  7., 10.,  1.,  2.,  1.,  2.,  3.,  2., 10.,  1.,\n",
      "           1.,  4.,  2.,  2.,  3.,  1.,  1.,  2.,  2.,  6.,  4.,  4.,  2.,  1.,\n",
      "           1.,  2.,  3.,  7., 19.,  9.,  3.,  2., 13.,  6.,  4.,  2.,  1.,  1.,\n",
      "           2.,  1.,  1.,  2., 18., 11., 33.,  2.,  3.,  1.,  2.,  1.,  1.,  3.,\n",
      "           1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  2.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  3.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  2.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  2.,  1.,\n",
      "           3.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           3.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  2.,  1.,  2.,  3.,  5.,  4.,  1.,  2.,  1.,  3.,\n",
      "           2.,  1.,  3.,  1.,  2.,  2.,  2.,  3.,  2.,  3.,  1.,  1.,  1.,  1.,\n",
      "           3.,  2.,  1.,  4.,  1.,  1.,  1.,  1.,  2.,  1.,  3.]]],\n",
      "       device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 3\n",
      "-----------------------------------------------------\n",
      "; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\n",
      "*****************************************************\n",
      "Phonetised text - 3\n",
      "-----------------------------------------------------\n",
      "_;_ _s_ˌ_o_ʊ_ _ˈ_a_ɪ_ _ɹ_ᵻ_m_ˈ_ɛ_m_b_ɚ_ɹ_ _ˈ_a_ɪ_ _ɹ_ˈ_æ_n_ _æ_z_ _f_ˈ_æ_s_t_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _ˈ_a_ɪ_ _t_ɹ_ˈ_a_ɪ_d_ _t_ə_ _ɡ_ɛ_t_ _ˈ_a_ʊ_t_;_ _,_ _b_ᵻ_t_w_ˌ_i_ː_n_ _ˈ_e_ɪ_;_ _,_ _ð_ə_ _p_ˈ_i_ː_p_ə_l_ _æ_z_ _k_w_ˈ_ɪ_k_l_i_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _b_ɪ_k_ˈ_ʌ_z_ _ˈ_a_ɪ_ _w_ʌ_z_ _l_ˈ_a_ɪ_k_ _ˈ_o_ʊ_ _m_a_ɪ_ _ɡ_ˈ_ɑ_ː_d_ _m_a_ɪ_ _s_t_ˈ_ʌ_m_ə_k_ _ɪ_z_ _d_ʒ_ˈ_ʌ_s_t_ _l_ˈ_a_ɪ_k_,_ _k_ˈ_ɪ_l_ɪ_ŋ_ _m_ˌ_i_ː_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.021925\n",
      "RTF Waveform:\t0.034056\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 173856 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 531176 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 2505\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[10.,  1.,  1.,  1.,  6.,  1.,  2., 14.,  1.,  1.,  2.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,  2.,  1.,  3.,\n",
      "           1.,  2.,  1.,  3.,  1.,  1.,  1.,  5.,  1.,  2.,  1.,  3.,  6., 10.,\n",
      "           6.,  3.,  4.,  3.,  2.,  7.,  2.,  2.,  4.,  3.,  3.,  1.,  1.,  2.,\n",
      "           6.,  2.,  2.,  1.,  1.,  3.,  2.,  1.,  1.,  1.,  3.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1., 13.,  2., 12.,  4.,\n",
      "           2.,  3.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,\n",
      "           1.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  1.,  1.,  3.,  2.,  1.,  1.,  3.,  2.,  3.,  3.,  4.,\n",
      "           4.,  1., 10.,  2.,  3.,  8.,  1.,  5.,  6.,  3.,  4.,  6.,  7.,  1.,\n",
      "           1.,  5.,  2.,  1.,  2.,  1.,  2.,  2.,  3.,  2.,  2.,  3.,  2.,  1.,\n",
      "           1.,  1.,  4.,  3.,  7.,  7.,  4.,  2.,  5.,  4.,  3.,  1.,  6.,  8.,\n",
      "           2.,  2.,  2.,  3., 24., 11., 30.,  3.,  3.,  1.,  3.,  1.,  2.,  3.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  3.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  2.,  1.,  1.,  2.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  1.,  5.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  2.,  1.,  1.,  2.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  2.,  3.,  1.,  1.,  5.,  3.,  3.,  4.,  1.,  2.,  1.,  4.,\n",
      "           1.,  1.,  8.,  2.,  4.,  2.,  3.,  3.,  2.,  3.,  1.,  3.,  1.,  3.,\n",
      "           2.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  1.]]],\n",
      "       device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 4\n",
      "-----------------------------------------------------\n",
      "; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\n",
      "*****************************************************\n",
      "Phonetised text - 4\n",
      "-----------------------------------------------------\n",
      "_;_ _s_ˌ_o_ʊ_ _ˈ_a_ɪ_ _ɹ_ᵻ_m_ˈ_ɛ_m_b_ɚ_ɹ_ _ˈ_a_ɪ_ _ɹ_ˈ_æ_n_ _æ_z_ _f_ˈ_æ_s_t_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _ˈ_a_ɪ_ _t_ɹ_ˈ_a_ɪ_d_ _t_ə_ _ɡ_ɛ_t_ _ˈ_a_ʊ_t_;_ _,_ _b_ᵻ_t_w_ˌ_i_ː_n_ _ˈ_e_ɪ_;_ _,_ _ð_ə_ _p_ˈ_i_ː_p_ə_l_ _æ_z_ _k_w_ˈ_ɪ_k_l_i_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _b_ɪ_k_ˈ_ʌ_z_ _ˈ_a_ɪ_ _w_ʌ_z_ _l_ˈ_a_ɪ_k_ _ˈ_o_ʊ_ _m_a_ɪ_ _ɡ_ˈ_ɑ_ː_d_ _m_a_ɪ_ _s_t_ˈ_ʌ_m_ə_k_ _ɪ_z_ _d_ʒ_ˈ_ʌ_s_t_ _l_ˈ_a_ɪ_k_,_ _k_ˈ_ɪ_l_ɪ_ŋ_ _m_ˌ_i_ː_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.020586\n",
      "RTF Waveform:\t0.031185\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 174376 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 547560 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 4942\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 3.,  1.,  3., 10.,  3.,  6.,  3.,  4.,  1.,  1.,  2.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,\n",
      "           1.,  3.,  3.,  1.,  3.,  1.,  3.,  3.,  1.,  2.,  2.,  3.,  6.,  5.,\n",
      "           2.,  2.,  5.,  5.,  1.,  2.,  1.,  1.,  2.,  1.,  3.,  1.,  1.,  3.,\n",
      "           4.,  3.,  1.,  1.,  2.,  4.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  3.,\n",
      "           1.,  4.,  2.,  1.,  2.,  1.,  1.,  1.,  5.,  1.,  8.,  3.,  4.,  6.,\n",
      "           2.,  4.,  1.,  2.,  2.,  2.,  2.,  1.,  1.,  1.,  1.,  2.,  3.,  1.,\n",
      "           1.,  1.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,  2.,  2.,  3.,  3.,\n",
      "           5.,  2.,  8.,  2.,  8.,  2.,  3.,  5.,  1.,  3.,  3.,  4.,  2.,  1.,\n",
      "           1.,  4.,  2.,  2.,  3.,  1.,  5.,  1.,  3.,  4.,  5.,  4.,  3.,  3.,\n",
      "           2.,  2.,  4.,  4.,  5., 11.,  2.,  3.,  5.,  9.,  2.,  3.,  1.,  2.,\n",
      "           2.,  1.,  1.,  1.,  5., 10., 15.,  2.,  3.,  1.,  2.,  2.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  5.,  4.,  2.,  1.,  1.,  1.,\n",
      "           2.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  5.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  2.,  2.,  2.,  1.,  1.,  1.,  1.,  2.,\n",
      "           3.,  2.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  1.,  1.,  1.,  2.,  3.,  4.,  1.,  3.,  2.,  1.,\n",
      "           3.,  1.,  5.,  1.,  3.,  3.,  4.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.]]],\n",
      "       device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 5\n",
      "-----------------------------------------------------\n",
      "; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\n",
      "*****************************************************\n",
      "Phonetised text - 5\n",
      "-----------------------------------------------------\n",
      "_;_ _s_ˌ_o_ʊ_ _ˈ_a_ɪ_ _ɹ_ᵻ_m_ˈ_ɛ_m_b_ɚ_ɹ_ _ˈ_a_ɪ_ _ɹ_ˈ_æ_n_ _æ_z_ _f_ˈ_æ_s_t_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _ˈ_a_ɪ_ _t_ɹ_ˈ_a_ɪ_d_ _t_ə_ _ɡ_ɛ_t_ _ˈ_a_ʊ_t_;_ _,_ _b_ᵻ_t_w_ˌ_i_ː_n_ _ˈ_e_ɪ_;_ _,_ _ð_ə_ _p_ˈ_i_ː_p_ə_l_ _æ_z_ _k_w_ˈ_ɪ_k_l_i_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _b_ɪ_k_ˈ_ʌ_z_ _ˈ_a_ɪ_ _w_ʌ_z_ _l_ˈ_a_ɪ_k_ _ˈ_o_ʊ_ _m_a_ɪ_ _ɡ_ˈ_ɑ_ː_d_ _m_a_ɪ_ _s_t_ˈ_ʌ_m_ə_k_ _ɪ_z_ _d_ʒ_ˈ_ʌ_s_t_ _l_ˈ_a_ɪ_k_,_ _k_ˈ_ɪ_l_ɪ_ŋ_ _m_ˌ_i_ː_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.022296\n",
      "RTF Waveform:\t0.033840\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 173968 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 498408 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 195\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 5.,  7.,  1.,  1., 13.,  4.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  4.,  1.,\n",
      "           1.,  2.,  2.,  1.,  1.,  1.,  4.,  2.,  1.,  2.,  4.,  7.,  6.,  7.,\n",
      "           3.,  3.,  2.,  2.,  2.,  2.,  1.,  2.,  3.,  7.,  5.,  1.,  1.,  1.,\n",
      "           4.,  5.,  3.,  1.,  2.,  3.,  1.,  1.,  2.,  2.,  4.,  2.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,  7.,  4.,\n",
      "           3.,  2.,  1.,  2.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  1.,  2.,  2.,  2.,  4.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2.,  2.,  2.,  1.,  1.,  3.,  1.,  3.,  3.,  2.,\n",
      "           3.,  2.,  3.,  1.,  8.,  1.,  7.,  4.,  2.,  4.,  7.,  4.,  4.,  1.,\n",
      "           1.,  6.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  3.,  4.,  4.,  1.,  1.,\n",
      "           1.,  2.,  5.,  4.,  8., 12.,  4.,  2., 14.,  5.,  2.,  2.,  2.,  3.,\n",
      "           5.,  1.,  5.,  2., 17.,  6., 21.,  6.,  3.,  1.,  2.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,  3.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  3.,  1.,  2.,  1.,  1.,  1.,  2.,  1.,  3.,  1.,  2.,  2.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,\n",
      "           1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  2.,  1.,\n",
      "           1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  2.,  2.,  1.,  2.,  3.,  4.,  4.,  2.,  1.,  1.,  2.,\n",
      "           2.,  1.,  5.,  1.,  2.,  2.,  2.,  1.,  1.,  3.,  2.,  1.,  1.,  1.,\n",
      "           2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  3.,  4.]]],\n",
      "       device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 6\n",
      "-----------------------------------------------------\n",
      "; So I remember I ran as fast as I could I tried to get out; , between a; , The people as quickly as I could because I was like oh my god my stomach is just like, Killing me.\n",
      "*****************************************************\n",
      "Phonetised text - 6\n",
      "-----------------------------------------------------\n",
      "_;_ _s_ˌ_o_ʊ_ _ˈ_a_ɪ_ _ɹ_ᵻ_m_ˈ_ɛ_m_b_ɚ_ɹ_ _ˈ_a_ɪ_ _ɹ_ˈ_æ_n_ _æ_z_ _f_ˈ_æ_s_t_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _ˈ_a_ɪ_ _t_ɹ_ˈ_a_ɪ_d_ _t_ə_ _ɡ_ɛ_t_ _ˈ_a_ʊ_t_;_ _,_ _b_ᵻ_t_w_ˌ_i_ː_n_ _ˈ_e_ɪ_;_ _,_ _ð_ə_ _p_ˈ_i_ː_p_ə_l_ _æ_z_ _k_w_ˈ_ɪ_k_l_i_ _æ_z_ _ˈ_a_ɪ_ _k_ʊ_d_ _b_ɪ_k_ˈ_ʌ_z_ _ˈ_a_ɪ_ _w_ʌ_z_ _l_ˈ_a_ɪ_k_ _ˈ_o_ʊ_ _m_a_ɪ_ _ɡ_ˈ_ɑ_ː_d_ _m_a_ɪ_ _s_t_ˈ_ʌ_m_ə_k_ _ɪ_z_ _d_ʒ_ˈ_ʌ_s_t_ _l_ˈ_a_ɪ_k_,_ _k_ˈ_ɪ_l_ɪ_ŋ_ _m_ˌ_i_ː_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.018696\n",
      "RTF Waveform:\t0.022766\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 174956 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 525712 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 9757\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 3.,  2.,  1.,  3.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  2.,  2.,  2.,  1.,  1.,  2.,  1.,  3.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  3.,  2.,  1.,  1.,  3.,  2.,  2.,  2.,  2.,  4., 17.,  5.,  4.,\n",
      "           1.,  4.,  1.,  1.,  1.,  2.,  2.,  1.,  2.,  1.,  1.,  1.,  2.,  2.,\n",
      "           3.,  1.,  1.,  2.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  2.,  2.,  2.,\n",
      "           1.,  1.,  3.,  1.,  2.,  2.,  3.,  2.,  2.,  3.,  1.,  1.,  2.,  8.,\n",
      "           1.,  1.,  2.,  2.,  1.,  1.,  3.,  1.,  1.,  1.,  3.,  1.,  2.,  1.,\n",
      "           3.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,  1., 10.,  1.,  1.,  1.,  1.,\n",
      "           1.,  3.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  2.,  5.,  1.,  2.,  2.,  4.,  1.,  3.,  1.,  1.,  2.,\n",
      "           1.,  1.,  2.,  1.,  1.,  3.,  3.,  3.,  1.,  1.,  2.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,\n",
      "           1.,  2.,  3.,  2.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2., 18.,  2.,  2.,  5.,  2.,  1.,  1.,  1.,  2.,\n",
      "           2.,  1.,  4.,  2.,  2.,  2.,  3.,  2.,  2.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  7.,  1.,  2.,  1.,\n",
      "           3.,  1.,  1.,  3.,  2.,  2.,  3.,  1.,  2.,  2.,  1.,  1.,  1.,  3.,\n",
      "           1.,  1.,  2.,  2.,  2.,  4.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  1.,  2.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  3.,\n",
      "           3.,  1.,  2.,  3.,  9.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  1.,\n",
      "           2.,  2.,  2.,  1.,  2.,  1.,  1.,  2.,  2.,  1.,  2.,  1.,  2.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  2.,  1.,  4.,  4.,  2.,  2.,  1.,  2.,  5.,\n",
      "           1., 13.,  2.,  2.,  9.,  1.,  1.,  5.,  3.,  1.,  3.,  2., 11.,  2.,\n",
      "           2.,  2.,  1.,  2.,  1.,  2.,  5.,  8., 10.,  6.,  2.,  1.,  1.,  2.,\n",
      "          13.]]], device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 7\n",
      "-----------------------------------------------------\n",
      "that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\n",
      "*****************************************************\n",
      "Phonetised text - 7\n",
      "-----------------------------------------------------\n",
      "_ð_æ_t_s_ _ˈ_o_ʊ_n_l_i_ _ɐ_n_ˈ_ʌ_ð_ɚ_ _s_t_ˈ_o_ː_ɹ_i_;_ _s_ˈ_e_ɪ_m_ _s_t_ˈ_o_ː_ɹ_i_ _ɐ_ɡ_ˈ_ɛ_n_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _ð_ɪ_s_ _ɪ_z_ _ð_ə_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _a_ɪ_m_ _t_ˈ_ɛ_l_ɪ_ŋ_ _j_u_ː_;_ _ð_ɛ_ɹ_ _h_ˈ_a_ʊ_s_ _ɪ_z_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _w_ˈ_ʌ_n_h_ˈ_ʌ_n_d_ɹ_ɪ_d_ _p_ɚ_s_ˈ_ɛ_n_t_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _o_ʊ_k_ˈ_e_ɪ_?_;_ _b_ɪ_k_ˈ_ʌ_z_ _ð_e_ɪ_ɚ_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.025769\n",
      "RTF Waveform:\t0.038450\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 169508 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 467004 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 795\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 2.,  1.,  1.,  3.,  1.,  1.,  1.,  2.,  1.,  1.,  3.,  2.,  1.,  2.,\n",
      "           1.,  2.,  1.,  1.,  1.,  3.,  1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  3.,  2.,  3.,  1.,  3.,  1.,  1.,  2.,  2.,  1.,  1.,  6.,  1.,\n",
      "           2.,  3.,  2.,  1.,  2.,  2.,  3.,  1.,  1.,  1.,  5., 15.,  3.,  7.,\n",
      "           1.,  8.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,\n",
      "           2.,  2.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,\n",
      "           1.,  1.,  3.,  1.,  2.,  2.,  4.,  3.,  2.,  4.,  2.,  2.,  1.,  6.,\n",
      "           1.,  1.,  2.,  2.,  2.,  1.,  2.,  2.,  1.,  3.,  2.,  1.,  1.,  2.,\n",
      "           2.,  3.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  5.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  3.,  2.,  2.,  1.,  1.,  1.,\n",
      "           1.,  1.,  3.,  1.,  1.,  1.,  3.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  3.,\n",
      "           1.,  1.,  2.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  3., 16.,  3.,  2.,  3.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  2.,  9.,  2.,  1.,  2.,  3.,  3.,  1.,  2.,  1.,  1.,  4.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  2.,  3.,  2.,  1.,  1.,  6.,  1.,  2.,  1.,\n",
      "           2.,  1.,  1.,  2.,  1.,  2.,  1.,  4.,  1.,  2.,  1.,  1.,  2.,  1.,\n",
      "           2.,  2.,  2.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,  2.,  2.,  3.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  2.,  2.,  1.,  2.,\n",
      "           2.,  2.,  3.,  1.,  1.,  2.,  1.,  3.,  1.,  1.,  3.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  3.,  1.,  3.,  4.,  2.,  2.,  2.,  3.,  5.,\n",
      "           1., 18.,  2.,  1.,  7.,  1.,  1.,  4.,  2.,  1.,  4.,  1.,  8.,  2.,\n",
      "           2.,  1.,  1.,  1.,  1.,  2.,  5.,  6.,  6.,  6.,  2.,  2.,  1.,  1.,\n",
      "           1.]]], device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 8\n",
      "-----------------------------------------------------\n",
      "that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\n",
      "*****************************************************\n",
      "Phonetised text - 8\n",
      "-----------------------------------------------------\n",
      "_ð_æ_t_s_ _ˈ_o_ʊ_n_l_i_ _ɐ_n_ˈ_ʌ_ð_ɚ_ _s_t_ˈ_o_ː_ɹ_i_;_ _s_ˈ_e_ɪ_m_ _s_t_ˈ_o_ː_ɹ_i_ _ɐ_ɡ_ˈ_ɛ_n_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _ð_ɪ_s_ _ɪ_z_ _ð_ə_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _a_ɪ_m_ _t_ˈ_ɛ_l_ɪ_ŋ_ _j_u_ː_;_ _ð_ɛ_ɹ_ _h_ˈ_a_ʊ_s_ _ɪ_z_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _w_ˈ_ʌ_n_h_ˈ_ʌ_n_d_ɹ_ɪ_d_ _p_ɚ_s_ˈ_ɛ_n_t_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _o_ʊ_k_ˈ_e_ɪ_?_;_ _b_ɪ_k_ˈ_ʌ_z_ _ð_e_ɪ_ɚ_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.024802\n",
      "RTF Waveform:\t0.038028\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 165132 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 442428 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 6567\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 1.,  1.,  1.,  3.,  2.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  2.,  2.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  2.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,\n",
      "           1.,  1.,  2.,  3.,  2.,  1.,  2.,  3.,  1.,  2.,  7., 13.,  9.,  3.,\n",
      "           1.,  1.,  2.,  1.,  1.,  2.,  5.,  1.,  2.,  3.,  1.,  1.,  2.,  2.,\n",
      "           2.,  1.,  1.,  1.,  2.,  3.,  3.,  2.,  1.,  3.,  1.,  2.,  2.,  1.,\n",
      "           1.,  1.,  1.,  2.,  3.,  2.,  4.,  2.,  2.,  1.,  1.,  1.,  2.,  3.,\n",
      "           1.,  1.,  3.,  2.,  2.,  1.,  2.,  2.,  1.,  1.,  3.,  1.,  2.,  1.,\n",
      "           2.,  2.,  1.,  3.,  1.,  3.,  1.,  1.,  1.,  1.,  2.,  3.,  1.,  1.,\n",
      "           1.,  3.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  2.,  3.,  2.,  1.,  1.,  3.,  2.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  1.,  1.,  2.,  3.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,\n",
      "           1.,  2.,  1.,  2.,  2.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  3., 12.,  1.,  3.,  3.,  1.,  1.,  1.,  2.,  2.,\n",
      "           2.,  4.,  4.,  1.,  2.,  2.,  2.,  2.,  2.,  2.,  1.,  2.,  3.,  1.,\n",
      "           1.,  1.,  2.,  1.,  1.,  2.,  2.,  3.,  3.,  2.,  6.,  3.,  3.,  1.,\n",
      "           5.,  1.,  1.,  2.,  1.,  3.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  2.,\n",
      "           2.,  1.,  1.,  2.,  1.,  3.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  3.,\n",
      "           1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  3.,  1.,  2.,  1.,  1.,\n",
      "           1.,  1.,  2.,  2.,  2.,  2.,  1.,  3.,  1.,  1.,  2.,  2.,  2.,  2.,\n",
      "           1.,  2.,  1.,  2.,  1.,  2.,  2.,  1.,  5.,  2.,  2.,  2.,  2.,  7.,\n",
      "           1.,  7.,  8.,  4.,  5.,  1.,  1.,  4.,  2.,  2.,  3.,  1., 10.,  1.,\n",
      "           3.,  1.,  1.,  2.,  1.,  1.,  6.,  8.,  6.,  5.,  2.,  1.,  1.,  2.,\n",
      "           1.]]], device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 9\n",
      "-----------------------------------------------------\n",
      "that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\n",
      "*****************************************************\n",
      "Phonetised text - 9\n",
      "-----------------------------------------------------\n",
      "_ð_æ_t_s_ _ˈ_o_ʊ_n_l_i_ _ɐ_n_ˈ_ʌ_ð_ɚ_ _s_t_ˈ_o_ː_ɹ_i_;_ _s_ˈ_e_ɪ_m_ _s_t_ˈ_o_ː_ɹ_i_ _ɐ_ɡ_ˈ_ɛ_n_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _ð_ɪ_s_ _ɪ_z_ _ð_ə_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _a_ɪ_m_ _t_ˈ_ɛ_l_ɪ_ŋ_ _j_u_ː_;_ _ð_ɛ_ɹ_ _h_ˈ_a_ʊ_s_ _ɪ_z_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _w_ˈ_ʌ_n_h_ˈ_ʌ_n_d_ɹ_ɪ_d_ _p_ɚ_s_ˈ_ɛ_n_t_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _o_ʊ_k_ˈ_e_ɪ_?_;_ _b_ɪ_k_ˈ_ʌ_z_ _ð_e_ɪ_ɚ_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.025533\n",
      "RTF Waveform:\t0.038864\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 166720 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 439696 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Global seed set to 3807\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 6.,  1.,  1.,  2.,  1.,  1.,  1.,  3.,  1.,  1.,  1.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  2.,  3.,  3.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  3.,  3.,  2.,  2.,  2.,  2.,  1.,  3.,  7.,  9.,  4.,  7.,\n",
      "           3.,  6.,  1.,  1.,  1.,  2.,  3.,  2.,  1.,  2.,  1.,  1.,  2.,  1.,\n",
      "           3.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  2.,  2.,  2.,  3.,  8.,  2.,  3.,  2.,  2.,  1.,  2.,  2.,  3.,\n",
      "           1.,  1.,  1.,  2.,  1.,  1.,  2.,  2.,  1.,  2.,  3.,  1.,  2.,  3.,\n",
      "           1.,  1.,  2.,  2.,  1.,  3.,  1.,  1.,  4.,  1.,  1.,  4.,  1.,  1.,\n",
      "           1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,\n",
      "           1.,  1.,  1.,  1.,  4.,  1.,  1.,  2.,  3.,  2.,  2.,  2.,  1.,  4.,\n",
      "           1.,  1.,  2.,  1.,  1.,  2.,  1.,  2.,  1.,  2.,  2.,  1.,  1.,  2.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  3.,\n",
      "           2.,  1.,  3.,  2.,  2.,  2.,  1.,  1.,  1.,  1.,  1.,  2.,  2.,  1.,\n",
      "           1.,  1.,  1.,  2.,  2., 12.,  3.,  1.,  4.,  1.,  1.,  1.,  2.,  2.,\n",
      "           1.,  2.,  4.,  2.,  2.,  2.,  2.,  3.,  5.,  1.,  1.,  2.,  2.,  2.,\n",
      "           1.,  2.,  1.,  1.,  1.,  2.,  2.,  1.,  2.,  2.,  5.,  1.,  2.,  1.,\n",
      "           2.,  3.,  1.,  3.,  1.,  6.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  3.,\n",
      "           1.,  5.,  2.,  1.,  1.,  1.,  1.,  3.,  1.,  1.,  2.,  1.,  2.,  1.,\n",
      "           1.,  1.,  1.,  1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  5.,\n",
      "           1.,  1.,  1.,  1.,  1.,  1.,  1.,  2.,  1.,  2.,  1.,  6.,  1.,  1.,\n",
      "           1.,  1.,  1.,  2.,  2.,  1.,  2.,  2.,  1.,  1.,  1.,  1.,  2.,  1.,\n",
      "           1.,  2.,  1.,  2.,  1.,  2.,  2.,  2.,  5.,  3.,  2.,  2.,  1.,  6.,\n",
      "           3.,  7.,  4.,  2.,  6.,  1.,  2.,  6.,  2.,  1.,  3.,  2.,  4.,  2.,\n",
      "           3.,  1.,  2.,  3.,  1.,  3.,  4.,  7.,  7.,  4.,  1.,  2.,  1.,  1.,\n",
      "           1.]]], device='cuda:0')\n",
      "*****************************************************\n",
      "Input text - 10\n",
      "-----------------------------------------------------\n",
      "that's only another story; Same story again same family This is the same family I'm telling you; Their house is haunted 100% haunted okay?; because they're.\n",
      "*****************************************************\n",
      "Phonetised text - 10\n",
      "-----------------------------------------------------\n",
      "_ð_æ_t_s_ _ˈ_o_ʊ_n_l_i_ _ɐ_n_ˈ_ʌ_ð_ɚ_ _s_t_ˈ_o_ː_ɹ_i_;_ _s_ˈ_e_ɪ_m_ _s_t_ˈ_o_ː_ɹ_i_ _ɐ_ɡ_ˈ_ɛ_n_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _ð_ɪ_s_ _ɪ_z_ _ð_ə_ _s_ˈ_e_ɪ_m_ _f_ˈ_æ_m_ɪ_l_i_ _a_ɪ_m_ _t_ˈ_ɛ_l_ɪ_ŋ_ _j_u_ː_;_ _ð_ɛ_ɹ_ _h_ˈ_a_ʊ_s_ _ɪ_z_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _w_ˈ_ʌ_n_h_ˈ_ʌ_n_d_ɹ_ɪ_d_ _p_ɚ_s_ˈ_ɛ_n_t_ _h_ˈ_ɔ_ː_n_t_ᵻ_d_ _o_ʊ_k_ˈ_e_ɪ_?_;_ _b_ɪ_k_ˈ_ʌ_z_ _ð_e_ɪ_ɚ_._\n",
      "*****************************************************\n",
      "RTF:\t\t0.024560\n",
      "RTF Waveform:\t0.040508\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 166008 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 444476 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of ODE steps: 10\n",
      "Mean RTF:\t\t\t\t0.020956 ± 0.003944\n",
      "Mean RTF Waveform (incl. vocoder):\t0.031546 ± 0.007028\n"
     ]
    }
   ],
   "source": [
    "outputs, rtfs = [], []\n",
    "rtfs_w = []\n",
    "for i, text in enumerate(tqdm(texts)):\n",
    "    seed_everything(random.randint(1, 10000))\n",
    "    output = synthesise(text) #, torch.tensor([15], device=device, dtype=torch.long).unsqueeze(0))\n",
    "    output['waveform'] = to_waveform(output['mel'], vocoder)\n",
    "\n",
    "    # Compute Real Time Factor (RTF) with HiFi-GAN\n",
    "    t = (dt.datetime.now() - output['start_t']).total_seconds()\n",
    "    rtf_w = t * 22050 / (output['waveform'].shape[-1])\n",
    "\n",
    "    ## Pretty print\n",
    "    print(f\"{'*' * 53}\")\n",
    "    print(f\"Input text - {i}\")\n",
    "    print(f\"{'-' * 53}\")\n",
    "    print(output['x_orig'])\n",
    "    print(f\"{'*' * 53}\")\n",
    "    print(f\"Phonetised text - {i}\")\n",
    "    print(f\"{'-' * 53}\")\n",
    "    print(output['x_phones'])\n",
    "    print(f\"{'*' * 53}\")\n",
    "    print(f\"RTF:\\t\\t{output['rtf']:.6f}\")\n",
    "    print(f\"RTF Waveform:\\t{rtf_w:.6f}\")\n",
    "    rtfs.append(output['rtf'])\n",
    "    rtfs_w.append(rtf_w)\n",
    "\n",
    "    ## Display the synthesised waveform\n",
    "    plot_spectrogram(output['mel'])\n",
    "    ipd.display(ipd.Audio(output['waveform'], rate=22050))\n",
    "\n",
    "    ## Save the generated waveform\n",
    "    save_to_folder(i, output, OUTPUT_FOLDER)\n",
    "\n",
    "print(f\"Number of ODE steps: {n_timesteps}\")\n",
    "print(f\"Mean RTF:\\t\\t\\t\\t{np.mean(rtfs):.6f} ± {np.std(rtfs):.6f}\")\n",
    "print(f\"Mean RTF Waveform (incl. vocoder):\\t{np.mean(rtfs_w):.6f} ± {np.std(rtfs_w):.6f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3e85c3f-1623-4647-b40c-fa96907656fc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "44530e0b-e83a-4441-a460-12a4f3e23e2c",
   "metadata": {},
   "outputs": [],
   "source": [
    "a1 = np.load('/home/smehta/Projects/Matcha-TTS/synth_output/0.npy')\n",
    "a2 = np.load('/home/smehta/Projects/Matcha-TTS/synth_output/1.npy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c8c9f781-aa0a-498f-bf6d-066d8c1a75f4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
