Skip to content
3 changes: 3 additions & 0 deletions apps/desktop-gpui/locales/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,7 @@ model_downloaded = "Modell {model} heruntergeladen"
model_label = "Modell"
model_updated = "Empfohlenes Modell aktualisiert"
model_updated_description = "Wir empfehlen die neue Version. Sie ist genauer und erkennt auch kurze Aufnahmen, die der alten entgangen sind."
new_caption = "Neuer Untertitel"
position = "Position"
refining_word_timings = "Wort-Timings werden verfeinert…"
regenerate = "Untertitel neu erstellen"
Expand Down Expand Up @@ -2908,6 +2909,7 @@ video = "Video"
zoom = "Zoom"

[editor.transcript]
add_caption = "Untertitel am Abspielkopf hinzufügen"
cleanup = "Aufräumen"
cleanup_tooltip = "Füllwörter entfernen und Pausen kürzen"
delete_matches = "Alle löschen"
Expand Down Expand Up @@ -2967,6 +2969,7 @@ audio_segment_changed = "Dieses Audiosegment hat sich geändert. Wählen Sie es
crop = "Zuschneiden"
crop_tooltip = "Video zuschneiden"
no_room_for_3d_shot = "Kein Platz für eine weitere 3D-Einstellung"
no_room_for_caption = "Hier ist kein Platz für einen weiteren Untertitel"
redo = "Wiederholen"
save_failed = "{path} konnte nicht gespeichert werden. Lassen Sie den Editor geöffnet und versuchen Sie es erneut: {error}"
undo = "Rückgängig"
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-gpui/locales/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,7 @@ model_downloaded = "{model} model downloaded"
model_label = "Model"
model_updated = "Recommended model updated"
model_updated_description = "We recommend the new version. It is more accurate and catches short recordings the old one missed."
new_caption = "New caption"
position = "Position"
refining_word_timings = "Refining word timings…"
regenerate = "Regenerate Captions"
Expand Down Expand Up @@ -2910,6 +2911,7 @@ video = { text = "Video", context = "Timeline gutter label of the recording's vi
zoom = "Zoom"

[editor.transcript]
add_caption = "Add caption at playhead"
cleanup = "Clean up"
cleanup_tooltip = "Remove filler words and shorten pauses"
delete_matches = "Delete all"
Expand Down Expand Up @@ -2969,6 +2971,7 @@ audio_segment_changed = "This audio segment changed. Select it and choose a repl
crop = "Crop"
crop_tooltip = "Crop Video"
no_room_for_3d_shot = "No room for another 3D shot"
no_room_for_caption = "No room for another caption here"
redo = "Redo"
save_failed = { text = "Could not save {path}. Keep the editor open and try again: {error}", context = "{path} is the recording's folder; {error} is a technical message that stays in English." }
undo = "Undo"
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-gpui/locales/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,7 @@ model_downloaded = "Modelo {model} descargado"
model_label = "Modelo"
model_updated = "Modelo recomendado actualizado"
model_updated_description = "Te recomendamos la nueva versión. Es más precisa y transcribe grabaciones cortas que la anterior pasaba por alto."
new_caption = "Subtítulo nuevo"
position = "Posición"
refining_word_timings = "Ajustando los tiempos de las palabras…"
regenerate = "Regenerar subtítulos"
Expand Down Expand Up @@ -2908,6 +2909,7 @@ video = "Vídeo"
zoom = "Zoom"

[editor.transcript]
add_caption = "Añadir subtítulo en el cabezal"
cleanup = "Limpiar"
cleanup_tooltip = "Quitar muletillas y acortar pausas"
delete_matches = "Eliminar todo"
Expand Down Expand Up @@ -2967,6 +2969,7 @@ audio_segment_changed = "Este segmento de audio cambió. Selecciónalo y vuelve
crop = "Recortar"
crop_tooltip = "Recortar vídeo"
no_room_for_3d_shot = "No hay espacio para otra toma 3D"
no_room_for_caption = "No hay espacio para otro subtítulo aquí"
redo = "Rehacer"
save_failed = "No se pudo guardar {path}. Mantén el editor abierto e inténtalo de nuevo: {error}"
undo = "Deshacer"
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-gpui/locales/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,7 @@ model_downloaded = "Modèle {model} téléchargé"
model_label = "Modèle"
model_updated = "Modèle recommandé mis à jour"
model_updated_description = "Nous recommandons la nouvelle version. Elle est plus précise et transcrit les enregistrements courts que l'ancienne ne captait pas."
new_caption = "Nouveau sous-titre"
position = "Position"
refining_word_timings = "Affinage du minutage des mots…"
regenerate = "Régénérer les sous-titres"
Expand Down Expand Up @@ -2908,6 +2909,7 @@ video = "Vidéo"
zoom = "Zoom"

[editor.transcript]
add_caption = "Ajouter un sous-titre à la tête de lecture"
cleanup = "Nettoyer"
cleanup_tooltip = "Supprimer les mots de remplissage et raccourcir les pauses"
delete_matches = "Tout supprimer"
Expand Down Expand Up @@ -2967,6 +2969,7 @@ audio_segment_changed = "Ce segment audio a changé. Sélectionnez-le et choisis
crop = "Recadrer"
crop_tooltip = "Recadrer la vidéo"
no_room_for_3d_shot = "Plus de place pour un autre plan 3D"
no_room_for_caption = "Pas de place pour un autre sous-titre ici"
redo = "Rétablir"
save_failed = "Impossible d'enregistrer {path}. Gardez l'éditeur ouvert et réessayez : {error}"
undo = "Annuler"
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-gpui/locales/hi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,7 @@ model_downloaded = "{model} मॉडल डाउनलोड हो गया"
model_label = "मॉडल"
model_updated = "सुझाया गया मॉडल अपडेट हुआ"
model_updated_description = "हम नया वर्ज़न इस्तेमाल करने की सलाह देते हैं। यह ज़्यादा सटीक है और उन छोटी रिकॉर्डिंग को भी पकड़ता है जो पुराने वर्ज़न से छूट जाती थीं।"
new_caption = "नया कैप्शन"
position = "पोज़िशन"
refining_word_timings = "शब्दों का समय सुधारा जा रहा है…"
regenerate = "कैप्शन दोबारा बनाएँ"
Expand Down Expand Up @@ -2908,6 +2909,7 @@ video = "वीडियो"
zoom = "ज़ूम"

[editor.transcript]
add_caption = "प्लेहेड पर कैप्शन जोड़ें"
cleanup = "साफ़ करें"
cleanup_tooltip = "फ़िलर शब्द हटाएँ और ठहराव छोटे करें"
delete_matches = "सभी हटाएँ"
Expand Down Expand Up @@ -2967,6 +2969,7 @@ audio_segment_changed = "यह ऑडियो सेगमेंट बदल
crop = "क्रॉप"
crop_tooltip = "वीडियो क्रॉप करें"
no_room_for_3d_shot = "एक और 3D शॉट के लिए जगह नहीं है"
no_room_for_caption = "यहाँ एक और कैप्शन के लिए जगह नहीं है"
redo = "फिर करें"
save_failed = "{path} सेव नहीं हो सका। एडिटर खुला रखें और फिर से कोशिश करें: {error}"
undo = "पहले जैसा करें"
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-gpui/locales/ja.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,7 @@ model_downloaded = "{model}モデルをダウンロード済み"
model_label = "モデル"
model_updated = "推奨モデルを更新しました"
model_updated_description = "新しいバージョンをおすすめします。より正確になり、以前のバージョンでは聞き取れなかった短い録画も文字起こしできます。"
new_caption = "新しい字幕"
position = "位置"
refining_word_timings = "単語のタイミングを調整中…"
regenerate = "字幕を再生成"
Expand Down Expand Up @@ -2908,6 +2909,7 @@ video = "動画"
zoom = "ズーム"

[editor.transcript]
add_caption = "再生ヘッドに字幕を追加"
cleanup = "クリーンアップ"
cleanup_tooltip = "フィラーを削除し、間を短くします"
delete_matches = "すべて削除"
Expand Down Expand Up @@ -2967,6 +2969,7 @@ audio_segment_changed = "この音声セグメントは変更されました。
crop = "切り抜き"
crop_tooltip = "動画を切り抜く"
no_room_for_3d_shot = "別の3Dショットを入れる余地がありません"
no_room_for_caption = "ここには字幕を追加する余地がありません"
redo = "やり直す"
save_failed = "{path}を保存できませんでした。エディタを開いたまま、もう一度お試しください:{error}"
undo = "取り消す"
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-gpui/locales/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,7 @@ model_downloaded = "已下载“{model}”模型"
model_label = "模型"
model_updated = "推荐模型已更新"
model_updated_description = "推荐使用新版本。它更准确,还能转写旧版本漏掉的短录制内容。"
new_caption = "新字幕"
position = "位置"
refining_word_timings = "正在优化单词时间…"
regenerate = "重新生成字幕"
Expand Down Expand Up @@ -2908,6 +2909,7 @@ video = "视频"
zoom = "缩放"

[editor.transcript]
add_caption = "在播放头处添加字幕"
cleanup = "清理"
cleanup_tooltip = "移除填充词并缩短停顿"
delete_matches = "全部删除"
Expand Down Expand Up @@ -2967,6 +2969,7 @@ audio_segment_changed = "此音频分段已更改。请选中它并重新选择
crop = "裁剪"
crop_tooltip = "裁剪视频"
no_room_for_3d_shot = "没有空间再添加 3D 镜头"
no_room_for_caption = "这里没有空间再添加字幕"
redo = "重做"
save_failed = "无法保存 {path}。请保持编辑器打开并重试:{error}"
undo = "撤销"
Expand Down
216 changes: 216 additions & 0 deletions apps/desktop-gpui/src/editor_edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,83 @@ pub fn insert_scene_segment(timeline: &mut TimelineConfiguration, segment: Scene
index
}

pub const NEW_CAPTION_LENGTH: f64 = 2.0;

pub const MIN_ADDED_CAPTION: f64 = 0.25;

/// Adds a caption with no word timings over `output`, in edited-timeline
/// seconds, to the source-time captions, and switches captions on. Returns
/// its index in `captions.segments`.
///
/// It is written in recording time like every other caption, so it stays on
/// its moment as clips are trimmed, cut or moved. It ends where its clip does:
/// past that point the recording jumps, and the caption would land on footage
/// it was never placed over. `None` when the clip leaves less than
/// [`MIN_ADDED_CAPTION`] of room, as inside a fullscreen text hold, or when
/// legacy captions cannot be moved to recording time yet.
pub fn add_caption_segment(
project: &mut ProjectConfiguration,
output: std::ops::Range<f64>,
id: String,
text: &str,
recording_durations: &[f64],
) -> Option<usize> {
let timeline = project.timeline.as_ref()?;
let holds = timeline.hold_windows();
if holds
.iter()
.any(|(start, end)| output.start >= *start && output.start < *end)
{
return None;
}
let effective = |time: f64| time - held_time_before(&holds, time);
let (start, end) = (effective(output.start), effective(output.end));
Comment thread
richiemcilroy marked this conversation as resolved.
Resolved
let mappings = crate::transcript::model::build_mappings(timeline, recording_durations);
let mapping = mappings
[..mappings.partition_point(|mapping| mapping.effective_start <= start + 1e-9)]
.last()?;
let start = start.max(mapping.effective_start);
let end = end.min(mapping.effective_end());
if !start.is_finite() || !end.is_finite() || end - start < MIN_ADDED_CAPTION {
return None;
}
let source = |time: f64| {
(mapping.source_start + (time - mapping.effective_start) * mapping.timescale) as f32
};
let (source_start, source_end) = (source(start), source(end));
if project
.captions
.as_ref()
.is_some_and(|captions| !captions.source_timed)
{
cap_project::synchronize_captions(project, recording_durations);
}
let captions = project
.captions
.get_or_insert_with(|| cap_project::CaptionsData {
source_timed: true,
..Default::default()
});
if !captions.source_timed {
return None;
}
captions.settings.enabled = true;
let index = captions
.segments
.partition_point(|segment| segment.start <= source_start);
captions.segments.insert(
index,
cap_project::CaptionSegment {
id,
start: source_start,
end: source_end,
text: text.to_string(),
words: Vec::new(),
},
);
Some(index)
}

pub fn find_placement<T: TrackSegmentOps>(
segments: &[T],
time: f64,
Expand Down Expand Up @@ -5788,3 +5865,142 @@ mod style_image_replacement_tests {
);
}
}

#[cfg(test)]
mod add_caption_tests {
use super::*;

fn project(timeline: serde_json::Value) -> ProjectConfiguration {
serde_json::from_value(serde_json::json!({ "timeline": timeline })).unwrap()
}

fn add(project: &mut ProjectConfiguration, output: std::ops::Range<f64>) -> Option<usize> {
add_caption_segment(project, output, "caption-test".into(), "Hello", &[10.0])
}

fn source(project: &ProjectConfiguration) -> Vec<(String, f32, f32)> {
project
.captions
.as_ref()
.unwrap()
.segments
.iter()
.map(|segment| (segment.text.clone(), segment.start, segment.end))
.collect()
}

fn track(project: &mut ProjectConfiguration) -> Vec<(String, f64, f64)> {
cap_project::synchronize_captions(project, &[10.0]);
project
.timeline
.as_ref()
.unwrap()
.caption_segments
.iter()
.map(|segment| (segment.text.clone(), segment.start, segment.end))
.collect()
}

#[test]
fn a_caption_with_no_transcript_turns_captions_on_in_recording_time() {
let mut project = project(serde_json::json!({
"segments": [{ "start": 0.0, "end": 10.0, "timescale": 1.0 }],
"zoomSegments": []
}));
assert_eq!(add(&mut project, 1.0..3.0), Some(0));
let captions = project.captions.as_ref().unwrap();
assert!(captions.settings.enabled && captions.source_timed);
assert!(captions.segments[0].words.is_empty());
assert_eq!(captions.segments[0].id, "caption-test");
assert_eq!(track(&mut project), [("Hello".to_string(), 1.0, 3.0)]);
}

#[test]
fn a_caption_follows_clip_speed_and_stops_at_its_clip_edge() {
let mut project = project(serde_json::json!({
"segments": [
{ "start": 0.0, "end": 4.0, "timescale": 2.0 },
{ "start": 6.0, "end": 10.0, "timescale": 1.0 }
],
"zoomSegments": []
}));
assert_eq!(add(&mut project, 0.5..1.5), Some(0));
assert_eq!(add(&mut project, 1.5..3.5), Some(1));
assert_eq!(add(&mut project, 4.0..6.0), Some(2));
assert_eq!(
source(&project),
[
("Hello".to_string(), 1.0, 3.0),
("Hello".to_string(), 3.0, 4.0),
("Hello".to_string(), 8.0, 10.0),
]
);
assert_eq!(
track(&mut project),
[
("Hello".to_string(), 0.5, 1.5),
("Hello".to_string(), 1.5, 2.0),
("Hello".to_string(), 4.0, 6.0),
]
);
assert_eq!(add(&mut project, 1.9..3.0), None);
}

#[test]
fn a_caption_under_a_fullscreen_hold_is_refused() {
let mut project = project(serde_json::json!({
"segments": [{ "start": 0.0, "end": 10.0, "timescale": 1.0 }],
"zoomSegments": [],
"textSegments": [{ "start": 2.0, "end": 4.0, "layout": "fullscreen" }]
}));
assert_eq!(add(&mut project, 2.5..3.5), None);
assert_eq!(add(&mut project, 3.0..5.0), None);
assert_eq!(add(&mut project, 2.0..4.5), None);
assert!(project.captions.is_none());
assert_eq!(add(&mut project, 4.0..6.0), Some(0));
assert_eq!(source(&project), [("Hello".to_string(), 2.0, 4.0)]);
assert_eq!(track(&mut project), [("Hello".to_string(), 4.0, 6.0)]);
}

#[test]
fn a_caption_inside_a_later_cut_leaves_with_it_and_comes_back_on_restore() {
let mut project = project(serde_json::json!({
"segments": [{ "start": 0.0, "end": 10.0, "timescale": 1.0 }],
"zoomSegments": []
}));
assert_eq!(add(&mut project, 4.0..5.0), Some(0));
let uncut = project.clone();
let timeline = project.timeline.as_mut().unwrap();
crate::transcript::cuts::apply_source_cuts(timeline, &[10.0], &[3.5..5.5]);
assert!(track(&mut project).is_empty());
assert_eq!(source(&project), [("Hello".to_string(), 4.0, 5.0)]);
let mut restored = uncut;
assert_eq!(track(&mut restored), [("Hello".to_string(), 4.0, 5.0)]);
}

#[test]
fn legacy_output_time_captions_move_to_recording_time_first() {
let mut project: ProjectConfiguration = serde_json::from_value(serde_json::json!({
"timeline": {
"segments": [
{ "start": 0.0, "end": 4.0, "timescale": 1.0 },
{ "start": 6.0, "end": 10.0, "timescale": 1.0 }
],
"zoomSegments": []
},
"captions": {
"segments": [{ "id": "segment-0", "start": 5.0, "end": 6.0, "text": "old" }],
"settings": {}
}
}))
.unwrap();
assert_eq!(add(&mut project, 1.0..2.0), Some(0));
assert_eq!(
source(&project),
[
("Hello".to_string(), 1.0, 2.0),
("old".to_string(), 7.0, 8.0),
]
);
}
}
Loading
Loading