Sin2pi commited on
Commit
ddcf040
·
verified ·
1 Parent(s): a371c98

Delete code_to_download_datasets_in_wav_or_mp3.ipynb

Browse files
code_to_download_datasets_in_wav_or_mp3.ipynb DELETED
@@ -1,47 +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, pandas as pd, re\n",
11
- "from tqdm import tqdm\n",
12
- "\n",
13
- "dataset = load_dataset(\"Sin2pi/JA_audio_JA_text_180k_samples\", trust_remote_code=True, streaming=True, token=\"your_token\")\n",
14
- "\n",
15
- "name = \"JA_audio_JA_text_180k_samples\"\n",
16
- "output_file = 'metadata.csv'\n",
17
- "os.makedirs(\"./datasets/\" + name, exist_ok=True)\n",
18
- "folder_path = \"./datasets/\" + name # Create a folder to store the audio and transcription files\n",
19
- "\n",
20
- "char = '[ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]'\n",
21
- "special_characters = '[♬「」 ?!;:“%‘” ~♪… ?!゛#$%&()*+:;〈=〉?@^_‘{|}~\"█♩♫♩ ♩』『.;:<>_()*&^%$#@?!`~, \"]'\n",
22
- "dsa = dataset.filter(lambda batch: bool(batch[\"sentence\"])).filter(lambda sample: not re.search(char, sample[\"sentence\"]))\n",
23
- "\n",
24
- "for i, sample in tqdm(enumerate(dsa)): # Process each sample in the filtered dataset\n",
25
- " audio_sample = name + f'_{i}.mp3' # or wav\n",
26
- " audio_path = os.path.join(folder_path, audio_sample)\n",
27
- " transcription_path = os.path.join(folder_path, output_file) # Path to save transcription file \n",
28
- " if not os.path.exists(audio_path):\n",
29
- " sf.write(audio_path, sample['audio']['array'], sample['audio']['sampling_rate'])\n",
30
- " sample[\"audio_length\"] = len(sample[\"audio\"][\"array\"]) / sample[\"audio\"][\"sampling_rate\"] # Get audio length, remove if not needed\n",
31
- " with open(transcription_path, 'a', encoding='utf-8') as transcription_file: # Save transcription file \n",
32
- " transcription_file.write(audio_sample+\",\") # Save transcription file name \n",
33
- " sample[\"sentence\"] = re.sub(special_characters,'', sample[\"sentence\"])\n",
34
- " transcription_file.write(sample['sentence']) # Save transcription \n",
35
- " transcription_file.write(str(\",\"+str(sample['audio_length']))) # Save audio length, remove if not needed\n",
36
- " transcription_file.write('\\n') "
37
- ]
38
- }
39
- ],
40
- "metadata": {
41
- "language_info": {
42
- "name": "python"
43
- }
44
- },
45
- "nbformat": 4,
46
- "nbformat_minor": 2
47
- }