diff --git "a/prepare-upload.ipynb" "b/prepare-upload.ipynb" new file mode 100644--- /dev/null +++ "b/prepare-upload.ipynb" @@ -0,0 +1,3379 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "33ff07b7", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import soundfile as sf\n", + "from tqdm import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "8b36e5d6", + "metadata": {}, + "outputs": [], + "source": [ + "!mkdir audio" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "26f935d3", + "metadata": {}, + "outputs": [], + "source": [ + "with open('/home/husein/speech-bahasa/malay-asr-train-shuffled.json') as fopen:\n", + " data = json.load(fopen)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "c9d2279d", + "metadata": {}, + "outputs": [], + "source": [ + "# !wget https://gist.githubusercontent.com/huseinzol05/98974ae8c6c7a65d4bc0af9f5003786a/raw/5aa5257608b61e8fcc828e99fbd070d5ca7358e3/mp.py" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "51e46ebc", + "metadata": {}, + "outputs": [], + "source": [ + "import mp\n", + "\n", + "def loop(index):\n", + " index, _ = index\n", + " for i in tqdm(index):\n", + " y, _ = sf.read(data['X'][i])\n", + " sf.write(f'audio/{i}.mp3', y, 16000)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "61fb2fd6", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|███████████████████████████████████████████| 10/10 [00:02<00:00, 4.63it/s]\n" + ] + } + ], + "source": [ + "loop((range(10), 0))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "45421d6d", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " 76%|████████████████████████▎ | 61997/81779 [20:02:48<7:46:14, 1.41s/it]IOPub message rate exceeded.\n", + "The notebook server will temporarily stop sending output\n", + "to the client in order to avoid crashing it.\n", + "To change this limit, set the config variable\n", + "`--NotebookApp.iopub_msg_rate_limit`.\n", + "\n", + "Current values:\n", + "NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec)\n", + "NotebookApp.rate_limit_window=3.0 (secs)\n", + "\n", + "100%|██████████████████████████████████| 81779/81779 [26:37:45<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:37:49<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:37:51<00:00, 1.17s/it]\n", + "100%|███████████████████████████████████████████| 19/19 [00:23<00:00, 1.22s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:38:09<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:38:16<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:38:17<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:38:17<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:38:21<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:38:29<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:38:57<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:39:09<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:39:09<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:39:21<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:39:30<00:00, 1.17s/it]\n", + "100%|████████████████████████████████��█| 81779/81779 [26:39:33<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:39:48<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:39:52<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:39:56<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:40:06<00:00, 1.17s/it]\n", + "100%|██████████████████████████████████| 81779/81779 [26:40:12<00:00, 1.17s/it]\n" + ] + } + ], + "source": [ + "mp.multiprocessing(range(len(data['X'])), loop, cores = 20, returned = False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "deb07990", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|█████████████████████████████| 1635599/1635599 [00:03<00:00, 484512.06it/s]\n" + ] + } + ], + "source": [ + "import os\n", + "\n", + "with open('label.jsonl', 'w') as fopen:\n", + " for i in tqdm(range(len(data['X']))):\n", + " f = f'audio/{i}.mp3'\n", + " d = {\n", + " 'filename': f,\n", + " 'Y': data['Y'][i]\n", + " }\n", + " fopen.write(f'{json.dumps(d)}\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "85353fef", + "metadata": {}, + "outputs": [], + "source": [ + "from datasets import load_dataset, Audio" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "5676f8b5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloading and preparing dataset json/default to /home/husein/.cache/huggingface/datasets/json/default-e2b95159dbdc9fa6/0.0.0/e347ab1c932092252e717ff3f949105a4dd28b27e842dd53157d2f72e276c2e4...\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "589c88f771424543b3d60f24f89fbe83", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Downloading data files: 0%| | 0/1 [00:00\n", + " \n", + " Your browser does not support the audio element.\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import IPython.display as ipd\n", + "ipd.Audio(dataset[10000]['filename']['array'], rate = 16000)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "390a8aff", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "26d553fe2c7a485fba88312495a124e8", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Map: 0%| | 0/15286 [00:00