Repository: SYSTRAN/faster-whisper

Issue:
Output timestamps not correct. I want it same like input clip_timestamps.
I have a sentences timestamp. I want result use this timestamp

segments, info =       batched_model.transcribe(
            "/content/drive/MyDrive/0/tool_gemini/video/QaCPwYO5vYs/originVideo/videoplayback.opus",
            language="vi",
            vad_filter=False,
            clip_timestamps=[{'start':0.0, 'end': 5.667},{'start': 5.667,  'end':10.5333}],{'start': 10.5333,  'end':16.867}],
            beam_size=1,
            batch_size=32
        )
result 
[0.0->16.867] text


I want 
[0.0->5.667] text
[5.667->10.5333] text
[10.5333->16.867] text

How?.




Discussion:
you can do this now on the main branch



Patch:
diff --git a/faster_whisper/transcribe.py b/faster_whisper/transcribe.py
index 382c77cb..a73b31b5 100644
--- a/faster_whisper/transcribe.py
+++ b/faster_whisper/transcribe.py
@@ -417,15 +417,27 @@ def transcribe(
                     "No clip timestamps found. "
                     "Set 'vad_filter' to True or provide 'clip_timestamps'."
                 )
+
+            audio_chunks, chunks_metadata = collect_chunks(
+                audio, clip_timestamps, max_duration=chunk_length
+            )
+
         else:
             clip_timestamps = [
                 {k: int(v * sampling_rate) for k, v in segment.items()}
                 for segment in clip_timestamps
             ]
 
-        audio_chunks, chunks_metadata = collect_chunks(
-            audio, clip_timestamps, max_duration=chunk_length
-        )
+            audio_chunks, chunks_metadata = [], []
+            for clip in clip_timestamps:
+                audio_chunks.append(audio[clip["start"] : clip["end"]])
+                chunks_metadata.append(
+                    {
+                        "offset": clip["start"] / sampling_rate,
+                        "duration": (clip["end"] - clip["start"]) / sampling_rate,
+                        "segments": [clip],
+                    }
+                )
 
         duration_after_vad = (
             sum((segment["end"] - segment["start"]) for segment in clip_timestamps)


Test patch:
diff --git a/tests/test_transcribe.py b/tests/test_transcribe.py
index d3d9270d..48b409eb 100644
--- a/tests/test_transcribe.py
+++ b/tests/test_transcribe.py
@@ -269,3 +269,24 @@ def test_monotonic_timestamps(physcisworks_path):
             assert word.start <= word.end
             assert word.end <= segments[i].end
     assert segments[-1].end <= info.duration
+
+
+def test_cliptimestamps_segments(jfk_path):
+    model = WhisperModel("tiny")
+    pipeline = BatchedInferencePipeline(model=model)
+
+    audio = decode_audio(jfk_path)
+    audio = np.concatenate([audio, audio])
+    clip_timestamps = [{"start": 0.0, "end": 11.0}, {"start": 11.0, "end": 22.0}]
+
+    segments, info = pipeline.transcribe(audio, clip_timestamps=clip_timestamps)
+    segments = list(segments)
+
+    assert len(segments) == 2
+    for segment, clip in zip(segments, clip_timestamps):
+        assert segment.start == clip["start"]
+        assert segment.end == clip["end"]
+        assert segment.text == (
+            " And so my fellow Americans ask not what your country can do for you, "
+            "ask what you can do for your country."
+        )