{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "70038f5c-6473-42df-b070-c658dd1ee0cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://www.pythonpool.com/spectrogram-python/\n",
    "import os\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "import librosa\n",
    "import librosa.display\n",
    " \n",
    "import IPython.display as ipd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "93ad2e79-1b8d-42ce-9ca5-a85b8e07a4ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "audio = '611.wav'\n",
    "x, sr = librosa.load(audio, sr=44100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e14b44c6-14bb-4465-b6ad-0c291907ba96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<librosa.display.AdaptiveWaveplot at 0x16db416c510>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 65784 characters]",
      "text/plain": [
       "<Figure size 1400x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# https://stackoverflow.com/questions/75799092/librosa-error-attributeerror-module-librosa-display-has-no-attribute-wave\n",
    "plt.figure(figsize=(14, 5))\n",
    "librosa.display.waveshow(x, sr=sr) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "657390ef-a09e-487e-93c4-b47a305fb55a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x16dbe8c4310>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 946784 characters]",
      "text/plain": [
       "<Figure size 1400x500 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "X = librosa.stft(x)\n",
    "Xdb = librosa.amplitude_to_db(abs(X))\n",
    "plt.figure(figsize=(14, 5))\n",
    "librosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')\n",
    "plt.colorbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fbed760a-dc27-46aa-a43d-80ea264b8782",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<librosa.display.AdaptiveWaveplot at 0x16dc682fcd0>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 65892 characters]",
      "text/plain": [
       "<Figure size 1400x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "audio1 = '611wm.wav'\n",
    "x1, sr1 = librosa.load(audio1, sr=44100)\n",
    "plt.figure(figsize=(14, 5))\n",
    "librosa.display.waveshow(x1, sr=sr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c51c8c22-7d25-4985-b3f6-c9d18543d749",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x16dcab25850>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 946804 characters]",
      "text/plain": [
       "<Figure size 1400x500 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "X1 = librosa.stft(x1)\n",
    "Xdb1 = librosa.amplitude_to_db(abs(X1))\n",
    "plt.figure(figsize=(14, 5))\n",
    "librosa.display.specshow(Xdb1, sr=sr1, x_axis='time', y_axis='hz')\n",
    "plt.colorbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ffdb1db6-a1f9-453a-87eb-c1bd59b7b9ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<librosa.display.AdaptiveWaveplot at 0x16dcab4fcd0>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 15064 characters]",
      "text/plain": [
       "<Figure size 1400x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(14, 5))\n",
    "librosa.display.waveshow(x1-x, sr=sr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "fd2aeb69-d2c9-45d0-8d5a-c435059836eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x16dcb13fd10>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 34620 characters]",
      "text/plain": [
       "<Figure size 1400x500 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(14, 5))\n",
    "librosa.display.specshow(Xdb1-Xdb, sr=sr1, x_axis='time', y_axis='hz')\n",
    "plt.colorbar()"
   ]
  }
 ],
 "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.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
