Upload download_datasets_in_wav_or_mp3_and_create_csv.ipynb
Browse files
download_datasets_in_wav_or_mp3_and_create_csv.ipynb
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from datasets import Dataset, load_dataset, DatasetDict, Audio, concatenate_datasets, load_from_disk, IterableDataset, interleave_datasets\n",
|
10 |
+
"import soundfile as sf, os, pandas as pd, re\n",
|
11 |
+
"from tqdm import tqdm\n",
|
12 |
+
"\n",
|
13 |
+
"max = 20.0\n",
|
14 |
+
"min = 1.0\n",
|
15 |
+
"\n",
|
16 |
+
"dataset = load_dataset(\"Sin2pi/JA_audio_JA_text_180k_samples\", split=\"train\", trust_remote_code=True, streaming=True)\n",
|
17 |
+
"\n",
|
18 |
+
"name = \"gvs\"\n",
|
19 |
+
"ouput_dir = \"./datasets/\"\n",
|
20 |
+
"output_file = 'metadata.csv'\n",
|
21 |
+
"os.makedirs(ouput_dir + name, exist_ok=True)\n",
|
22 |
+
"folder_path = ouput_dir + name # Create a folder to store the audio and transcription files\n",
|
23 |
+
"\n",
|
24 |
+
"char = '[ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]'\n",
|
25 |
+
"special_characters = '[♬「」?!“%‘”~♪…?!゛#$%&()*+:;〈=〉@^_{|}~\"█♩♫』『.;:<>_()*&^$#@`, ]'\n",
|
26 |
+
"\n",
|
27 |
+
"for i, sample in tqdm(enumerate(dataset)): # Process each sample in the filtered dataset\n",
|
28 |
+
" audio_sample = name + f'_{i}.mp3' # or wav\n",
|
29 |
+
" audio_path = os.path.join(folder_path, audio_sample)\n",
|
30 |
+
" transcription_path = os.path.join(folder_path, output_file) # Path to save transcription file \n",
|
31 |
+
" sample[\"audio_length\"] = len(sample[\"audio\"][\"array\"]) / sample[\"audio\"][\"sampling_rate\"] # Get audio length, remove if not needed\n",
|
32 |
+
" sample[\"sentence\"] = re.sub(special_characters,'', sample[\"sentence\"])\n",
|
33 |
+
" \n",
|
34 |
+
" if not os.path.exists(audio_path) and bool(sample[\"sentence\"]) and sample[\"audio_length\"] > min and sample[\"audio_length\"] < max and not re.search(char, sample[\"sentence\"]) and sample[\"down_votes\"] == 0 and sample[\"up_votes\"] > 0:\n",
|
35 |
+
" \n",
|
36 |
+
" sf.write(audio_path, sample['audio']['array'], sample['audio']['sampling_rate'])\n",
|
37 |
+
" with open(transcription_path, 'a', encoding='utf-8') as transcription_file: # Save transcription file\n",
|
38 |
+
" transcription_file.write(audio_sample+\",\") # Save transcription file name \n",
|
39 |
+
" transcription_file.write(sample['sentence']) # Save transcription \n",
|
40 |
+
" transcription_file.write('\\n') "
|
41 |
+
]
|
42 |
+
}
|
43 |
+
],
|
44 |
+
"metadata": {
|
45 |
+
"kernelspec": {
|
46 |
+
"display_name": "Python 3",
|
47 |
+
"language": "python",
|
48 |
+
"name": "python3"
|
49 |
+
},
|
50 |
+
"language_info": {
|
51 |
+
"codemirror_mode": {
|
52 |
+
"name": "ipython",
|
53 |
+
"version": 3
|
54 |
+
},
|
55 |
+
"file_extension": ".py",
|
56 |
+
"mimetype": "text/x-python",
|
57 |
+
"name": "python",
|
58 |
+
"nbconvert_exporter": "python",
|
59 |
+
"pygments_lexer": "ipython3",
|
60 |
+
"version": "3.10.0"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"nbformat": 4,
|
64 |
+
"nbformat_minor": 2
|
65 |
+
}
|