{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n#         print(os.path.join(dirname, filename))\n        pass\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-14T20:18:06.666635Z","iopub.execute_input":"2023-03-14T20:18:06.667141Z","iopub.status.idle":"2023-03-14T20:18:06.903748Z","shell.execute_reply.started":"2023-03-14T20:18:06.667097Z","shell.execute_reply":"2023-03-14T20:18:06.902281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The competition is about idnetifying which birds are calling in long recordings made in Kenya. The could be helpful to monitor bird population.\n\nSo the goal of the competition is to identify Eastern African bird species by sound.","metadata":{}},{"cell_type":"markdown","source":"* # Dataset Overview\n\n* `train_audio\\` - directory which contains short recordings of individual bird calls\n* `test_soundscapes\\` - directory which contains recordings to be usedd for testing..\n\n* `train_metadata.csv` - wide range of metadata for the training data.\n    * `primary_label` - a code for the bird species\n    * `latitude & longitude` - coordinates for where the recordings was taken. Some birds may have local call (dialects), hence we can search geographic diversity in training data\n    * `author` - the user who provided the recording\n    * `filename` - the name of the associated audio file","metadata":{}},{"cell_type":"markdown","source":"Let's import necessary libraries and color palettes for visualization purposes.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pylab as plt\nimport seaborn as sns\nfrom glob import glob # we can file structure and access on to them\n\n# Audio processing libs\nimport librosa\nimport librosa.display\nimport IPython.display as ipd\n\n# Color palettes\nfrom itertools import cycle\n\nsns.set_theme(style='white', palette=None)\ncolor_pal = plt.rcParams['axes.prop_cycle'].by_key()['color']\ncolor_cycle = cycle(plt.rcParams['axes.prop_cycle'].by_key()['color'])","metadata":{"execution":{"iopub.status.busy":"2023-03-14T20:42:05.207869Z","iopub.execute_input":"2023-03-14T20:42:05.208453Z","iopub.status.idle":"2023-03-14T20:42:05.492620Z","shell.execute_reply.started":"2023-03-14T20:42:05.208407Z","shell.execute_reply":"2023-03-14T20:42:05.491486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Terms to Know...\n\n - The sounda are just basically waves...\n - Each wave / signal can be described in waveform, which means in terms of frequency and amplitude.\n\n### Frequency \n- Describes the difference of wave lengths, in other words the `pitch` of a sound.\n- (Hz) is unit of measure.\n\n<img src=\"https://uploads-cdn.omnicalculator.com/images/britannica-wave-frequency.jpg\" width=\"400\"/>\n\n\n### Intensity / Amplitude\n- Describes the height of the wave, in other words the loudness of the sound.\n\n<img src=\"https://ars.els-cdn.com/content/image/3-s2.0-B9780124722804500162-f13-15-9780124722804.gif\" width=\"400\"/>\n\n### Sample Rate\n- We need to fed the audio as an input to the computer. So the signal needs to be sampled called discritization.\n- The rate at which the signal is sampled called sampling rate.\n- Simply resolution of the wave / signal, higher the sample rate, more quality is the digitized wave.\n\n<img src=\"https://www.headphonesty.com/wp-content/uploads/2019/07/Sample-Rate-Bit-Depth-and-Bit-Rate.jpeg\" width=\"400\"/>\n\n### The Fourier Transform\n- The Fourier transform is a mathematical formula that allows us to decompose a signal into it’s individual frequencies and the frequency’s amplitude. In other words, it converts the signal from the time domain into the frequency domain. The result is called a spectrum.\n\n<img src=\"https://miro.medium.com/v2/resize:fit:1100/format:webp/1*xTYCtcx_7otHVu-uToI9dA.png\" width=\"400\"/>\n\n- The fast Fourier transform (FFT) is an algorithm that can efficiently compute the Fourier transform. It is widely used in signal processing.\n\n- check this [article](https://medium.com/analytics-vidhya/understanding-the-mel-spectrogram-fca2afa2ce53) for more information.","metadata":{}},{"cell_type":"markdown","source":"## Reading audio files","metadata":{}},{"cell_type":"code","source":"train_audio = glob('/kaggle/input/birdclef-2023/train_audio/*/*.ogg')\ntest_audio = glob('/kaggle/input/birdclef-2023/test_soundscapes/soundscape_29201.ogg')","metadata":{"execution":{"iopub.status.busy":"2023-03-14T21:28:21.842182Z","iopub.execute_input":"2023-03-14T21:28:21.842673Z","iopub.status.idle":"2023-03-14T21:28:22.043468Z","shell.execute_reply.started":"2023-03-14T21:28:21.842631Z","shell.execute_reply":"2023-03-14T21:28:22.042415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Play the an audio file\nipd.Audio(train_audio[0])","metadata":{"execution":{"iopub.status.busy":"2023-03-14T21:29:01.691666Z","iopub.execute_input":"2023-03-14T21:29:01.692189Z","iopub.status.idle":"2023-03-14T21:29:01.711493Z","shell.execute_reply.started":"2023-03-14T21:29:01.692145Z","shell.execute_reply":"2023-03-14T21:29:01.710162Z"},"trusted":true},"execution_count":null,"outputs":[]}]}