Skip to content

Commit

Permalink
Improve language detection when using clip_timestamps (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben91lin authored Jul 1, 2024
1 parent 8d400e9 commit 8862bee
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions faster_whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,27 @@ def transcribe(
or language_detection_segments < 1
):
language_detection_segments = 1
seek = 0
detected_language_info = {}
start_timestamp = (
float(clip_timestamps.split(",")[0])
if isinstance(clip_timestamps, str)
else clip_timestamps[0]
)
content_frames = (
features.shape[-1] - self.feature_extractor.nb_max_frames
)
while (
seek <= content_frames
and seek
< self.feature_extractor.nb_max_frames * language_detection_segments
):
seek = (
int(start_timestamp * self.frames_per_second)
if start_timestamp * self.frames_per_second < content_frames
else 0
)
end_frames = min(
seek
+ self.feature_extractor.nb_max_frames
* language_detection_segments,
content_frames,
)
detected_language_info = {}
while seek < end_frames:
segment = features[
:, seek : seek + self.feature_extractor.nb_max_frames
]
Expand Down

0 comments on commit 8862bee

Please sign in to comment.