{"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":"import numpy as np\nimport pandas as pd\nimport os\nimport librosa, librosa.display   \nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport IPython.display as ipd","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-05-26T15:06:51.793263Z","iopub.execute_input":"2021-05-26T15:06:51.793772Z","iopub.status.idle":"2021-05-26T15:06:51.801815Z","shell.execute_reply.started":"2021-05-26T15:06:51.793724Z","shell.execute_reply":"2021-05-26T15:06:51.800929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# LIBROSA Audio Feature Extraction\nhttps://librosa.org/doc/main/feature.html","metadata":{}},{"cell_type":"markdown","source":"### librosa.amplitude_to_db(spectrogram)","metadata":{}},{"cell_type":"code","source":"file = '../input/birdsong-recognition/train_audio/aldfly/XC134874.mp3'\nsignal, sr = librosa.load(file, sr=40200)\n\nlibrosa.display.waveplot(signal, sr = sr)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Amplitude\")\nplt.show()\n\nn_fft = 2048\nhop_length = 512\nstft = librosa.core.stft(signal, hop_length = hop_length, n_fft = n_fft)\nspectrogram = np.abs(stft)\nlog_spectrogram  = librosa.amplitude_to_db(spectrogram)","metadata":{"execution":{"iopub.status.busy":"2021-05-26T15:06:51.995213Z","iopub.execute_input":"2021-05-26T15:06:51.995814Z","iopub.status.idle":"2021-05-26T15:06:53.551234Z","shell.execute_reply.started":"2021-05-26T15:06:51.995779Z","shell.execute_reply":"2021-05-26T15:06:53.550098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### librosa.display.specshow(spectrogram, sr = sr, hop_length = hop_length)","metadata":{}},{"cell_type":"code","source":"librosa.display.specshow(spectrogram, sr = sr, hop_length = hop_length)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Frequency\")\nplt.colorbar()\nplt.set_cmap(\"viridis\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-05-26T15:06:53.553724Z","iopub.execute_input":"2021-05-26T15:06:53.554203Z","iopub.status.idle":"2021-05-26T15:06:54.670219Z","shell.execute_reply.started":"2021-05-26T15:06:53.554156Z","shell.execute_reply":"2021-05-26T15:06:54.669231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### librosa.display.specshow(log_spectrogram, sr = sr, hop_length = hop_length)","metadata":{}},{"cell_type":"code","source":"librosa.display.specshow(log_spectrogram, sr = sr, hop_length = hop_length)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Frequency\")\nplt.set_cmap(\"viridis\")\nplt.colorbar()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-05-26T15:06:54.671517Z","iopub.execute_input":"2021-05-26T15:06:54.671792Z","iopub.status.idle":"2021-05-26T15:06:55.807264Z","shell.execute_reply.started":"2021-05-26T15:06:54.671765Z","shell.execute_reply":"2021-05-26T15:06:55.806251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### librosa.feature.mfcc(signal, n_fft = n_fft, hop_length = hop_length, n_mfcc = 13)","metadata":{}},{"cell_type":"code","source":"MFCCs = librosa.feature.mfcc(signal, n_fft = n_fft, hop_length = hop_length, n_mfcc = 13)\nlibrosa.display.specshow(MFCCs, sr = sr, hop_length = hop_length)\nplt.xlabel(\"Time\")\nplt.ylabel(\"MFCCs\")\nplt.set_cmap(\"viridis\")\nplt.colorbar()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-05-26T15:06:55.808952Z","iopub.execute_input":"2021-05-26T15:06:55.809362Z","iopub.status.idle":"2021-05-26T15:06:56.040010Z","shell.execute_reply.started":"2021-05-26T15:06:55.809319Z","shell.execute_reply":"2021-05-26T15:06:56.039274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(file)","metadata":{"execution":{"iopub.status.busy":"2021-05-26T15:06:56.041445Z","iopub.execute_input":"2021-05-26T15:06:56.041833Z","iopub.status.idle":"2021-05-26T15:06:56.065440Z","shell.execute_reply.started":"2021-05-26T15:06:56.041803Z","shell.execute_reply":"2021-05-26T15:06:56.064260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}