{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a16e80a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import re\n",
    "import json\n",
    "import tqdm\n",
    "import uuid\n",
    "import funcy\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from suno_utils.audio import Audio\n",
    "from suno_utils.audio.conversion import get_audio_properties, play_audio\n",
    "from suno_utils.utils.numbers import safe_round\n",
    "\n",
    "BASE_DIR = \"/mnt/data-ssd-1/data/private/customer/speechly/2022-09-23_gymclass_40h/raw_data\"\n",
    "AUDIO_DIR = os.path.join(BASE_DIR, \"audio\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6417ef3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11105 files found\n",
      "11105 wav files found\n",
      "40.0 hours\n"
     ]
    }
   ],
   "source": [
    "tmp_fns = os.listdir(AUDIO_DIR)\n",
    "print(len(tmp_fns), \"files found\")\n",
    "fns = [fn for fn in tmp_fns if fn.endswith(\".wav\")]\n",
    "print(len(fns), \"wav files found\")\n",
    "fps = [os.path.join(AUDIO_DIR, fn) for fn in fns]\n",
    "durations_s = [Audio.get_details(fp, attempt_using_header=True)[\"duration_s\"] for fp in fps]\n",
    "print(round(np.sum(durations_s) / 60 / 60, 1), \"hours\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "dc07530a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11105 transcripts\n"
     ]
    }
   ],
   "source": [
    "with open(os.path.join(BASE_DIR, \"transcripts.tsv\")) as f:\n",
    "    transcripts = [e.split(\"\\t\") for e in f.read().strip().split(\"\\n\")]\n",
    "assert(all([len(e) == 2 for e in transcripts]))\n",
    "transcripts = [(uid, text.lower()) for uid, text in transcripts]\n",
    "print(len(transcripts), \"transcripts\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "cec744a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('09e56ba8-49c6-4301-802a-13a9d25d56aa', 'ohh fuck bro had a bounce'),\n",
       " ('081b33a7-128f-46f3-a40b-e83114bc8752',\n",
       "  \"bro i snatch blocked him bro what the fuck no god this game is so delayed with that stuff it's not hate socially\"),\n",
       " ('03fb152e-e401-4073-8ad7-45dbb02392b8',\n",
       "  'ooh dang cook butter cheese cook potato cheese')]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transcripts[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "131739c9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c3fb7cc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb4a5c0f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bfb03b0c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eaa5862a",
   "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
