Sin2pi commited on
Commit
7b396e6
·
verified ·
1 Parent(s): 9768842

Delete download_datasets_in_wav_or_mp3_and_create_csv.ipynb

Browse files
download_datasets_in_wav_or_mp3_and_create_csv.ipynb DELETED
@@ -1,71 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "metadata": {},
7
- "outputs": [],
8
- "source": [
9
- "from datasets import load_dataset\n",
10
- "import soundfile as sf, os, re, neologdn\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' # create metadata file with file names and transcripts\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, out_file) # Path to save transcription file \n",
31
- " if not os.path.exists(audio_path):\n",
32
- " patterns = [(r\"…\",'。'), (r\"!!\",'!'), (special_characters,\"\"), (r\"\\s+\", \"\")] # (r\"(.)\\1{2}\")\n",
33
- " for pattern, replace in patterns:\n",
34
- " sample[\"sentence\"] = re.sub(pattern, replace, sample[\"sentence\"])\n",
35
- " sample[\"sentence\"] = (neologdn.normalize(sample[\"sentence\"], repeat=1)) # for Japanese only, repeat number reduces repeat characters\n",
36
- " sample[\"sentence_length\"] = len(sample[\"sentence\"]) # Get sentence lengths \n",
37
- " sample[\"audio_length\"] = len(sample[\"audio\"][\"array\"]) / sample[\"audio\"][\"sampling_rate\"] # Get audio length, remove if not needed\n",
38
- " if bool(sample[\"sentence\"]) and max > sample[\"audio_length\"] > min and not re.search(char, sample[\"sentence\"]) and sample[\"sentence_length\"] > min_char:\n",
39
- " sf.write(audio_path, sample['audio']['array'], sample['audio']['sampling_rate']) # Get files \n",
40
- " # process_directory(folder_path, (folder_path + \"/trimmed/\")) # for use with audio sample silence removal script\n",
41
- " if os.path.isfile(audio_path):\n",
42
- " os.remove(audio_path)\n",
43
- " with open(transcription_path, 'a', encoding='utf-8') as transcription_file:\n",
44
- " transcription_file.write(audio_sample+\",\") # Save transcription file name \n",
45
- " transcription_file.write(sample['sentence']) # Save transcription \n",
46
- " transcription_file.write('\\n')"
47
- ]
48
- }
49
- ],
50
- "metadata": {
51
- "kernelspec": {
52
- "display_name": "Python 3",
53
- "language": "python",
54
- "name": "python3"
55
- },
56
- "language_info": {
57
- "codemirror_mode": {
58
- "name": "ipython",
59
- "version": 3
60
- },
61
- "file_extension": ".py",
62
- "mimetype": "text/x-python",
63
- "name": "python",
64
- "nbconvert_exporter": "python",
65
- "pygments_lexer": "ipython3",
66
- "version": "3.10.0"
67
- }
68
- },
69
- "nbformat": 4,
70
- "nbformat_minor": 2
71
- }