File size: 1,656 Bytes
9e9ea0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pandas as pd
import os

# --- YOU NEED TO CHANGE THESE TWO LINES ---
# Path to the folder containing your .wav files
audio_folder_path = r'C:/Users/bunny/Downloads/wav' 
# Path to your transcript file (metadata.csv)
transcript_file_path = r'C:/Users/bunny/Downloads/metadata.csv'
# --- ---

# 1. Read the transcript file
# It's separated by '|' and has no header, so we name the columns ourselves.
try:
    df = pd.read_csv(transcript_file_path, sep='|', header=None, names=['filename', 'transcript'])
except FileNotFoundError:
    print(f"Error: The transcript file was not found at '{transcript_file_path}'")
    exit()

# 2. Create the full path for each audio file
# os.path.join() correctly combines the folder path and the filename.
df['audio'] = df['filename'].apply(lambda x: os.path.join(audio_folder_path, x))

# 3. Keep only the columns you want and in the right order
final_df = df[['audio', 'transcript']]

# 4. (Optional) Check which files actually exist and remove rows for missing files
initial_rows = len(final_df)
final_df = final_df[final_df['audio'].apply(os.path.exists)]
removed_rows = initial_rows - len(final_df)
if removed_rows > 0:
    print(f"Warning: Removed {removed_rows} rows because the audio file could not be found.")


# 5. Save the final dataset to a new CSV file
output_path = 'final_dataset.csv'
final_df.to_csv(output_path, index=False)

print(f"Successfully created dataset with {len(final_df)} entries.")
print(f"File saved to: {os.path.abspath(output_path)}")

# Display the first 5 rows of your new dataset
print("\n--- Dataset Preview ---")
print(final_df.head())