{"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 librosa\nfrom IPython.display import Audio, display\nimport IPython\nimport librosa.display","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-01T05:51:24.823434Z","iopub.execute_input":"2022-08-01T05:51:24.823836Z","iopub.status.idle":"2022-08-01T05:51:35.768497Z","shell.execute_reply.started":"2022-08-01T05:51:24.823781Z","shell.execute_reply":"2022-08-01T05:51:35.767345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\nfilename= glob('../input/dlsprint/train_files/*.mp3')","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:00:54.972040Z","iopub.execute_input":"2022-08-01T06:00:54.972490Z","iopub.status.idle":"2022-08-01T06:00:55.960423Z","shell.execute_reply.started":"2022-08-01T06:00:54.972454Z","shell.execute_reply":"2022-08-01T06:00:55.959423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\nimport csv\nimport scipy\nfrom scipy.io import wavfile\nimport os\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.model_selection import train_test_split, ParameterGrid\nfrom sklearn.metrics import accuracy_score, precision_recall_fscore_support, confusion_matrix\nfrom sklearn.neural_network import MLPClassifier\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.metrics import classification_report","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:13:32.353918Z","iopub.execute_input":"2022-08-01T06:13:32.354289Z","iopub.status.idle":"2022-08-01T06:13:32.361438Z","shell.execute_reply.started":"2022-08-01T06:13:32.354259Z","shell.execute_reply":"2022-08-01T06:13:32.360305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def create_waveplot(data, sr, name):\n    plt.figure(figsize=(10, 3))\n    plt.title('Waveplot for audio of {} '.format(name), size=15)\n    librosa.display.waveplot(data, sr=sr)\n    plt.show()\n\ndef create_spectrogram(data, sr, idx):\n    # stft function converts the data into short term fourier transform\n    X = librosa.stft(data)\n    Xdb = librosa.amplitude_to_db(abs(X))\n    plt.figure(figsize=(12, 3))\n    plt.title('Spectrogram for audio for {} no data '.format(idx), size=15)\n    librosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')   \n    #librosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='log')\n    plt.colorbar()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:29:26.104931Z","iopub.execute_input":"2022-08-01T06:29:26.105329Z","iopub.status.idle":"2022-08-01T06:29:26.113756Z","shell.execute_reply.started":"2022-08-01T06:29:26.105296Z","shell.execute_reply":"2022-08-01T06:29:26.112234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 1\nindex=87\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#shohor theke valo batash paoa jay grame\n#1st e onk gap","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:16:37.889801Z","iopub.execute_input":"2022-08-01T06:16:37.890995Z","iopub.status.idle":"2022-08-01T06:16:38.750021Z","shell.execute_reply.started":"2022-08-01T06:16:37.890939Z","shell.execute_reply":"2022-08-01T06:16:38.748752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 2\nindex=400\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#shilalipi te Quran er kichu ayat khodai kora hoyeche\n#background noise","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:18:29.374460Z","iopub.execute_input":"2022-08-01T06:18:29.374864Z","iopub.status.idle":"2022-08-01T06:18:30.222848Z","shell.execute_reply.started":"2022-08-01T06:18:29.374821Z","shell.execute_reply":"2022-08-01T06:18:30.221772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 3\nindex=78\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#shekhane juddho ochol obosythay rup ney\n#slow","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:19:24.858593Z","iopub.execute_input":"2022-08-01T06:19:24.859377Z","iopub.status.idle":"2022-08-01T06:19:25.730949Z","shell.execute_reply.started":"2022-08-01T06:19:24.859335Z","shell.execute_reply":"2022-08-01T06:19:25.729772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 4\nindex=986\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#eti shit prodhan desher pakhi\n#good","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:20:54.851733Z","iopub.execute_input":"2022-08-01T06:20:54.852742Z","iopub.status.idle":"2022-08-01T06:20:55.854569Z","shell.execute_reply.started":"2022-08-01T06:20:54.852701Z","shell.execute_reply":"2022-08-01T06:20:55.853524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 5\nindex=654\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#jemon uccharon jotilota, dhoniprookaser jotilota ittadi\n#bujte onk kosto hoy","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:21:38.408142Z","iopub.execute_input":"2022-08-01T06:21:38.408522Z","iopub.status.idle":"2022-08-01T06:21:39.344132Z","shell.execute_reply.started":"2022-08-01T06:21:38.408488Z","shell.execute_reply":"2022-08-01T06:21:39.343072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 6\nindex=16477\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#chuktivittik duijon kormokorta ebong ekjon sthanio dioan shomonnoye ei commision gothito hoy\n#good","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:23:01.161484Z","iopub.execute_input":"2022-08-01T06:23:01.161909Z","iopub.status.idle":"2022-08-01T06:23:02.168773Z","shell.execute_reply.started":"2022-08-01T06:23:01.161871Z","shell.execute_reply":"2022-08-01T06:23:02.167755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 7\nindex=8777\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n# shadharonoto ei bakha ghonisher jonmo shongkranto ekti bishoy\n#background noise and distorted","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:24:32.103691Z","iopub.execute_input":"2022-08-01T06:24:32.104492Z","iopub.status.idle":"2022-08-01T06:24:32.958251Z","shell.execute_reply.started":"2022-08-01T06:24:32.104453Z","shell.execute_reply":"2022-08-01T06:24:32.957142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 8\nindex=1987\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#ei boi te tini forashi nari bader bekkha diyechen\n#good ","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:26:05.431195Z","iopub.execute_input":"2022-08-01T06:26:05.431634Z","iopub.status.idle":"2022-08-01T06:26:06.244106Z","shell.execute_reply.started":"2022-08-01T06:26:05.431599Z","shell.execute_reply":"2022-08-01T06:26:06.242813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 9\nindex=13574\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#tara duijon e shikkhok chilen\n#good","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:26:57.342943Z","iopub.execute_input":"2022-08-01T06:26:57.343618Z","iopub.status.idle":"2022-08-01T06:26:58.238653Z","shell.execute_reply.started":"2022-08-01T06:26:57.343578Z","shell.execute_reply":"2022-08-01T06:26:58.237422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#audio = 10\nindex=1\naudio,sr= librosa.load(filename[index])\nplt.plot(audio)\nIPython.display.Audio(filename[index])\n#tar ek chele dui meye\n#distorted","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:27:25.478141Z","iopub.execute_input":"2022-08-01T06:27:25.478819Z","iopub.status.idle":"2022-08-01T06:27:26.283925Z","shell.execute_reply.started":"2022-08-01T06:27:25.478765Z","shell.execute_reply":"2022-08-01T06:27:26.282768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for idx, file in enumerate ((filename[0:100])):\n    spectogram = []\n    path = filename[idx]\n    data, sampling_rate = librosa.load(path)\n    a = create_spectrogram(data, sampling_rate, idx)\n    spectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T06:29:32.951897Z","iopub.execute_input":"2022-08-01T06:29:32.952288Z","iopub.status.idle":"2022-08-01T06:31:34.882756Z","shell.execute_reply.started":"2022-08-01T06:29:32.952254Z","shell.execute_reply":"2022-08-01T06:31:34.881743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}