Skip to content

Commit

Permalink
fix: Use correct seek value in output, fix word timestamps when the…
Browse files Browse the repository at this point in the history
… initial timestamp is not zero (#1141)

Co-authored-by: Mahmoud Ashraf <[email protected]>
  • Loading branch information
heimoshuiyu and MahmoudAshraf97 authored Nov 15, 2024
1 parent 85e61ea commit 53bbe54
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions faster_whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def forward(self, features, chunks_metadata, **forward_params):
compression_ratio=get_compression_ratio(
self.tokenizer.decode(subsegment["tokens"])
),
seek=int(
chunk_metadata["start_time"] * self.model.frames_per_second
),
)
for subsegment in subsegments
]
Expand Down Expand Up @@ -496,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 @@ -1318,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 @@ -1585,7 +1588,7 @@ def add_word_timestamps(

for segment_idx, segment in enumerate(segments):
word_index = 0
time_offset = segment[0]["start"]
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 53bbe54

Please sign in to comment.