Datasets:
Update README.md
Browse files
README.md
CHANGED
|
@@ -32,50 +32,22 @@ size_categories:
|
|
| 32 |
---
|
| 33 |
|
| 34 |
<pre><code>
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
os.
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
sf.write(audio_path, sample['audio']['array'], sample['audio']['sampling_rate']) # Save the audio file
|
| 54 |
-
sample["audio_length"] = len(sample["audio"]["array"]) / sample["audio"]["sampling_rate"] # Get audio length
|
| 55 |
-
with open(transcription_path, 'w', encoding='utf-8') as transcription_file: # Save the transcription file
|
| 56 |
-
transcription_file.write(sample['sentence']) # Save the transcription sentence
|
| 57 |
-
transcription_file.write(str(","+str(sample['audio_length']))) # Save the audio length
|
| 58 |
-
|
| 59 |
-
# This creates a metadata.csv file with file_names and sentences in columns and then moves transcription text files to txt directory
|
| 60 |
-
|
| 61 |
-
name = name
|
| 62 |
-
folder_path = "./datasets/" + name
|
| 63 |
-
output_file = folder_path + '/metadata.csv'
|
| 64 |
-
|
| 65 |
-
with open(output_file, 'w', encoding='utf-8') as outfile:
|
| 66 |
-
writer = csv.writer(outfile) # Creates csv
|
| 67 |
-
writer.writerow(('file_name', 'sentence')) # Creates column heads
|
| 68 |
-
for file_name in os.listdir(folder_path):
|
| 69 |
-
if file_name.endswith('.txt'):
|
| 70 |
-
filepath = os.path.join(folder_path, file_name)
|
| 71 |
-
with open(filepath, 'r', encoding='utf-8') as infile:
|
| 72 |
-
outfile.write((file_name.rstrip('.txt'))+".mp3" + ",") # Add file names with trailing comma to csv
|
| 73 |
-
outfile.write(infile.read()) # Add sentence/transcriptions on the same line as file name
|
| 74 |
-
outfile.write('\n') # Adds a return
|
| 75 |
-
for file_name in os.listdir(folder_path):
|
| 76 |
-
os.makedirs(folder_path + "./txt/", exist_ok=True)
|
| 77 |
-
if file_name.endswith('.txt'):
|
| 78 |
-
source_path = os.path.join(folder_path, file_name)
|
| 79 |
-
dest_path = os.path.join(folder_path + '/txt/', file_name)
|
| 80 |
-
shutil.move(source_path, dest_path) # Moves txt files
|
| 81 |
</code></pre>
|
|
|
|
| 32 |
---
|
| 33 |
|
| 34 |
<pre><code>
|
| 35 |
+
|
| 36 |
+
dataset = load_dataset("sin2piusc/CSS10_jsss_jvs_cv")
|
| 37 |
+
output_file = 'metadata.csv'
|
| 38 |
+
|
| 39 |
+
special_characters = '[,♬「」 ?!;:“%‘” ~♪…~ !?!?#$%&゛#$%&()*+:;〈=〉?@^_‘{|}~".,]'
|
| 40 |
+
|
| 41 |
+
for i, sample in tqdm(enumerate(dataset)): # Process each sample in the filtered dataset
|
| 42 |
+
audio_sample = name + f'_{i}.mp3'
|
| 43 |
+
audio_path = os.path.join(folder_path, audio_sample)
|
| 44 |
+
transcription_path = os.path.join(folder_path, output_file) # Path to save transcription file
|
| 45 |
+
sf.write(audio_path, sample['audio']['array'], sample['audio']['sampling_rate']) # Save mp3/wav files
|
| 46 |
+
sample["audio_length"] = len(sample["audio"]["array"]) / sample["audio"]["sampling_rate"] # Get audio length
|
| 47 |
+
with open(transcription_path, 'a', encoding='utf-8') as transcription_file: # Save transcription file
|
| 48 |
+
sample["sentence"] = re.sub(special_characters,'', sample["sentence"]) # Remove special characters
|
| 49 |
+
transcription_file.write(audio_sample + ",") # Save transcription file name
|
| 50 |
+
transcription_file.write(sample['sentence']) # Save transcription
|
| 51 |
+
transcription_file.write(str(","+str(sample['audio_length']))) # Save audio length
|
| 52 |
+
transcription_file.write('\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
</code></pre>
|