Skip to content

Instantly share code, notes, and snippets.

@cyrillsemenov
Created November 22, 2023 22:12
Show Gist options
  • Save cyrillsemenov/755b386d6398528d2e61a3693a76d282 to your computer and use it in GitHub Desktop.
Save cyrillsemenov/755b386d6398528d2e61a3693a76d282 to your computer and use it in GitHub Desktop.
Convert csv to text or srt like Premiere tracscript wants
"""
Convert csv to text or srt like Premiere tracscript wants
"""
import csv
def convert_csv_to_text(csv_filename, text_filename):
with open(csv_filename, 'r') as csv_file, open(text_filename, 'w') as text_file:
csv_reader = csv.reader(csv_file)
next(csv_reader) # Skip the header row
for row in csv_reader:
start_time, end_time = row[1], row[2]
speaker_name = row[0]
text = row[3]
text_file.write(f"{start_time} - {end_time}\n")
text_file.write(f"{speaker_name}\n")
text_file.write(f"{text}\n\n")
def convert_csv_to_srt(csv_filename, text_filename):
with open(csv_filename, 'r') as csv_file, open(text_filename, 'w') as text_file:
csv_reader = csv.reader(csv_file)
next(csv_reader) # Skip the header row
for i, row in enumerate(csv_reader):
start_time, end_time = row[1], row[2]
speaker_name = row[0]
text = row[3]
text_file.write(f"{i+1}\n")
text_file.write(f"{start_time[:-3]},000 --> {end_time[:-3]},000\n")
text_file.write(f"{text}\n\n")
if __name__ == "__main__":
convert_csv_to_text('Sheet.csv', 'Sheet1.txt')
convert_csv_to_srt('Sheet.csv', 'Sheet1.srt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment