{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":73047,"databundleVersionId":8149390,"sourceType":"competition"}],"dockerImageVersionId":30684,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport librosa","metadata":{"execution":{"iopub.status.busy":"2024-04-17T04:25:16.055628Z","iopub.execute_input":"2024-04-17T04:25:16.056851Z","iopub.status.idle":"2024-04-17T04:25:16.071154Z","shell.execute_reply.started":"2024-04-17T04:25:16.056806Z","shell.execute_reply":"2024-04-17T04:25:16.070136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = \"https://raw.githubusercontent.com/Jak57/datasets/main/datathon_asr_2024/sample_submission_fix.csv\"\ndf = pd.read_csv(path)\nprint(len(df))\ndf.head(3)","metadata":{"execution":{"iopub.status.busy":"2024-04-17T04:17:35.091461Z","iopub.execute_input":"2024-04-17T04:17:35.092326Z","iopub.status.idle":"2024-04-17T04:17:35.653087Z","shell.execute_reply.started":"2024-04-17T04:17:35.092278Z","shell.execute_reply":"2024-04-17T04:17:35.651736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = []\n_id = []\npath = []\naudio_length = []\nfolder = '/kaggle/input/ben10/ben10/16_kHz_valid_audio/'\n\ndef read_audio(mp3_path, target_sr=16000):\n    audio, sr = librosa.load(mp3_path, sr=32000)\n    return audio\n\ndef get_audio_length(row):\n    audio = read_audio(folder + row['id'])\n    row['audio_length'] = len(audio)/32000\n    return row\n\ndf = df.apply(get_audio_length, axis=1)\ndf.head(2)","metadata":{"execution":{"iopub.status.busy":"2024-04-17T04:25:19.476409Z","iopub.execute_input":"2024-04-17T04:25:19.476800Z","iopub.status.idle":"2024-04-17T04:26:21.866787Z","shell.execute_reply.started":"2024-04-17T04:25:19.476772Z","shell.execute_reply":"2024-04-17T04:26:21.865589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bucket = []\nfor idx, row in df.iterrows():\n    bucket.append((row['audio_length'], idx, row['id'], folder + row['id']))\nprint(bucket[:3])","metadata":{"execution":{"iopub.status.busy":"2024-04-17T04:28:20.210367Z","iopub.execute_input":"2024-04-17T04:28:20.210793Z","iopub.status.idle":"2024-04-17T04:28:20.325824Z","shell.execute_reply.started":"2024-04-17T04:28:20.210757Z","shell.execute_reply":"2024-04-17T04:28:20.324707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bucket = sorted(bucket)","metadata":{"execution":{"iopub.status.busy":"2024-04-17T04:28:33.939185Z","iopub.execute_input":"2024-04-17T04:28:33.940202Z","iopub.status.idle":"2024-04-17T04:28:33.945309Z","shell.execute_reply.started":"2024-04-17T04:28:33.940168Z","shell.execute_reply":"2024-04-17T04:28:33.944296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = []\n_id = []\npath = []\naudio_length = []\n\nfor t in bucket:\n    index.append(t[1])\n    _id.append(t[2])\n    path.append(t[3])\n    audio_length.append(t[0])\n\ndata = {\n    'index': index,\n    'id': _id,\n    'path': path,\n    'audio_length': audio_length\n}\ndf = pd.DataFrame(data, columns=data.keys())\nprint(len(df))\ndf.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-04-17T04:32:52.386237Z","iopub.execute_input":"2024-04-17T04:32:52.386700Z","iopub.status.idle":"2024-04-17T04:32:52.406989Z","shell.execute_reply.started":"2024-04-17T04:32:52.386666Z","shell.execute_reply":"2024-04-17T04:32:52.405882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('test_data_with_duration_final_v1_1703.csv')","metadata":{"execution":{"iopub.status.busy":"2024-04-17T04:33:24.232904Z","iopub.execute_input":"2024-04-17T04:33:24.233323Z","iopub.status.idle":"2024-04-17T04:33:24.252225Z","shell.execute_reply.started":"2024-04-17T04:33:24.233289Z","shell.execute_reply":"2024-04-17T04:33:24.250876Z"},"trusted":true},"execution_count":null,"outputs":[]}]}