Skip to content

Commit

Permalink
Improve language detection when using clip_timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
ben91lin committed Jun 4, 2024
1 parent 65551c0 commit 1becddb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions faster_whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,24 @@ def transcribe(
or language_detection_segments < 1
):
language_detection_segments = 1
seek = 0
if isinstance(clip_timestamps, str):
start_timestamp = float(clip_timestamps.split(",")[0])
else:
start_timestamp = clip_timestamps[0]
detected_language_info = {}
seek = int(
start_timestamp * self.feature_extractor.sampling_rate
// self.feature_extractor.hop_length
)
content_frames = (
features.shape[-1] - self.feature_extractor.nb_max_frames
)
end_frames = (
seek + self.feature_extractor.nb_max_frames * language_detection_segments
)
while (
seek <= content_frames
and seek
< self.feature_extractor.nb_max_frames * language_detection_segments
and seek < end_frames
):
segment = features[
:, seek : seek + self.feature_extractor.nb_max_frames
Expand Down

0 comments on commit 1becddb

Please sign in to comment.