-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscribe.py
37 lines (29 loc) · 1.04 KB
/
transcribe.py
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
import os
import csv
import whisper
from glob import glob
from tqdm import tqdm
# Load the Whisper model
model = whisper.load_model("large")
# Get all files in the current directory that start with "0011_" and end with ".wav"
files = glob("./data/DATA/ESD-wavs-22k/0011_*.wav")
# Prepare the data for CSV
data = []
# Process each file
for file in tqdm(files):
# Extract the file number from the filename
file_number = file.split("_")[1].split(".")[0]
file_number_int = int(file_number)
if (file_number_int > 350):
continue
# Transcribe the audio file
result = model.transcribe(file)
transcription = result["text"]
# Add the data to our list
data.append([file_number, transcription])
# Write the data to a CSV file
with open("transcriptions.txt", "w", newline="", encoding="utf-8") as csvfile:
writer = csv.writer(csvfile, delimiter="|")
writer.writerow(["File Number", "Transcription"]) # Write header
writer.writerows(data)
print("Transcription complete. Results saved in 'transcriptions.csv'.")