File size: 636 Bytes
7b2c089
 
 
 
 
82a7fca
 
 
 
7b2c089
 
82a7fca
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

def save_subtitles(prediction, output_file):
    ## Save prediction to subtitles file format
    with open(output_file, "w") as f:
        for i, chunk in enumerate(prediction):
            start_time = format_time(chunk['timestamp'][0])
            end_time = format_time(chunk['timestamp'][1])
            f.write(f"{i+1}\n")
            f.write(f"{start_time} --> {end_time}\n")
            f.write(f"{chunk['text']}\n")
            f.write("\n")

def format_time(seconds):
    hours = int(seconds // 3600)
    minutes = int((seconds % 3600) // 60)
    seconds = seconds % 60
    return f"{hours:02d}:{minutes:02d}:{seconds:04.1f}"