{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"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\n\nimport 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\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-31T03:43:37.166424Z","iopub.execute_input":"2023-08-31T03:43:37.167515Z","iopub.status.idle":"2023-08-31T03:43:37.177990Z","shell.execute_reply.started":"2023-08-31T03:43:37.167425Z","shell.execute_reply":"2023-08-31T03:43:37.176489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\nfrom tqdm import tqdm\n\ndomain_dirs = ['/kaggle/input/rangpur-train-test/rangpur/*/*.wav', \n               '/kaggle/input/kishoreganj-train-test/kishoreganj/*/*.wav', \n               '/kaggle/input/narail-train-test/narail/*/*.wav', \n               '/kaggle/input/chittagong-train-test/chittagong/*/*.wav', \n               '/kaggle/input/narsingdi-train-test/narsingdi/*/*.wav',\n               '/kaggle/input/bengaliai-speech/train_mp3s/*.mp3'\n              ]\n\ndomains = ['Rangpur', 'Kishoreganj','Narail', 'Chittagong','Narsingdi', 'OOD_Train_Set']","metadata":{"execution":{"iopub.status.busy":"2023-08-31T03:43:37.179722Z","iopub.execute_input":"2023-08-31T03:43:37.180310Z","iopub.status.idle":"2023-08-31T03:43:37.195363Z","shell.execute_reply.started":"2023-08-31T03:43:37.180263Z","shell.execute_reply":"2023-08-31T03:43:37.193596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"arr = []\nfor domain, domain_dir in zip(domains, domain_dirs):\n    data = [] # X\n    \n    #filenames = glob(domain_dir)\n    \n    if domain=='OOD_Train_Set':\n        filenames = glob(domain_dir)[:10000]\n    else:\n        filenames = glob(domain_dir)\n\n\n#     for file in tqdm(filenames):\n#         temp = scipy.io.wavfile.read(file, mmap=False)\n#         data.append(temp[1])\n        \n    motherArr = []\n    for each in tqdm(filenames):\n        data, sampling_rate = librosa.load(each)\n\n        n_fft = 2048 # FFT window size\n        hop_length = 512 # number audio of frames between STFT columns (looks like a good default)\n\n        D = librosa.stft(data, n_fft=n_fft, hop_length=hop_length)\n        S_db = librosa.amplitude_to_db(np.abs(D), ref = np.max)\n        S_db_mean = np.mean(S_db, axis = 1)\n        motherArr.append(S_db_mean)\n        \n    motherArr_mean = np.mean(motherArr, axis = 0)\n    arr.append(motherArr_mean)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T03:28:53.370126Z","iopub.execute_input":"2023-08-31T03:28:53.370781Z","iopub.status.idle":"2023-08-31T03:43:37.163151Z","shell.execute_reply.started":"2023-08-31T03:28:53.370743Z","shell.execute_reply":"2023-08-31T03:43:37.161423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\n\nfig, ax = plt.subplots()\n\nax.plot(arr[0], color = 'green', label = domains[0])\nax.plot(arr[1], color = 'red', label = domains[1])\nax.plot(arr[2], color = 'blue', label = domains[2])\nax.plot(arr[3], color = 'aqua', label = domains[3])\nax.plot(arr[4], color = 'orange', label = domains[4])\nax.plot(arr[5], color = 'black', label = domains[5])\n\nax.legend(loc = 'upper right')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-30T22:31:49.116233Z","iopub.execute_input":"2023-08-30T22:31:49.116657Z","iopub.status.idle":"2023-08-30T22:31:49.379764Z","shell.execute_reply.started":"2023-08-30T22:31:49.116591Z","shell.execute_reply":"2023-08-30T22:31:49.378591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" plt.savefig('LTSA.png')","metadata":{"execution":{"iopub.status.busy":"2023-08-30T22:31:49.380927Z","iopub.execute_input":"2023-08-30T22:31:49.381225Z","iopub.status.idle":"2023-08-30T22:31:49.410337Z","shell.execute_reply.started":"2023-08-30T22:31:49.381198Z","shell.execute_reply":"2023-08-30T22:31:49.409079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-08-30T17:07:36.885517Z","iopub.execute_input":"2023-08-30T17:07:36.885824Z","iopub.status.idle":"2023-08-30T17:07:36.890957Z","shell.execute_reply.started":"2023-08-30T17:07:36.885799Z","shell.execute_reply":"2023-08-30T17:07:36.889715Z"},"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":[]},{"cell_type":"code","source":"filenames","metadata":{"execution":{"iopub.status.busy":"2023-08-30T17:07:53.520854Z","iopub.execute_input":"2023-08-30T17:07:53.521266Z","iopub.status.idle":"2023-08-30T17:07:53.541402Z","shell.execute_reply.started":"2023-08-30T17:07:53.521233Z","shell.execute_reply":"2023-08-30T17:07:53.539748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-08-30T16:23:59.130633Z","iopub.execute_input":"2023-08-30T16:23:59.131023Z","iopub.status.idle":"2023-08-30T16:24:37.665625Z","shell.execute_reply.started":"2023-08-30T16:23:59.130994Z","shell.execute_reply":"2023-08-30T16:24:37.664995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-08-30T16:27:30.92573Z","iopub.execute_input":"2023-08-30T16:27:30.926104Z","iopub.status.idle":"2023-08-30T16:27:30.934543Z","shell.execute_reply.started":"2023-08-30T16:27:30.926075Z","shell.execute_reply":"2023-08-30T16:27:30.933036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(motherArr_mean)","metadata":{"execution":{"iopub.status.busy":"2023-08-30T16:27:40.610465Z","iopub.execute_input":"2023-08-30T16:27:40.610802Z","iopub.status.idle":"2023-08-30T16:27:40.798727Z","shell.execute_reply.started":"2023-08-30T16:27:40.610764Z","shell.execute_reply":"2023-08-30T16:27:40.797695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}],"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"}}