{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8ccfdd2a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2242, 5)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv('malay-speech/UTTRANSINFO.txt', sep = '\\t')\n", "df.shape" ] }, { "cell_type": "code", "execution_count": 2, "id": "b4a00d54", "metadata": {}, "outputs": [], "source": [ "import soundfile as sf\n", "from glob import glob\n", "import os" ] }, { "cell_type": "code", "execution_count": 5, "id": "a31241cf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timestamps = [i * 0.02 for i in range(1500 + 1)]\n", "timestamps[0]" ] }, { "cell_type": "code", "execution_count": 3, "id": "448b3211", "metadata": {}, "outputs": [], "source": [ "!mkdir audio-whisper" ] }, { "cell_type": "code", "execution_count": 14, "id": "f5508d8d", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████████████████████████████████████████████████████████████████████████████████████████████| 2242/2242 [00:04<00:00, 529.83it/s]\n" ] } ], "source": [ "from tqdm import tqdm\n", "\n", "data = []\n", "for i in tqdm(range(len(df))):\n", " row = df.iloc[i]\n", " audio = os.path.join('malay-speech/WAV', row['SPEAKER_ID'], row['UTTRANS_ID'])\n", " if not os.path.exists(audio):\n", " continue\n", " \n", " y, sr = sf.read(audio)\n", " length = len(y) / sr\n", " \n", " start = 0.0\n", " end = min(timestamps, key=lambda t: abs(t - length))\n", " t = row['PROMPT']\n", " filtered = f\"<|{start:.2f}|> {t}<|{end:.2f}|>\"\n", " text = f\"<|startoftranscript|><|ms|><|transcribe|>{filtered}<|endoftext|>\"\n", " \n", " new_f = os.path.join('audio-whisper', f'{i}.wav')\n", " \n", " data.append({\n", " 'filename': new_f,\n", " 'Y': text,\n", " })\n", " \n", " sf.write(new_f, y, sr)" ] }, { "cell_type": "code", "execution_count": 15, "id": "70171283", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2242" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(data)" ] }, { "cell_type": "code", "execution_count": 16, "id": "a8dcd8ae", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'filename': 'audio-whisper/0.wav',\n", " 'Y': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Dia tidak tahu apa-apa .<|3.56|><|endoftext|>'}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[0]" ] }, { "cell_type": "code", "execution_count": 18, "id": "3e494e41", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import IPython.display as ipd\n", "ipd.Audio('audio-whisper/2233.wav')" ] }, { "cell_type": "code", "execution_count": 19, "id": "31f5c2f7", "metadata": {}, "outputs": [], "source": [ "!zip -rq scripted-malay-daily-use-speech-corpus-whisper-format.zip audio-whisper" ] }, { "cell_type": "code", "execution_count": 20, "id": "81f25b63", "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open('scripted-malay-daily-use-speech-corpus-whisper-format.json', 'w') as fopen:\n", " json.dump(data, fopen)" ] }, { "cell_type": "code", "execution_count": 22, "id": "ac25c536", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "44b8115898d640f8b0c4b1ff0fc5dedc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "scripted-malay-daily-use-speech-corpus-whisper-format.zip: 0%| | 0.00/399M [00:00