From a84ac408d4ce1f11eef33369f77d30c53cccc683 Mon Sep 17 00:00:00 2001 From: Louis-Fiacre Date: Wed, 18 Dec 2024 13:11:44 +0100 Subject: [PATCH] fix dot for local import module --- whisperx/SubtitlesProcessor.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/whisperx/SubtitlesProcessor.py b/whisperx/SubtitlesProcessor.py index 5ffd1afa..c0d8c9b3 100644 --- a/whisperx/SubtitlesProcessor.py +++ b/whisperx/SubtitlesProcessor.py @@ -1,5 +1,5 @@ import math -from conjunctions import get_conjunctions, get_comma +from .conjunctions import get_conjunctions, get_comma from typing import TextIO def normal_round(n): @@ -23,7 +23,7 @@ def format_timestamp(seconds: float, is_vtt: bool = False): milliseconds -= seconds * 1_000 separator = '.' if is_vtt else ',' - + hours_marker = f"{hours:02d}:" return ( f"{hours_marker}{minutes:02d}:{seconds:02d}{separator}{milliseconds:03d}" @@ -78,7 +78,7 @@ def process_segments(self, advanced_splitting=True): subtitles = [] for i, segment in enumerate(self.segments): next_segment_start_time = self.segments[i + 1]['start'] if i + 1 < len(self.segments) else None - + if advanced_splitting: split_points = self.determine_advanced_split_points(segment, next_segment_start_time) @@ -138,10 +138,10 @@ def determine_advanced_split_points(self, segment, next_segment_start_time=None) return split_points - + def generate_subtitles_from_split_points(self, segment, split_points, next_start_time=None): subtitles = [] - + words = segment.get('words', segment['text'].split()) total_word_count = len(words) total_time = segment['end'] - segment['start'] @@ -152,7 +152,7 @@ def generate_subtitles_from_split_points(self, segment, split_points, next_start fragment_words = words[start_idx:split_point + 1] current_word_count = len(fragment_words) - + if isinstance(fragment_words[0], dict): start_time = fragment_words[0]['start'] @@ -173,14 +173,14 @@ def generate_subtitles_from_split_points(self, segment, split_points, next_start 'end': end_time, 'text': fragment if not isinstance(fragment_words[0], dict) else prefix.join(word['word'] for word in fragment_words) }) - + start_idx = split_point + 1 # Handle the last fragment if start_idx < len(words): fragment_words = words[start_idx:] current_word_count = len(fragment_words) - + if isinstance(fragment_words[0], dict): start_time = fragment_words[0]['start'] end_time = fragment_words[-1]['end'] @@ -198,13 +198,13 @@ def generate_subtitles_from_split_points(self, segment, split_points, next_start 'end': end_time if end_time is not None else segment['end'], 'text': fragment if not isinstance(fragment_words[0], dict) else prefix.join(word['word'] for word in fragment_words) }) - + return subtitles - + def save(self, filename="subtitles.srt", advanced_splitting=True): - + subtitles = self.process_segments(advanced_splitting) def write_subtitle(file, idx, start_time, end_time, text): @@ -216,7 +216,7 @@ def write_subtitle(file, idx, start_time, end_time, text): with open(filename, 'w', encoding='utf-8') as file: if self.is_vtt: file.write("WEBVTT\n\n") - + if advanced_splitting: for idx, subtitle in enumerate(subtitles, 1): start_time = format_timestamp(subtitle['start'], self.is_vtt) @@ -224,4 +224,4 @@ def write_subtitle(file, idx, start_time, end_time, text): text = subtitle['text'].strip() write_subtitle(file, idx, start_time, end_time, text) - return len(subtitles) \ No newline at end of file + return len(subtitles)