{"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":{"execution":{"iopub.status.busy":"2022-07-27T05:46:10.364681Z","iopub.execute_input":"2022-07-27T05:46:10.365102Z","iopub.status.idle":"2022-07-27T05:46:22.704456Z","shell.execute_reply.started":"2022-07-27T05:46:10.365068Z","shell.execute_reply":"2022-07-27T05:46:22.703230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\n\nfilenames = glob('../input/dlsprint/train_files/*.mp3')\n\n\nfor each in filenames:\n    each = each.split('/')[-1][:-3]\n","metadata":{"execution":{"iopub.status.busy":"2022-07-27T05:46:22.706364Z","iopub.execute_input":"2022-07-27T05:46:22.706709Z","iopub.status.idle":"2022-07-27T05:46:28.406911Z","shell.execute_reply.started":"2022-07-27T05:46:22.706678Z","shell.execute_reply":"2022-07-27T05:46:28.405768Z"},"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\nfrom pydub import AudioSegment","metadata":{"execution":{"iopub.status.busy":"2022-07-27T05:46:28.408434Z","iopub.execute_input":"2022-07-27T05:46:28.408858Z","iopub.status.idle":"2022-07-27T05:46:28.420902Z","shell.execute_reply.started":"2022-07-27T05:46:28.408818Z","shell.execute_reply":"2022-07-27T05:46:28.419535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_filenames=[]\n\nfor each in filenames:\n    sound = AudioSegment.from_mp3(each)\n    sound.export(output_file, format=\"wav\")\n    new_filenames.append(output_file)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T12:36:41.757905Z","iopub.execute_input":"2022-07-26T12:36:41.758896Z","iopub.status.idle":"2022-07-26T12:36:42.638682Z","shell.execute_reply.started":"2022-07-26T12:36:41.758849Z","shell.execute_reply":"2022-07-26T12:36:42.636039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_filenames","metadata":{"execution":{"iopub.status.busy":"2022-07-26T12:37:01.792204Z","iopub.execute_input":"2022-07-26T12:37:01.792583Z","iopub.status.idle":"2022-07-26T12:37:01.798317Z","shell.execute_reply.started":"2022-07-26T12:37:01.792554Z","shell.execute_reply":"2022-07-26T12:37:01.797461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(filenames)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T05:46:33.836761Z","iopub.execute_input":"2022-07-27T05:46:33.837190Z","iopub.status.idle":"2022-07-27T05:46:33.846508Z","shell.execute_reply.started":"2022-07-27T05:46:33.837154Z","shell.execute_reply":"2022-07-27T05:46:33.845642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1st Task: Listening random audios","metadata":{}},{"cell_type":"code","source":"index = 461\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n#তিনি খুব অল্প বয়সে জাতির জন্য নিজের জীবন উতসর্গ করেছিলেন","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:17:49.950466Z","iopub.execute_input":"2022-07-27T06:17:49.950907Z","iopub.status.idle":"2022-07-27T06:17:50.827553Z","shell.execute_reply.started":"2022-07-27T06:17:49.950865Z","shell.execute_reply":"2022-07-27T06:17:50.826445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 462\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n\n# এটি একটি জাতীয় ছুটি এবং জনসাধারণের অধিকাংশ এদিনে স্কুল এবং কাজ থেকে বিরত থাকে।","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:20:17.587992Z","iopub.execute_input":"2022-07-27T06:20:17.588468Z","iopub.status.idle":"2022-07-27T06:20:18.558995Z","shell.execute_reply.started":"2022-07-27T06:20:17.588427Z","shell.execute_reply":"2022-07-27T06:20:18.558000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 463\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n\n#তাই তিনি তার প্রথম উপন্যাসটি লিখেন","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:21:58.167251Z","iopub.execute_input":"2022-07-27T06:21:58.168422Z","iopub.status.idle":"2022-07-27T06:21:59.040401Z","shell.execute_reply.started":"2022-07-27T06:21:58.168370Z","shell.execute_reply":"2022-07-27T06:21:59.039382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 464\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n#চিনারা সাধারণত তাদের দেব দেবী ও ধর্মীয় নেতাদের বিশালাকার মূর্তি বানিয়ে থাকে....loud","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:22:29.948736Z","iopub.execute_input":"2022-07-27T06:22:29.949764Z","iopub.status.idle":"2022-07-27T06:22:30.926190Z","shell.execute_reply.started":"2022-07-27T06:22:29.949721Z","shell.execute_reply":"2022-07-27T06:22:30.924929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 465\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n\n#তাদের অভিজ্ঞতা ছিল যুদ্ধকালীন এবং যুদ্ধ পরবর্তী সমকালীন","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:23:50.946052Z","iopub.execute_input":"2022-07-27T06:23:50.946710Z","iopub.status.idle":"2022-07-27T06:23:51.846690Z","shell.execute_reply.started":"2022-07-27T06:23:50.946674Z","shell.execute_reply":"2022-07-27T06:23:51.845728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 466\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n#.......... গল্পের পরিসমাপ্তি ঘটে ......unclear\n","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:32:34.507571Z","iopub.execute_input":"2022-07-27T06:32:34.508042Z","iopub.status.idle":"2022-07-27T06:32:35.428436Z","shell.execute_reply.started":"2022-07-27T06:32:34.508000Z","shell.execute_reply":"2022-07-27T06:32:35.427428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 467\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n# এই প্রচেষ্টা মূলত স্কটল্যান্ড, পোল্যান্ড এবং নিউজিল্যান্ড কেন্দ্রিক","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:34:28.685599Z","iopub.execute_input":"2022-07-27T06:34:28.686189Z","iopub.status.idle":"2022-07-27T06:34:29.558436Z","shell.execute_reply.started":"2022-07-27T06:34:28.686147Z","shell.execute_reply":"2022-07-27T06:34:29.556951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 468\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n#কারাগার থেকে মুক্তিলাভ এর পর বগুরা জেলার আওয়ামী লীগের সাংগঠনিক সম্পাদক, সাধারণ সম্পাদক ও পরবর্তীতে সভাপতি  হিসেবে দায়িত্ব পালন করেন","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:26:22.193348Z","iopub.execute_input":"2022-07-27T06:26:22.194671Z","iopub.status.idle":"2022-07-27T06:26:23.284262Z","shell.execute_reply.started":"2022-07-27T06:26:22.194614Z","shell.execute_reply":"2022-07-27T06:26:23.282874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 469\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n#তিনি প্রথমবার সংসদ সদস্য নির্বাচিত হয়েছেন।","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:30:24.025014Z","iopub.execute_input":"2022-07-27T06:30:24.025483Z","iopub.status.idle":"2022-07-27T06:30:24.948814Z","shell.execute_reply.started":"2022-07-27T06:30:24.025442Z","shell.execute_reply":"2022-07-27T06:30:24.947779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = 470\n\ntemp,sr = librosa.load(filenames[index])\nplt.plot(temp)\n\nIPython.display.Audio(filenames[index])\n\n# মুঘল আমলে এখানে জনবসতি গড়ে উঠে","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:31:05.995317Z","iopub.execute_input":"2022-07-27T06:31:05.996071Z","iopub.status.idle":"2022-07-27T06:31:07.160147Z","shell.execute_reply.started":"2022-07-27T06:31:05.996027Z","shell.execute_reply":"2022-07-27T06:31:07.158850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Spectogram**","metadata":{}},{"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, name):\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 of {} '.format(name), 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-07-27T06:36:35.811068Z","iopub.execute_input":"2022-07-27T06:36:35.812344Z","iopub.status.idle":"2022-07-27T06:36:35.820726Z","shell.execute_reply.started":"2022-07-27T06:36:35.812286Z","shell.execute_reply":"2022-07-27T06:36:35.819636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name='tini khub olpo boyoshe jatir jonno nijer jibon utsorgo korechilen'\n\nspectogram = []\nidx = 461\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:59:25.632312Z","iopub.execute_input":"2022-07-27T06:59:25.632720Z","iopub.status.idle":"2022-07-27T06:59:26.799105Z","shell.execute_reply.started":"2022-07-27T06:59:25.632684Z","shell.execute_reply":"2022-07-27T06:59:26.797764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name='eti ekti jatiyo chuti ebong jonosadharoner odhikangso edine school ebong kaj theke biroto thake'\n\nspectogram = []\nidx = 462\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:59:29.793252Z","iopub.execute_input":"2022-07-27T06:59:29.793680Z","iopub.status.idle":"2022-07-27T06:59:30.973541Z","shell.execute_reply.started":"2022-07-27T06:59:29.793642Z","shell.execute_reply":"2022-07-27T06:59:30.972056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name='tai tini tar prothom uponnas ti likhen'\n\nspectogram = []\nidx = 463\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:59:33.746805Z","iopub.execute_input":"2022-07-27T06:59:33.747253Z","iopub.status.idle":"2022-07-27T06:59:34.770845Z","shell.execute_reply.started":"2022-07-27T06:59:33.747211Z","shell.execute_reply":"2022-07-27T06:59:34.769253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nname='china ra sadharonoto tader deb debi o dormiyo netader bishalakar murti baniye thake'\nspectogram = []\nidx = 464\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:59:34.773189Z","iopub.execute_input":"2022-07-27T06:59:34.773610Z","iopub.status.idle":"2022-07-27T06:59:36.080288Z","shell.execute_reply.started":"2022-07-27T06:59:34.773571Z","shell.execute_reply":"2022-07-27T06:59:36.078909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nname='tader oviggota chilo juddho kalin ebong juddho poroborti somokalin'\nspectogram = []\nidx = 465\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:59:38.867165Z","iopub.execute_input":"2022-07-27T06:59:38.867614Z","iopub.status.idle":"2022-07-27T06:59:39.993132Z","shell.execute_reply.started":"2022-07-27T06:59:38.867572Z","shell.execute_reply":"2022-07-27T06:59:39.991535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nname='........golper porisomapti ghote'\nspectogram = []\nidx = 466\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T06:59:39.996074Z","iopub.execute_input":"2022-07-27T06:59:39.996599Z","iopub.status.idle":"2022-07-27T06:59:41.120390Z","shell.execute_reply.started":"2022-07-27T06:59:39.996546Z","shell.execute_reply":"2022-07-27T06:59:41.119022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name='ei prochesta muloto scotland, poland o new zealand kendrik'\n\nspectogram = []\nidx = 467\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T07:00:10.435247Z","iopub.execute_input":"2022-07-27T07:00:10.436122Z","iopub.status.idle":"2022-07-27T07:00:11.470307Z","shell.execute_reply.started":"2022-07-27T07:00:10.436070Z","shell.execute_reply":"2022-07-27T07:00:11.468869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name='karagar theke muktilaver por bogra jela awami league er sangothonik sompadok, sadharon sompadok o sovapoti hisebe dayitto palon koren'\n\nspectogram = []\nidx = 468\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T07:00:11.608656Z","iopub.execute_input":"2022-07-27T07:00:11.609101Z","iopub.status.idle":"2022-07-27T07:00:12.948845Z","shell.execute_reply.started":"2022-07-27T07:00:11.609059Z","shell.execute_reply":"2022-07-27T07:00:12.947456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name='tini prothombar songsod sodosso nirbachito hoyhechen'\n\nspectogram = []\nidx = 469\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T07:00:15.528185Z","iopub.execute_input":"2022-07-27T07:00:15.528730Z","iopub.status.idle":"2022-07-27T07:00:16.678286Z","shell.execute_reply.started":"2022-07-27T07:00:15.528679Z","shell.execute_reply":"2022-07-27T07:00:16.676614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name='mughol amole ekhane jonobosoti gore uthe'\n\nspectogram = []\nidx = 470\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-27T07:00:16.681080Z","iopub.execute_input":"2022-07-27T07:00:16.681622Z","iopub.status.idle":"2022-07-27T07:00:17.694385Z","shell.execute_reply.started":"2022-07-27T07:00:16.681568Z","shell.execute_reply":"2022-07-27T07:00:17.693034Z"},"trusted":true},"execution_count":null,"outputs":[]}]}