I am using OpenAI's whisper to take an .mp4 file and convert it to a .vtt file.
This works well for the most part, here is an example:
my_file = "filepath.mp4"
model = whisper.load_model("tiny")
result = model.transcribe(my_file )
vtt_writer = whisper.utils.WriteVTT(output_dir="./")
vtt_writer(result, my_file)
This produces a .vtt file for me that looks all correct.
However, I want to, instead of writing to a file, keep it as a string variable.
Simply assigning vtt=vtt_writer(result, my_file) doesn't result in anything (i.e. vtt is an empty object).
I was able to find where this is happening;
class WriteVTT(SubtitlesWriter):
extension: str = "vtt"
always_include_hours: bool = False
decimal_marker: str = "."
def write_result(self, result: dict, file: TextIO, options: dict):
print("WEBVTT\n", file=file)
for start, end, text in self.iterate_result(result, options):
print(f"{start} --> {end}\n{text}\n", file=file, flush=True)
However, I'd like to avoid:
- Reworking/editing the source code if I can
- Writing to file, reading it back in, then deleting it from file
What other options do I have?