{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"\n<b><font size = 2><span style=\"font-family:'Times New Roman';color:#03045e\">🐤EDA|🐦Visualizations + Audio Exploration 🔉🔉 </span></font></b>  \n\n<b><font size = 2><span style=\"font-family:'Times New Roman';color:#03045e;\">Created By Burhanuddin Latsaheb </span></font> </b> \n\n\n\n#  <center><font size = 8><span style=\"color:#0077b6;font-family:'Times New Roman'\">🐤EDA|🐦Visualizations + Audio Exploration 🔉🔉</span></font></center>\n\n\n <center><font size =4><span style=\"font-family:'Times New Roman';color:#03045e\"> If you find this notebook useful,support with an upvote👍👍 </span></font></center>\n","metadata":{}},{"cell_type":"markdown","source":"#  <center><font size = 3><span style=\"color:#38a3a5\"> <p style=\"background-color:#90e0ef;font-family:newtimeroman;color:#03045e;font-size:200%;text-align:center;border-radius:100px 10px;\">INTRODUCTION</p>   </span></font></center>\n \n<font size = 5><span style=\"color:#202833;font-family:'Times New Roman'\">Notebook Overview : </span></font>\n\n<!-- * <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\"> This notebook contains:  </span></font> -->\n1. <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">An  extensive <b>EDA</b> of the different Bird sounds and its different characteristics   </span></font>\n2. <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">The goal of this competition is to use machine learning to <b>identify Eastern African bird species by sound</b>.</span></font>\n\n\n<font size = 5><span style=\"color:#202833;font-family:'Times New Roman'\">Introduction to the BirdCLEF 2023 Competition:</span></font>\n\n\n<font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Birds are not only fascinating creatures, but also an important indicator of the health of our environment. The BirdCLEF 2023 competition, hosted by Kaggle, aims to promote research and innovation in the field of bird species identification through acoustic signals.   </span></font>\n\n<font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">\nIn this competition, participants are challenged to develop algorithms that can accurately identify bird species from audio recordings. The dataset consists of over 1 million audio recordings from around the world, with a total duration of over 1,000 hours. Each recording is labeled with the corresponding bird species, and participants are tasked with developing a machine learning model that can accurately classify the species in new, unseen recordings.</span></font>\n\n<font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">\nThe BirdCLEF 2023 competition provides a unique opportunity for researchers and data scientists to advance the field of bioacoustics and contribute to the preservation of bird populations around the world. Whether you are an experienced machine learning practitioner or just getting started, this competition offers a challenging and rewarding opportunity to make a real-world impact.</span></font>","metadata":{}},{"cell_type":"markdown","source":"<a id='top'></a>\n#  <center><font size = 3><span style=\"color:#38a3a5\"> <p style=\"background-color:#90e0ef;font-family:newtimeroman;color:#03045e;font-size:200%;text-align:center;border-radius:100px 10px;\">TABLE OF CONTENTS</p>   </span></font></center>\n- [1. Imports 📂](#1)\n- [2. EDA 📊](#2)\n    * [Train Meta Data Info](#2.1)\n    * [Plots](#2.2)\n    * [Correlation Plots](#2.4)\n    * [Interactive Map Plots](#2.3)\n       * [Scatter Plot](#2.3.1)\n       * [Map Box (Open Street Map)](#2.3.2)\n       * [Map Box(Terrain View)](#2.3.3)\n    * [EBird Taxonomy](#2.5)\n- [3. AUDIO EXPLORATION 🔉🔉](#3)\n    * [Helper Function](#3.1)\n    * [Audio Exploration](#3.2)\n        * [Black-and-white Mannikin](#3.2.1)\n        * [African Black-headed Oriole](#3.2.2)\n        * [African Bare-eyed Thrush](#3.2.3)\n        * [African Gray Flycatcher](#3.2.4)\n        * [African Goshawk](#3.2.5)\n","metadata":{}},{"cell_type":"markdown","source":"<a id='1'></a>\n#  <center><font size = 3><span style=\"color:#a8dadc\"> <p style=\"background-color:#90e0ef;font-family:newtimeroman;color:#03045e;font-size:200%;text-align:center;border-radius:100px 10px;\">1. IMPORTS📂 </p>   </span></font></center>\n\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"import ast\nimport librosa\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport plotly.express as px\nimport plotly.graph_objs as go\nfrom collections import Counter\nimport matplotlib.pyplot as plt\nfrom IPython.display import Audio","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-08T07:38:11.474081Z","iopub.execute_input":"2023-03-08T07:38:11.475760Z","iopub.status.idle":"2023-03-08T07:38:11.483747Z","shell.execute_reply.started":"2023-03-08T07:38:11.475672Z","shell.execute_reply":"2023-03-08T07:38:11.482087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='2'></a>\n#  <center><font size = 3><span style=\"color:#a8dadc\">  <p style=\"background-color:#90e0ef;font-family:newtimeroman;color:#03045e;font-size:200%;text-align:center;border-radius:100px 10px;\">2. 📊EDA 📊 </p>   </span></font></center>\n\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-info\" style=\"font-size:14px; font-family:verdana; line-height: 1.7em;\">\n     💡 &nbsp;<b><u>Observations in Train Meta Data:</u></b><br>\n * <i> There are total of <b><u>12</u></b> columns and <b><u>16941</u></b> rows in <b><u>train meta</u></b> data.</i><br>\n* <i> Train data contains <b><u>16941</u></b> values with <b><u>454(0.2%)</u></b> of  missing values.</i><br>\n* <i></i>There are total of <b><u>12</u></b> columns : <b><u>3</u></b> numerical , <b><u>9</u></b> categorical<br>\n* <i> <b><u>454 Missing </u></b> values in the <b><u>train meta</u></b> data.</i><br>\n</div>","metadata":{}},{"cell_type":"code","source":"trainmeta_df = pd.read_csv(\"/kaggle/input/birdclef-2023/train_metadata.csv\")\ntrainmeta_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:12:44.446156Z","iopub.execute_input":"2023-03-08T07:12:44.446528Z","iopub.status.idle":"2023-03-08T07:12:44.550205Z","shell.execute_reply.started":"2023-03-08T07:12:44.446493Z","shell.execute_reply":"2023-03-08T07:12:44.548730Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = trainmeta_df[trainmeta_df[\"primary_label\"] == \"afgfly1\"]\nx","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.1\"></a>\n<p style=\"background-color:#03045e;font-family:newtimeroman;color:#90e0ef;font-size:140%;text-align:center;border-radius:200px 10px;\">Train Meta Data Info</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-info\" style=\"font-size:14px; font-family:verdana; line-height: 1.7em;\">\n     💡💡 &nbsp;<b><u>Further Insights of train dataset</u></b><br>\n    * <i> <b><u>Latitude </u></b> &  <b><u>Longitude</u></b> have  <b>227(1.34%) Missing Values</b></i><br>\n    * <i> <b><u>Longitude</u></b> & <b><u>Rating</u></b> are <b><u>skewed</u></b></i><br>\n    * <i> <b><u>Primary labels</u></b> , <b><u>Secondary Labels</u></b> , <b><u>Type</u></b> , <b><u>Scientific Name</u></b> , <b><u>Common Name</u></b> , <b><u>Author</u></b> ,<b><u>Filename</u></b> have  <b><u>high Cardinality</u></b></i><br>\n</div>\n","metadata":{}},{"cell_type":"code","source":"print(trainmeta_df.info())","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-03-08T07:19:11.142989Z","iopub.execute_input":"2023-03-08T07:19:11.143739Z","iopub.status.idle":"2023-03-08T07:19:11.172209Z","shell.execute_reply.started":"2023-03-08T07:19:11.143649Z","shell.execute_reply":"2023-03-08T07:19:11.170642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.2\"></a>\n<p style=\"background-color:#03045e;font-family:newtimeroman;color:#90e0ef;font-size:140%;text-align:center;border-radius:200px 10px;\">Plots</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"fig = px.histogram(trainmeta_df, x=\"primary_label\", nbins=len(trainmeta_df[\"primary_label\"].unique()))\nfig.update_layout(title_text=\"Distribution of Primary Labels\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:27:10.229488Z","iopub.execute_input":"2023-03-08T07:27:10.230588Z","iopub.status.idle":"2023-03-08T07:27:10.800684Z","shell.execute_reply.started":"2023-03-08T07:27:10.230527Z","shell.execute_reply":"2023-03-08T07:27:10.799352Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"secondary_df = trainmeta_df['secondary_labels'].str.replace('[','').str.replace(']','').str.replace('\\'','').str.split(',', expand=True).stack().reset_index(level=1, drop=True).rename('secondary_label')\nsecondary_df = pd.merge(trainmeta_df.drop(columns=['secondary_labels']), secondary_df, left_index=True, right_index=True)\n\nfig = px.histogram(secondary_df, x=\"secondary_label\", title=\"Distribution of Secondary Labels\")\nfig.update_layout(xaxis_title=\"Secondary Label\", yaxis_title=\"Count\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:27:18.922302Z","iopub.execute_input":"2023-03-08T07:27:18.922782Z","iopub.status.idle":"2023-03-08T07:27:19.135530Z","shell.execute_reply.started":"2023-03-08T07:27:18.922741Z","shell.execute_reply":"2023-03-08T07:27:19.134342Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Flatten the list of labels in the \"type\" column\nlabels = [label.strip(\"[]'\") for sublist in trainmeta_df['type'].apply(ast.literal_eval) for label in sublist]\n\n# Count the occurrence of each label\nlabel_counts = Counter(labels)\n\n# Create a bar plot of the label counts\nfig = px.bar(x=list(label_counts.keys()), y=list(label_counts.values()))\nfig.update_layout(title_text=\"Distribution of Types\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:27:26.129399Z","iopub.execute_input":"2023-03-08T07:27:26.129932Z","iopub.status.idle":"2023-03-08T07:27:26.352224Z","shell.execute_reply.started":"2023-03-08T07:27:26.129885Z","shell.execute_reply":"2023-03-08T07:27:26.350862Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig1 = px.box(trainmeta_df, y=\"latitude\")\nfig1.update_layout(title_text=\"Distribution of Latitude\",\n                   yaxis=dict(title=\"Latitude\"))\n\n# create a box plot for longitude\nfig2 = px.box(trainmeta_df, y=\"longitude\")\nfig2.update_layout(title_text=\"Distribution of Longitude\",\n                   yaxis=dict(title=\"Longitude\"))\n\n# create a box plot for rating\nfig3 = px.box(trainmeta_df, y=\"rating\")\nfig3.update_layout(title_text=\"Distribution of Ratings\",\n                   yaxis=dict(title=\"Rating\"))\n\n# show the figures\nfig1.show()\nfig2.show()\nfig3.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:27:33.012501Z","iopub.execute_input":"2023-03-08T07:27:33.013248Z","iopub.status.idle":"2023-03-08T07:27:33.195810Z","shell.execute_reply.started":"2023-03-08T07:27:33.013197Z","shell.execute_reply":"2023-03-08T07:27:33.194441Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(trainmeta_df, x=\"scientific_name\", nbins=len(trainmeta_df[\"scientific_name\"].unique()))\nfig.update_layout(title_text=\"Distribution of Scientific Names\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:27:43.370548Z","iopub.execute_input":"2023-03-08T07:27:43.370996Z","iopub.status.idle":"2023-03-08T07:27:43.504732Z","shell.execute_reply.started":"2023-03-08T07:27:43.370959Z","shell.execute_reply":"2023-03-08T07:27:43.503438Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfig = px.histogram(trainmeta_df, x=\"common_name\", nbins=len(trainmeta_df[\"common_name\"].unique()))\nfig.update_layout(title_text=\"Distribution of Common Names\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:27:53.932176Z","iopub.execute_input":"2023-03-08T07:27:53.933390Z","iopub.status.idle":"2023-03-08T07:27:54.064382Z","shell.execute_reply.started":"2023-03-08T07:27:53.933320Z","shell.execute_reply":"2023-03-08T07:27:54.063321Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(trainmeta_df, x=\"author\", nbins=len(trainmeta_df[\"author\"].unique()))\nfig.update_layout(title_text=\"Distribution of Authors\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:27:58.591349Z","iopub.execute_input":"2023-03-08T07:27:58.591923Z","iopub.status.idle":"2023-03-08T07:27:58.728538Z","shell.execute_reply.started":"2023-03-08T07:27:58.591875Z","shell.execute_reply":"2023-03-08T07:27:58.726863Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfig = px.histogram(trainmeta_df, x=\"rating\", nbins=len(trainmeta_df[\"rating\"].unique()) , color_discrete_sequence=['red'])\nfig.update_layout(title_text=\"Distribution of Ratings\")\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-03-08T07:28:12.587433Z","iopub.execute_input":"2023-03-08T07:28:12.587962Z","iopub.status.idle":"2023-03-08T07:28:12.662569Z","shell.execute_reply.started":"2023-03-08T07:28:12.587895Z","shell.execute_reply":"2023-03-08T07:28:12.661151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.4\"></a>\n<p style=\"background-color:#03045e;font-family:newtimeroman;color:#90e0ef;font-size:140%;text-align:center;border-radius:200px 10px;\">Correlation Plots</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"# drop columns from correlation matrix\ncorr = trainmeta_df.corr()\n\n# create correlation heatmap\nfig = px.imshow(corr,\n                labels=dict(x=\"Columns\", y=\"Columns\", color=\"Correlation\"),\n                x=corr.columns,\n                y=corr.columns,\n                color_continuous_scale='RdBU',\n                zmin=-1,\n                zmax=1,\n                title=\"Correlation Heatmap\")\n                \n# add text annotations\nannotations = []\nfor i, row in enumerate(corr.values):\n    for j, value in enumerate(row):\n        text = '{:.2f}'.format(value)\n        annotations.append(dict(x=corr.columns[j], y=corr.columns[i], text=text, showarrow=False))\n\nfig.update_layout(width=800, height=800)\nfig.update_traces(showscale=True, colorbar_thickness=25, colorbar_len=0.75)\nfig.update_layout(margin=dict(l=50, r=50, b=100, t=100, pad=4))\nfig.update_layout(annotations=annotations)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:33:31.960194Z","iopub.execute_input":"2023-03-08T07:33:31.962165Z","iopub.status.idle":"2023-03-08T07:33:32.044251Z","shell.execute_reply.started":"2023-03-08T07:33:31.962092Z","shell.execute_reply":"2023-03-08T07:33:32.042974Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.3\"></a>\n<p style=\"background-color:#03045e;font-family:newtimeroman;color:#90e0ef;font-size:140%;text-align:center;border-radius:200px 10px;\">Interactive Map Plots</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"2.3.1\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">Scatter Plot</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(trainmeta_df, x=\"longitude\", y=\"latitude\", color=\"common_name\")\nfig.update_layout(title=\"Distribution of Recordings by Location\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:28:18.340465Z","iopub.execute_input":"2023-03-08T07:28:18.340985Z","iopub.status.idle":"2023-03-08T07:28:19.328002Z","shell.execute_reply.started":"2023-03-08T07:28:18.340938Z","shell.execute_reply":"2023-03-08T07:28:19.326674Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.3.2\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">Map Box (Open Street Map)</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"fig = px.scatter_mapbox(trainmeta_df, lat=\"latitude\", lon=\"longitude\", color=\"common_name\",\n                        hover_name=\"filename\", hover_data=[\"common_name\", \"author\", \"rating\"],\n                        zoom=3, height=500)\nfig.update_layout(mapbox_style=\"open-street-map\")\nfig.update_layout(margin={\"r\":0,\"t\":0,\"l\":0,\"b\":0})\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:30:36.116688Z","iopub.execute_input":"2023-03-08T07:30:36.118072Z","iopub.status.idle":"2023-03-08T07:30:37.787289Z","shell.execute_reply.started":"2023-03-08T07:30:36.117987Z","shell.execute_reply":"2023-03-08T07:30:37.785133Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.3.3\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">Map Box(Terrain View)</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"fig = px.density_mapbox(trainmeta_df, lat='latitude', lon='longitude', radius=10,\n                        center=dict(lat=47.6, lon=-122.3), zoom=7,\n                        mapbox_style=\"stamen-terrain\")\nfig.update_layout(title_text=\"Distribution of Bird Sightings\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:32:23.049884Z","iopub.execute_input":"2023-03-08T07:32:23.050337Z","iopub.status.idle":"2023-03-08T07:32:23.128009Z","shell.execute_reply.started":"2023-03-08T07:32:23.050299Z","shell.execute_reply":"2023-03-08T07:32:23.126718Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.5\"></a>\n<p style=\"background-color:#03045e;font-family:newtimeroman;color:#90e0ef;font-size:140%;text-align:center;border-radius:200px 10px;\">EBird Taxonomy</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"train_species_df = pd.read_csv(\"/kaggle/input/birdclef-2023/eBird_Taxonomy_v2021.csv\")\ntrain_species_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:37:43.882566Z","iopub.execute_input":"2023-03-08T07:37:43.883006Z","iopub.status.idle":"2023-03-08T07:37:43.952049Z","shell.execute_reply.started":"2023-03-08T07:37:43.882962Z","shell.execute_reply":"2023-03-08T07:37:43.951063Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Histogram of the taxonomic order counts\nfig1 = px.histogram(train_species_df, x=\"TAXON_ORDER\", color_discrete_sequence=['aquamarine'])\nfig1.update_layout(title_text=\"Distribution of Taxonomic Orders\")\n\n# Bar plot of the species group counts\n# Box plot of the taxonomic order counts by category\nfig3 = px.box(train_species_df, x=\"CATEGORY\", y=\"TAXON_ORDER\", color_discrete_sequence=['red'])\nfig3.update_layout(title_text=\"Taxonomic Order Distribution by Category\")\n\n# Scatter plot of the taxonomic order counts by family\nfig4 = px.scatter(train_species_df, x=\"FAMILY\", y=\"TAXON_ORDER\")\nfig4.update_layout(title_text=\"Taxonomic Order Distribution by Family\")\n\n# Show the plots\nfig1.show()\nfig3.show()\nfig4.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-03-08T07:38:22.185201Z","iopub.execute_input":"2023-03-08T07:38:22.185634Z","iopub.status.idle":"2023-03-08T07:38:22.501009Z","shell.execute_reply.started":"2023-03-08T07:38:22.185598Z","shell.execute_reply":"2023-03-08T07:38:22.499807Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='3'></a>\n#  <center><font size = 3><span style=\"color:#a8dadc\">  <p style=\"background-color:#90e0ef;font-family:newtimeroman;color:#03045e;font-size:200%;text-align:center;border-radius:100px 10px;\">3. AUDIO EXPLORATION 🔉🔉 </p>   </span></font></center>\n\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"markdown","source":"<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Audio Files :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">An audio file is a type of digital file format that stores recorded sound or music. It can be played back through speakers or headphones and is commonly used in a variety of applications, such as music, film, television, radio, and other forms of media. Audio files come in many different formats, including <b>MP3, WAV, OGG, AAC, and FLAC.</b></span></font><br>\n\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> How to Visualize Audio Files ?? </b></span></font><br>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> There are many ways in which we can view audio in 2D like : </b></span></font>\n\n1. <font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Waveforms :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">In audio processing, a waveform is a graphical representation of a sound signal that shows how the signal varies over time. It is a plot of the amplitude of the sound wave on the y-axis versus time on the x-axis. Waveforms can be used to visualize and analyze the properties of audio signals, such as frequency, amplitude, phase, and duration.</span></font><br>\n<img src =https://t4.ftcdn.net/jpg/03/27/36/95/360_F_327369570_CAxxxHHLvjk6IJ3wGi1kuW6WTtqjaMpc.jpg>\n\n2. <font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Spectograms :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">A spectrogram is a visual representation of the spectrum of frequencies of a sound or other signal as it varies with time. It is a way of analyzing the sound signal to understand how the signal changes over time and what frequencies are present in the signal at any given point in time. The x-axis of a spectrogram represents time, while the y-axis represents frequency. The intensity of the color or brightness of each point in the spectrogram represents the amplitude or energy of the frequency at that point in time.</span></font><br>\n<img src = https://i.stack.imgur.com/styEs.png>\n3. <font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b>  Mel Spectograms :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Mel spectrograms are a type of spectrogram that use the Mel scale to determine the spacing of frequency bins. The Mel scale is a perceptual scale of pitches judged by listeners to be equal in distance from one another. By using the Mel scale, the frequency bins are spaced closer together at lower frequencies and farther apart at higher frequencies, which better matches the way humans perceive sound.</span></font><br>\n<img src =https://i.stack.imgur.com/8j108.png>\n4. <font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Chromagram :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">A chromagram is a visual representation of the pitch content of an audio signal, where each column corresponds to a particular frequency band or pitch class. It is a 2D representation of the distribution of energy in a sound, plotted as a function of time and pitch class.The chromagram is calculated by taking the short-time Fourier transform (STFT) of the audio signal and projecting the resulting spectrogram onto a pitch-class basis, typically using a bank of 12 log-spaced filters to represent the 12 pitch classes of the Western musical scale</span></font><br>\n<img src = https://www.researchgate.net/profile/Giovanni-De-Poli/publication/265404164/figure/fig7/AS:295785980809229@1447532281700/Chromagram-of-a-framed-signal.png>\n\n5. <font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> MFCC :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">MFCC stands for Mel Frequency Cepstral Coefficients, which is a feature extraction technique commonly used in speech processing, music information retrieval, and other related fields.MFCCs are derived from a short-time Fourier transform (STFT) of the audio signal, which involves breaking the signal down into small, overlapping segments and performing a Fourier transform on each segment to obtain its frequency spectrum. The Mel scale is then applied to the frequency spectrum to transform it into a logarithmic scale that approximates the human auditory system's perception of sound.</span></font><br>\n<img src =https://i.stack.imgur.com/nvBcU.png>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"3.1\"></a>\n<p style=\"background-color:#03045e;font-family:newtimeroman;color:#90e0ef;font-size:140%;text-align:center;border-radius:200px 10px;\">Helper Function</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"code","source":"def audio_eda(audio_path):\n   \n    # Load an audio file\n    samples, sample_rate = librosa.load(audio_path)\n\n    # Visualize the waveform\n    plt.figure(figsize=(14, 5))\n    librosa.display.waveshow(samples, sr=sample_rate)\n    plt.title('Waveform')\n\n    # Compute the spectrogram\n    spectrogram = librosa.stft(samples)\n    spectrogram_db = librosa.amplitude_to_db(abs(spectrogram))\n\n    # Visualize the spectrogram\n    plt.figure(figsize=(14, 5))\n    librosa.display.specshow(spectrogram_db, sr=sample_rate, x_axis='time', y_axis='log')\n    plt.colorbar(format='%+2.0f dB')\n    plt.title('Spectrogram (dB)')\n\n    # Compute the mel spectrogram\n\n\n    # Visualize the mel spectrogram\n    S = librosa.feature.melspectrogram(y=samples, sr=sample_rate)\n\n    # Visualize mel spectrogram\n    plt.figure(figsize=(10, 4))\n    librosa.display.specshow(librosa.power_to_db(S, ref=np.max), y_axis='mel', fmax=8000, x_axis='time')\n    plt.colorbar(format='%+2.0f dB')\n    plt.title('Mel spectrogram')\n    plt.tight_layout()\n\n\n    # Compute the chromagram\n    chromagram = librosa.feature.chroma_stft( y = samples , sr = sample_rate)\n\n    # Visualize the chromagram\n    plt.figure(figsize=(14, 5))\n    librosa.display.specshow(chromagram, sr=sample_rate, x_axis='time', y_axis='chroma')\n    plt.colorbar()\n    plt.title('Chromagram')\n\n    # Compute the MFCCs\n    mfccs = librosa.feature.mfcc(y=samples, sr=sample_rate, n_mfcc=13)\n\n    # Visualize the MFCCs\n    plt.figure(figsize=(14, 5))\n    librosa.display.specshow(mfccs, sr=sample_rate, x_axis='time')\n    plt.colorbar()\n    plt.title('MFCCs')\n\n    # Show the plots\n    display(Audio(samples, rate=sample_rate))\n    plt.show()","metadata":{"_kg_hide-input":false,"execution":{"iopub.status.busy":"2023-03-08T08:02:19.274177Z","iopub.execute_input":"2023-03-08T08:02:19.275850Z","iopub.status.idle":"2023-03-08T08:02:19.289095Z","shell.execute_reply.started":"2023-03-08T08:02:19.275797Z","shell.execute_reply":"2023-03-08T08:02:19.287815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3.2\"></a>\n<p style=\"background-color:#03045e;font-family:newtimeroman;color:#90e0ef;font-size:140%;text-align:center;border-radius:200px 10px;\">Audio Exploration</p>\n\n#### [Top ↑](#top)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"3.2.1\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">Black-and-white Mannikin</p>\n<img src = https://cdn.download.ams.birds.cornell.edu/api/v1/asset/212028741/1200>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Primary Label :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">bawman1</span></font><br>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Scientific Name :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Spermestes bicolor</span></font><br>\n\n#### [Top ↑](#top)\n","metadata":{}},{"cell_type":"code","source":"audio_eda(\"/kaggle/input/birdclef-2023/train_audio/bawman1/XC115075.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:02:20.350192Z","iopub.execute_input":"2023-03-08T08:02:20.350697Z","iopub.status.idle":"2023-03-08T08:02:25.664783Z","shell.execute_reply.started":"2023-03-08T08:02:20.350629Z","shell.execute_reply":"2023-03-08T08:02:25.663507Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3.2.2\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">African Black-headed Oriole</p>\n<img src = https://cdn.download.ams.birds.cornell.edu/api/v1/asset/183432491/1200>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Primary Label :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">abhori1</span></font><br>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Scientific Name :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Oriolus larvatus</span></font><br>\n\n#### [Top ↑](#top)\n\n\n","metadata":{}},{"cell_type":"code","source":"audio_eda(\"/kaggle/input/birdclef-2023/train_audio/abhori1/XC120251.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:14:52.241546Z","iopub.execute_input":"2023-03-08T08:14:52.242091Z","iopub.status.idle":"2023-03-08T08:14:57.766108Z","shell.execute_reply.started":"2023-03-08T08:14:52.242048Z","shell.execute_reply":"2023-03-08T08:14:57.764896Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3.2.3\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">African Bare-eyed Thrush</p>\n<img src = https://cdn.download.ams.birds.cornell.edu/api/v1/asset/247097231/1200>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Primary Label :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">abethr1</span></font><br>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Scientific Name :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Turdus tephronotus</span></font><br>\n\n#### [Top ↑](#top)\n","metadata":{}},{"cell_type":"code","source":"audio_eda(\"/kaggle/input/birdclef-2023/train_audio/abethr1/XC128013.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:17:17.536886Z","iopub.execute_input":"2023-03-08T08:17:17.537364Z","iopub.status.idle":"2023-03-08T08:17:21.542035Z","shell.execute_reply.started":"2023-03-08T08:17:17.537326Z","shell.execute_reply":"2023-03-08T08:17:21.540716Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3.2.4\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">African Gray Flycatcher</p>\n<img src = https://cdn.download.ams.birds.cornell.edu/api/v1/asset/247103901/1200>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Primary Label :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">afgfly1</span></font><br>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Scientific Name :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Bradornis microrhynchus</span></font><br>\n\n#### [Top ↑](#top)\n","metadata":{}},{"cell_type":"code","source":"audio_eda(\"/kaggle/input/birdclef-2023/train_audio/afgfly1/XC134487.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:21:00.509819Z","iopub.execute_input":"2023-03-08T08:21:00.510226Z","iopub.status.idle":"2023-03-08T08:21:03.054197Z","shell.execute_reply.started":"2023-03-08T08:21:00.510192Z","shell.execute_reply":"2023-03-08T08:21:03.052744Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3.2.5\"></a>\n<p style=\"background-color:#f0f3bd;font-family:newtimeroman;color:#05668d;font-size:140%;text-align:center;border-radius:200px 10px;\">African Goshawk</p>\n<img src = https://live.staticflickr.com/2950/15449835341_c4ee7ea96a_b.jpg>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Primary Label :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">afrgos1</span></font><br>\n\n<font size = 4><span style=\"color:#3A3E59;font-family:'Times New Roman'\"><b> Scientific Name :</b></span></font> <font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Accipiter tachiro</span></font><br>\n\n#### [Top ↑](#top)\n","metadata":{}},{"cell_type":"code","source":"audio_eda(\"/kaggle/input/birdclef-2023/train_audio/afrgos1/XC115984.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:26:28.777924Z","iopub.execute_input":"2023-03-08T08:26:28.778364Z","iopub.status.idle":"2023-03-08T08:26:32.453977Z","shell.execute_reply.started":"2023-03-08T08:26:28.778321Z","shell.execute_reply":"2023-03-08T08:26:32.452728Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n<center>\n<b><font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Thank You for reading 😊  </span></font></b><br>\n<b><font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">Please do upvote if you liked the notebook   </span></font></b><br>\n<b><font size = 3><span style=\"color:#3A3E59;font-family:'Times New Roman'\">If you have any suggestions or feeback, please let me know  </span></font></b><br>\n  </center>","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}