{"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":"# Introduction\nI found the noisereduce package in Jira Borovec's notebook: https://www.kaggle.com/jirkaborovec/birdclef-convert-spectrograms-noise-reduce\nThis is a very useful package but the normal pip install command doesn't work without Internet connection. So I created a dataset wich contains this package so you can also add it to your kernel.\n\nYou can add the package to your kernel if you click on Add data and look for noisereduce noisereduce 2.0.0.\n![](https://goew.eu/kaggle/bird_clef_2022/noisereduce.png)","metadata":{}},{"cell_type":"markdown","source":"# Example","metadata":{}},{"cell_type":"code","source":"!pip install '../input/noisereduce-2-0-0/noisereduce-2.0.0-py3-none-any.whl'","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:13:44.099758Z","iopub.execute_input":"2022-03-04T14:13:44.100461Z","iopub.status.idle":"2022-03-04T14:14:12.180303Z","shell.execute_reply.started":"2022-03-04T14:13:44.100422Z","shell.execute_reply":"2022-03-04T14:14:12.179180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa\nimport matplotlib.pyplot as plt\nimport librosa.display\nfrom IPython.display import Audio","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:15:41.854524Z","iopub.execute_input":"2022-03-04T14:15:41.854843Z","iopub.status.idle":"2022-03-04T14:15:43.990034Z","shell.execute_reply.started":"2022-03-04T14:15:41.854809Z","shell.execute_reply":"2022-03-04T14:15:43.986909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Original data","metadata":{}},{"cell_type":"code","source":"test_soundscape = '../input/birdclef-2022/test_soundscapes/soundscape_453028782.ogg'\nAudio(test_soundscape)","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:16:05.167481Z","iopub.execute_input":"2022-03-04T14:16:05.168053Z","iopub.status.idle":"2022-03-04T14:16:05.231057Z","shell.execute_reply.started":"2022-03-04T14:16:05.168004Z","shell.execute_reply":"2022-03-04T14:16:05.230198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y, sr = librosa.load(test_soundscape, sr=32000, offset=None)","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:17:07.732329Z","iopub.execute_input":"2022-03-04T14:17:07.733174Z","iopub.status.idle":"2022-03-04T14:17:07.806252Z","shell.execute_reply.started":"2022-03-04T14:17:07.733134Z","shell.execute_reply":"2022-03-04T14:17:07.805540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = librosa.stft(y.astype('float'))\nXdb = librosa.amplitude_to_db(X)\nplt.figure(figsize=(12, 5))\nlibrosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:17:13.945390Z","iopub.execute_input":"2022-03-04T14:17:13.945982Z","iopub.status.idle":"2022-03-04T14:17:16.772321Z","shell.execute_reply.started":"2022-03-04T14:17:13.945945Z","shell.execute_reply":"2022-03-04T14:17:16.768763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Noise reduction","metadata":{}},{"cell_type":"code","source":"import noisereduce as nr","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:18:42.092063Z","iopub.execute_input":"2022-03-04T14:18:42.092488Z","iopub.status.idle":"2022-03-04T14:18:42.297579Z","shell.execute_reply.started":"2022-03-04T14:18:42.092453Z","shell.execute_reply":"2022-03-04T14:18:42.296906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"reduced_noise = nr.reduce_noise(y=y, sr=32000)\nAudio(reduced_noise, rate=32000)","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:18:43.680843Z","iopub.execute_input":"2022-03-04T14:18:43.681607Z","iopub.status.idle":"2022-03-04T14:18:45.409089Z","shell.execute_reply.started":"2022-03-04T14:18:43.681569Z","shell.execute_reply":"2022-03-04T14:18:45.408245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = librosa.stft(reduced_noise.astype('float'))\nXdb = librosa.amplitude_to_db(X)\nplt.figure(figsize=(12, 5))\nlibrosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-04T14:19:10.849919Z","iopub.execute_input":"2022-03-04T14:19:10.850196Z","iopub.status.idle":"2022-03-04T14:19:13.445093Z","shell.execute_reply.started":"2022-03-04T14:19:10.850166Z","shell.execute_reply":"2022-03-04T14:19:13.444242Z"},"trusted":true},"execution_count":null,"outputs":[]}]}