Convert WebVTT to Elan
For Whisper's output
!pip install pympi-ling webvtt-py
from pympi import Eaf
import webvtt
from pathlib import Path
def convert_vtt_to_elan(filename, tiername="whisper"):
outfile = filename.replace(".vtt", ".eaf")
eaf = Eaf()
eaf.add_tier(tiername)
count = 1
for caption in webvtt.read(filename):
start = int(caption.start_in_seconds * 1000)
end = int(caption.end_in_seconds * 1000)
text = caption.text.replace("\n", " ").replace("\r", "")
eaf.add_annotation(tiername, start, end, text)
eaf.to_file(outfile)
for file in Path(".").glob("*vtt"):
convert_vtt_to_elan(str(file))