Skip to content

Commit

Permalink
use correct seek for sequential and batched segments
Browse files Browse the repository at this point in the history
  • Loading branch information
MahmoudAshraf97 authored Nov 15, 2024
1 parent 98c1487 commit b5da5e8
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions faster_whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ def forward(self, features, chunks_metadata, **forward_params):
compression_ratio=get_compression_ratio(
self.tokenizer.decode(subsegment["tokens"])
),
seek=seek,
seek=int(
chunk_metadata["start_time"] * self.model.frames_per_second
),
)
for subsegment in subsegments
]
Expand Down Expand Up @@ -497,7 +499,7 @@ def _batched_segments_generator(
for segment in result:
seg_idx += 1
yield Segment(
seek=int(result[-1]["end"] * self.model.frames_per_second),
seek=segment["seek"],
id=seg_idx,
text=segment["text"],
start=round(segment["start"], 3),
Expand Down Expand Up @@ -1319,7 +1321,7 @@ def next_words_segment(segments: List[dict]) -> Optional[dict]:

yield Segment(
id=idx,
seek=seek,
seek=previous_seek,
start=segment["start"],
end=segment["end"],
text=text,
Expand Down Expand Up @@ -1586,11 +1588,7 @@ def add_word_timestamps(

for segment_idx, segment in enumerate(segments):
word_index = 0
time_offset = (
segment[0]["seek"]
* self.feature_extractor.hop_length
/ self.feature_extractor.sampling_rate
)
time_offset = segment[0]["seek"] / self.frames_per_second
median_duration, max_duration = median_max_durations[segment_idx]
for subsegment_idx, subsegment in enumerate(segment):
saved_tokens = 0
Expand Down

0 comments on commit b5da5e8

Please sign in to comment.