{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2a61d194",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21f27189",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "sys.path.insert(0, os.path.dirname(os.path.abspath(\"\")))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "218fcdf1",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Audio\n",
    "from audiodiffusion.mel import Mel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e4f8ee5",
   "metadata": {},
   "outputs": [],
   "source": [
    "mel = Mel()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2178c3f",
   "metadata": {},
   "source": [
    "### Transform slice of audio to mel spectrogram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61dbcd2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "mel.load_audio('/home/teticio/Music/Music/A Tribe Called Quest/The Anthology/08 Can I Kick It_.mp3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ccadcc0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "image = mel.audio_slice_to_image(15)\n",
    "image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cec79c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "image.width, image.height"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe112fef",
   "metadata": {},
   "source": [
    "### Transform mel spectrogram back to audio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b268a54",
   "metadata": {},
   "outputs": [],
   "source": [
    "audio = mel.image_to_audio(image)\n",
    "Audio(data=audio, rate=mel.get_sample_rate())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0dffbc4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "huggingface",
   "language": "python",
   "name": "huggingface"
  },
  "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.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}