Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/desktop-gpui/locales/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,10 @@ cleanup = "Aufräumen"
cleanup_tooltip = "Füllwörter entfernen und Pausen kürzen"
delete_matches = "Alle löschen"
delete_matches_tooltip = "Jeden Treffer aus dem Video schneiden"
edit_hint = "Eingabetaste zum Speichern, Esc zum Abbrechen, Tab für das nächste Wort"
empty_description = "Transkribieren Sie diese Aufnahme auf diesem Computer und bearbeiten Sie dann das Video über seinen Text."
empty_title = "Noch kein Transkript"
hint = "Klicken Sie auf ein Wort, um dorthin zu springen. Wählen Sie Wörter aus und drücken Sie die Löschtaste, um sie aus dem Video zu schneiden."
hint = "Klicken Sie auf ein Wort, um dorthin zu springen, oder doppelklicken Sie, um es zu korrigieren. Wählen Sie Wörter aus und drücken Sie die Löschtaste, um sie aus dem Video zu schneiden."
next_match = "Nächster Treffer"
no_audio = "Diese Aufnahme hat keinen Ton zum Transkribieren."
no_speech = "Keine Sprache in dieser Aufnahme gefunden"
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop-gpui/locales/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2921,9 +2921,10 @@ cleanup = "Clean up"
cleanup_tooltip = "Remove filler words and shorten pauses"
delete_matches = "Delete all"
delete_matches_tooltip = "Cut every match from the video"
edit_hint = "Enter to save, Esc to cancel, Tab for the next word"
empty_description = "Transcribe this recording on this computer, then edit the video by editing its text."
empty_title = "No transcript yet"
hint = "Click a word to jump to it. Select words and press Delete to cut them from the video."
hint = "Click a word to jump to it, double-click to fix it. Select words and press Delete to cut them from the video."
next_match = "Next match"
no_audio = "This recording has no audio to transcribe."
no_speech = "No speech found in this recording"
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop-gpui/locales/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,10 @@ cleanup = "Limpiar"
cleanup_tooltip = "Quitar muletillas y acortar pausas"
delete_matches = "Eliminar todo"
delete_matches_tooltip = "Cortar del vídeo cada coincidencia"
edit_hint = "Intro para guardar, Esc para cancelar, Tab para la siguiente palabra"
empty_description = "Transcribe esta grabación en este ordenador y luego edita el vídeo editando su texto."
empty_title = "Aún no hay transcripción"
hint = "Haz clic en una palabra para ir a ella. Selecciona palabras y pulsa la tecla de borrar para cortarlas del vídeo."
hint = "Haz clic en una palabra para ir a ella o doble clic para corregirla. Selecciona palabras y pulsa la tecla de borrar para cortarlas del vídeo."
next_match = "Siguiente coincidencia"
no_audio = "Esta grabación no tiene audio que transcribir."
no_speech = "No se encontró voz en esta grabación"
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop-gpui/locales/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,10 @@ cleanup = "Nettoyer"
cleanup_tooltip = "Supprimer les mots de remplissage et raccourcir les pauses"
delete_matches = "Tout supprimer"
delete_matches_tooltip = "Couper chaque résultat de la vidéo"
edit_hint = "Entrée pour enregistrer, Échap pour annuler, Tab pour le mot suivant"
empty_description = "Transcrivez cet enregistrement sur cet ordinateur, puis modifiez la vidéo en modifiant son texte."
empty_title = "Pas encore de transcription"
hint = "Cliquez sur un mot pour y aller. Sélectionnez des mots et appuyez sur la touche Supprimer pour les couper de la vidéo."
hint = "Cliquez sur un mot pour y aller, double-cliquez pour le corriger. Sélectionnez des mots et appuyez sur la touche Supprimer pour les couper de la vidéo."
next_match = "Résultat suivant"
no_audio = "Cet enregistrement n'a pas d'audio à transcrire."
no_speech = "Aucune parole trouvée dans cet enregistrement"
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop-gpui/locales/hi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,10 @@ cleanup = "साफ़ करें"
cleanup_tooltip = "फ़िलर शब्द हटाएँ और ठहराव छोटे करें"
delete_matches = "सभी हटाएँ"
delete_matches_tooltip = "हर मिलान को वीडियो से काटें"
edit_hint = "सेव करने के लिए Enter, रद्द करने के लिए Esc, अगले शब्द के लिए Tab"
empty_description = "इस कंप्यूटर पर इस रिकॉर्डिंग को ट्रांसक्राइब करें, फिर उसका टेक्स्ट बदलकर वीडियो एडिट करें।"
empty_title = "अभी कोई ट्रांसक्रिप्ट नहीं"
hint = "किसी शब्द पर जाने के लिए उस पर क्लिक करें। शब्द चुनें और डिलीट कुंजी दबाएँ, वे वीडियो से कट जाएँगे।"
hint = "किसी शब्द पर जाने के लिए उस पर क्लिक करें, उसे ठीक करने के लिए डबल-क्लिक करें। शब्द चुनें और डिलीट कुंजी दबाएँ, वे वीडियो से कट जाएँगे।"
next_match = "अगला मिलान"
no_audio = "इस रिकॉर्डिंग में ट्रांसक्राइब करने के लिए कोई ऑडियो नहीं है।"
no_speech = "इस रिकॉर्डिंग में कोई बोली नहीं मिली"
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop-gpui/locales/ja.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,10 @@ cleanup = "クリーンアップ"
cleanup_tooltip = "フィラーを削除し、間を短くします"
delete_matches = "すべて削除"
delete_matches_tooltip = "一致した箇所をすべて動画からカットします"
edit_hint = "Enterで保存、Escでキャンセル、Tabで次の単語へ"
empty_description = "このコンピュータで録画を文字起こしすると、テキストを編集して動画を編集できます。"
empty_title = "文字起こしはまだありません"
hint = "単語をクリックするとその位置に移動します。単語を選択して削除キーを押すと、動画からカットされます。"
hint = "単語をクリックするとその位置に移動し、ダブルクリックすると修正できます。単語を選択して削除キーを押すと、動画からカットされます。"
next_match = "次の一致"
no_audio = "この録画には文字起こしできる音声がありません。"
no_speech = "この録画に発話は見つかりませんでした"
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop-gpui/locales/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,10 @@ cleanup = "清理"
cleanup_tooltip = "移除填充词并缩短停顿"
delete_matches = "全部删除"
delete_matches_tooltip = "从视频中剪掉所有匹配项"
edit_hint = "按 Enter 保存,按 Esc 取消,按 Tab 编辑下一个单词"
empty_description = "在这台电脑上转写此录制内容,然后通过编辑文字来编辑视频。"
empty_title = "还没有转写内容"
hint = "点击单词即可跳转。选中单词后按删除键,即可从视频中剪掉。"
hint = "点击单词即可跳转,双击即可修改。选中单词后按删除键,即可从视频中剪掉。"
next_match = "下一个匹配项"
no_audio = "此录制内容没有可转写的音频。"
no_speech = "此录制内容中未发现语音"
Expand Down
6 changes: 5 additions & 1 deletion apps/desktop-gpui/src/i18n/editor_shell_surface_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,9 +1125,13 @@ fn editor_shell_surfaces_match_the_literals_they_replaced() {
"the the, I I",
),
(tr::editor::transcript::fillers::title(), "Filler words"),
(
tr::editor::transcript::edit_hint(),
"Enter to save, Esc to cancel, Tab for the next word",
),
(
tr::editor::transcript::hint(),
"Click a word to jump to it. Select words and press Delete to cut them from the video.",
"Click a word to jump to it, double-click to fix it. Select words and press Delete to cut them from the video.",
),
(tr::editor::transcript::next_match(), "Next match"),
(
Expand Down
47 changes: 45 additions & 2 deletions apps/desktop-gpui/src/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ pub(crate) mod model;
#[cfg(test)]
mod tests;
mod view;
pub(crate) mod word_edit;

use std::cell::RefCell;
use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet};
use std::ops::Range;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Instant;

use cap_project::disfluency::DisfluencyKind;
use gpui::{FocusHandle, ListAlignment, ListState, TextLayout, px};
use gpui::{FocusHandle, ListAlignment, ListOffset, ListState, Pixels, Point, TextLayout, px};

use self::energy::EnergyEnvelope;
use self::model::{TranscriptDoc, TranscriptEdl};
Expand Down Expand Up @@ -61,6 +62,21 @@ impl WordSelection {
}
}

#[derive(Clone, Debug, PartialEq)]
pub(crate) struct WordEditor {
pub word: usize,
pub text: String,
pub start: f64,
}

/// Where the edited word sits inside its paragraph's text, measured when the
/// paragraph paints so the field lands exactly over it.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct WordAnchor {
pub origin: Point<Pixels>,
pub width: Pixels,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum DragUnit {
Word,
Expand Down Expand Up @@ -165,6 +181,12 @@ pub(crate) struct TranscriptState {
pub selection: Option<WordSelection>,
pub caret: Option<usize>,
pub drag: Option<WordDrag>,
pub editing: Option<WordEditor>,
pub edit_input: Option<gpui::Entity<crate::ui::TextInputState>>,
pub edit_anchor: Rc<Cell<Option<WordAnchor>>>,
/// The press that started this click restored a cut, so its double click
/// must not also open the word for editing.
pub restored_on_press: bool,
pub active: Option<usize>,
pub hovered_cut: Option<usize>,
pub user_scrolled: Option<Instant>,
Expand All @@ -190,6 +212,10 @@ impl TranscriptState {
selection: None,
caret: None,
drag: None,
editing: None,
edit_input: None,
edit_anchor: Rc::new(Cell::new(None)),
restored_on_press: false,
active: None,
hovered_cut: None,
user_scrolled: None,
Expand All @@ -216,6 +242,7 @@ impl TranscriptState {
let Some(captions) = project.captions.as_ref().filter(|_| has_words(project)) else {
let changed = self.doc.is_some();
self.doc = None;
self.editing = None;
self.edl = None;
self.list.reset(0);
self.selection = None;
Expand All @@ -231,7 +258,23 @@ impl TranscriptState {
.is_none_or(|doc| doc.signature != signature)
{
let doc = TranscriptDoc::build(captions);
if let Some(editing) = self.editing.as_mut() {
match word_edit::locate(&doc.words, editing.word, &editing.text, editing.start) {
Some(word) => {
editing.word = word;
editing.start = doc.words[word].start;
}
None => self.editing = None,
}
}
let scroll = self.doc.is_some().then(|| self.list.logical_scroll_top());
self.list.reset(doc.paragraphs.len());
if let Some(scroll) = scroll.filter(|_| !doc.paragraphs.is_empty()) {
self.list.scroll_to(ListOffset {
item_ix: scroll.item_ix.min(doc.paragraphs.len() - 1),
offset_in_item: scroll.offset_in_item,
});
}
self.layouts.borrow_mut().clear();
self.selection = None;
self.caret = None;
Expand Down
49 changes: 40 additions & 9 deletions apps/desktop-gpui/src/transcript/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,68 @@ pub fn captions_signature(captions: Option<&CaptionsData>) -> u64 {
}

pub fn flatten_words(captions: &CaptionsData) -> Vec<Word> {
flatten(captions, None)
}

/// Where each transcript word came from: the `(segment, word)` indices of the
/// caption words folded into it, its spoken word first.
pub fn word_sources(captions: &CaptionsData) -> (Vec<Word>, Vec<Vec<(usize, usize)>>) {
let mut sources = Vec::new();
let words = flatten(captions, Some(&mut sources));
(words, sources)
}

fn flatten(
captions: &CaptionsData,
mut sources: Option<&mut Vec<Vec<(usize, usize)>>>,
) -> Vec<Word> {
let mut words: Vec<Word> = Vec::new();
let mut raw: Vec<(&str, f64, f64)> = captions
let mut raw: Vec<(&str, f64, f64, (usize, usize))> = captions
.segments
.iter()
.flat_map(|segment| segment.words.iter())
.filter_map(|word| {
.enumerate()
.flat_map(|(segment_index, segment)| {
segment
.words
.iter()
.enumerate()
.map(move |(word_index, word)| (word, (segment_index, word_index)))
})
.filter_map(|(word, source)| {
let text = word.text.trim();
let (start, end) = (f64::from(word.start), f64::from(word.end));
(!text.is_empty() && start.is_finite() && end.is_finite()).then_some((
text,
start,
end.max(start),
source,
))
})
.collect();
raw.sort_by(|a, b| a.1.total_cmp(&b.1));
for (text, start, end) in raw {
for (text, start, end, source) in raw {
let spoken = !cap_project::disfluency::normalize_word(text).is_empty();
match words.last_mut() {
Some(previous) if !spoken || attaches_to_previous(text) => {
previous.text.push_str(text);
if spoken {
previous.end = previous.end.max(end);
}
if let Some(last) = sources.as_mut().and_then(|sources| sources.last_mut()) {
last.push(source);
}
}
_ if !spoken => {}
_ => words.push(Word {
text: text.to_string(),
start,
end,
}),
_ => {
words.push(Word {
text: text.to_string(),
start,
end,
});
if let Some(sources) = sources.as_mut() {
sources.push(vec![source]);
}
}
}
}
words
Expand Down
Loading
Loading