{"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)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')\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\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":"2022-03-13T23:19:33.824317Z","iopub.execute_input":"2022-03-13T23:19:33.824639Z","iopub.status.idle":"2022-03-13T23:19:48.802644Z","shell.execute_reply.started":"2022-03-13T23:19:33.824552Z","shell.execute_reply":"2022-03-13T23:19:48.801902Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/kaggle-pog-series-s01e02/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/kaggle-pog-series-s01e02/test.csv\")\nsub = pd.read_csv(\"/kaggle/input/kaggle-pog-series-s01e02/sample_submission.csv\")\ngenres = pd.read_csv(\"/kaggle/input/kaggle-pog-series-s01e02/genres.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-13T23:44:29.570680Z","iopub.execute_input":"2022-03-13T23:44:29.571422Z","iopub.status.idle":"2022-03-13T23:44:29.646045Z","shell.execute_reply.started":"2022-03-13T23:44:29.571369Z","shell.execute_reply":"2022-03-13T23:44:29.645212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:03:58.459847Z","iopub.execute_input":"2022-03-14T00:03:58.460680Z","iopub.status.idle":"2022-03-14T00:03:58.478309Z","shell.execute_reply.started":"2022-03-14T00:03:58.460641Z","shell.execute_reply":"2022-03-14T00:03:58.477637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<iframe width=\"707\" height=\"530\" src=\"https://www.youtube.com/embed/78GdsomjoNA\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>","metadata":{}},{"cell_type":"markdown","source":"#Jimmy James - I'll Go Where The Music Takes Me - 1976\n\nhttps://www.youtube.com/watch?v=78GdsomjoNA","metadata":{}},{"cell_type":"code","source":"# Other  \nimport librosa\nimport librosa.display\nimport json\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nfrom matplotlib.pyplot import specgram\nimport pandas as pd\nimport seaborn as sns\nimport glob \nimport os\nfrom tqdm import tqdm\nimport pickle\nimport IPython.display as ipd  # To play sound in the notebook","metadata":{"execution":{"iopub.status.busy":"2022-03-13T23:20:23.329246Z","iopub.execute_input":"2022-03-13T23:20:23.329572Z","iopub.status.idle":"2022-03-13T23:20:29.836720Z","shell.execute_reply.started":"2022-03-13T23:20:23.329537Z","shell.execute_reply":"2022-03-13T23:20:29.835736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Sayantan Mazumdar https://www.kaggle.com/swaralipibose/converting-audio-to-spectogram-noise-image-data/notebook\n\n!pip install soundfile","metadata":{"execution":{"iopub.status.busy":"2022-03-13T23:20:47.612326Z","iopub.execute_input":"2022-03-13T23:20:47.613097Z","iopub.status.idle":"2022-03-13T23:20:56.957063Z","shell.execute_reply.started":"2022-03-13T23:20:47.613047Z","shell.execute_reply":"2022-03-13T23:20:56.956277Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Sayantan Mazumdar https://www.kaggle.com/swaralipibose/converting-audio-to-spectogram-noise-image-data/notebook\n\n!pip install noisereduce","metadata":{"execution":{"iopub.status.busy":"2022-03-13T23:21:24.820696Z","iopub.execute_input":"2022-03-13T23:21:24.823290Z","iopub.status.idle":"2022-03-13T23:21:33.806659Z","shell.execute_reply.started":"2022-03-13T23:21:24.823241Z","shell.execute_reply":"2022-03-13T23:21:33.805554Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_DIR = '../input/kaggle-pog-series-s01e02/'\nDATA_DIR ='../input/kaggle-pog-series-s01e02/train'\n\npath = '/kaggle/input/kaggle-pog-series-s01e02/'","metadata":{"execution":{"iopub.status.busy":"2022-03-13T23:58:03.971506Z","iopub.execute_input":"2022-03-13T23:58:03.971790Z","iopub.status.idle":"2022-03-13T23:58:03.976329Z","shell.execute_reply.started":"2022-03-13T23:58:03.971753Z","shell.execute_reply":"2022-03-13T23:58:03.975227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Train audio","metadata":{}},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\nprint('Number of train/songs:', len(os.listdir(path+'train')))\nprint(\"Example\")\nfn = train[\"filename\"].values[1]\nipd.Audio(f\"{BASE_DIR}train/{fn}\")","metadata":{"execution":{"iopub.status.busy":"2022-03-13T23:58:10.586706Z","iopub.execute_input":"2022-03-13T23:58:10.587169Z","iopub.status.idle":"2022-03-13T23:58:10.630557Z","shell.execute_reply.started":"2022-03-13T23:58:10.587128Z","shell.execute_reply":"2022-03-13T23:58:10.629679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\ny, sr = librosa.load(f\"{BASE_DIR}train/{fn}\")\nprint(f\"Numpy array of the audio loaded of shape {y.shape} and sample rate {sr}\")","metadata":{"execution":{"iopub.status.busy":"2022-03-13T23:58:26.356006Z","iopub.execute_input":"2022-03-13T23:58:26.356841Z","iopub.status.idle":"2022-03-13T23:58:28.608612Z","shell.execute_reply.started":"2022-03-13T23:58:26.356769Z","shell.execute_reply":"2022-03-13T23:58:28.607583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\nclass configuration():\n    '''Configuration File'''\n    n_fft = 2048\n    hop_length = n_fft // 4\n    \n    n_show_songs = 5\n    \nCFG = configuration()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:01:52.074352Z","iopub.execute_input":"2022-03-14T00:01:52.074709Z","iopub.status.idle":"2022-03-14T00:01:52.080276Z","shell.execute_reply.started":"2022-03-14T00:01:52.074677Z","shell.execute_reply":"2022-03-14T00:01:52.079367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values = 20","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:08:40.074110Z","iopub.execute_input":"2022-03-14T00:08:40.074622Z","iopub.status.idle":"2022-03-14T00:08:40.079323Z","shell.execute_reply.started":"2022-03-14T00:08:40.074572Z","shell.execute_reply":"2022-03-14T00:08:40.078345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\ntail = train['genre'].value_counts().tail(values).index\n\nfor i in tail[:CFG.n_show_songs]:\n    print(i)\n    \n    path = train[train['genre'] == i].sample(1,random_state = 2022)['filename'].values[0]\n    path ='/kaggle/input/kaggle-pog-series-s01e02/train/' + path\n    \n    data, sample_rate = librosa.load(path)\n    \n    stft = librosa.stft(data, n_fft=CFG.n_fft, hop_length=CFG.hop_length)\n    spectrogram = np.abs(stft)\n    x = librosa.amplitude_to_db(spectrogram)\n    \n    \n    fig, ax = plt.subplots(ncols = 2, nrows = 1, figsize = (12,5))\n    \n    librosa.display.specshow(x, sr=sample_rate, hop_length=CFG.hop_length,ax = ax[0])\n    ax[0].set_xlabel(\"Time\")\n    ax[0].set_ylabel(\"Frequency\")\n    ax[0].set_title(\"Spectrogram\")\n    \n    librosa.display.waveshow(data,ax = ax[1])\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:18:20.251292Z","iopub.execute_input":"2022-03-14T00:18:20.251799Z","iopub.status.idle":"2022-03-14T00:18:40.025638Z","shell.execute_reply.started":"2022-03-14T00:18:20.251765Z","shell.execute_reply":"2022-03-14T00:18:40.024910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Noise reduction","metadata":{}},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\nfrom IPython.display import Audio\n\ntest_soundscape = '../input/kaggle-pog-series-s01e02/test/000050.ogg'\ny, sr = librosa.load(test_soundscape, sr=32000, offset=None)\nAudio(test_soundscape)","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:23:52.871144Z","iopub.execute_input":"2022-03-14T00:23:52.871462Z","iopub.status.idle":"2022-03-14T00:23:54.231390Z","shell.execute_reply.started":"2022-03-14T00:23:52.871429Z","shell.execute_reply":"2022-03-14T00:23:54.230604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\nfig, ax = plt.subplots(figsize=(16, 8))\nsns.lineplot(x=np.arange(len(y)), y=y, ax=ax);","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:24:52.484261Z","iopub.execute_input":"2022-03-14T00:24:52.484882Z","iopub.status.idle":"2022-03-14T00:25:17.647137Z","shell.execute_reply.started":"2022-03-14T00:24:52.484840Z","shell.execute_reply":"2022-03-14T00:25:17.646191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\nimport noisereduce as nr\n\nreduced_noise = nr.reduce_noise(y=y, sr=32000)\nAudio(reduced_noise, rate=32000)","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:25:58.050316Z","iopub.execute_input":"2022-03-14T00:25:58.050871Z","iopub.status.idle":"2022-03-14T00:25:59.215464Z","shell.execute_reply.started":"2022-03-14T00:25:58.050835Z","shell.execute_reply":"2022-03-14T00:25:59.211899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Miyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda\n\ny = reduced_noise\n\nfig, ax = plt.subplots(figsize=(16, 8))\nsns.lineplot(x=np.arange(len(y)), y=y, ax=ax);","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:27:26.505446Z","iopub.execute_input":"2022-03-14T00:27:26.506130Z","iopub.status.idle":"2022-03-14T00:27:50.215629Z","shell.execute_reply.started":"2022-03-14T00:27:26.506083Z","shell.execute_reply":"2022-03-14T00:27:50.214612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Just checking Genres file","metadata":{}},{"cell_type":"code","source":"genres.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:30:14.920878Z","iopub.execute_input":"2022-03-14T00:30:14.921837Z","iopub.status.idle":"2022-03-14T00:30:14.932226Z","shell.execute_reply.started":"2022-03-14T00:30:14.921782Z","shell.execute_reply":"2022-03-14T00:30:14.931220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##Code by Taha07  https://www.kaggle.com/taha07/data-scientists-jobs-analysis-visualization/notebook\n\nfrom wordcloud import WordCloud\nfrom wordcloud import STOPWORDS\nstopwords = set(STOPWORDS)\nwordcloud = WordCloud(background_color = 'green',\n                      height =2000,\n                      width = 2000\n                     ).generate(str(genres[\"genre\"]))\nplt.rcParams['figure.figsize'] = (12,12)\nplt.axis(\"off\")\nplt.imshow(wordcloud)\nplt.title(\"Music Genres\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T00:32:45.816048Z","iopub.execute_input":"2022-03-14T00:32:45.816365Z","iopub.status.idle":"2022-03-14T00:32:49.494644Z","shell.execute_reply.started":"2022-03-14T00:32:45.816334Z","shell.execute_reply":"2022-03-14T00:32:49.493918Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Chiptune\n\n\"Chiptune, also known as chip music or 8-bit music, is a style of synthesized electronic music made using the programmable sound generator (PSG) sound chips or synthesizers in vintage arcade machines, computers and video game consoles. The term is commonly used to refer to tracker format music which intentionally sounds similar to older PSG-created music (this is the original meaning of the term), as well as music that combines PSG sounds with modern musical styles.\"\n\n\"It has been described as \"an interpretation of many genres\" since any existing song can be arranged in a chiptune style defined more by choice of instrument and timbre than specific style elements.\"\n\nhttps://en.wikipedia.org/wiki/Chiptune","metadata":{}},{"cell_type":"markdown","source":"![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDXKUedx9FADPRXR7l3y0RWuGDQSVQXYGc_g&usqp=CAU)open.spotify.com","metadata":{}},{"cell_type":"markdown","source":"#Acknowledgement:\n\nMiyuki Suzuki https://www.kaggle.com/m1y7k8/birdclef-2022-eda","metadata":{}}]}