Skip to content
Draft
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
154 changes: 154 additions & 0 deletions modules/shell/scripts/e2e_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6059,6 +6059,159 @@ def page(folder):
check("the naming is logged, never a name", lines and not any(name in line for line in lines for name in ("Sarah", "équipe", "Camille")), lines)


def speakers_by_line(now: dt.datetime) -> None:
"""DJ. D131, #1230's S2: each line of a complete transcript says who spoke, named by the user. Its speaker, a button
on the line, opens « Qui parle sur cette ligne ? »: a name given to this line alone gives it a voice of the
person's own (`transcript/v1`'s `voice` and `given`, #1244), its name in `speakers.json`'s `voices`; « Toutes les
lignes de cette voix » names every line of it; Escape closes it as it was; a blank name is said under the field,
what was typed kept; the field stays when the window comes back. Each line's speaker follows its line in the
order of Tab (D62). By keyboard alone; axe on the open field. No name is logged."""
print("DJ. each line of a transcript named by the user: one line, or a voice everywhere (D131)")
meetings = WORK / "speakers-by-line"
meeting = meetings / "2026-11-30_14-00"
session(meeting, now - dt.timedelta(hours=2), 1, {}, form="v3")
# A sound that plays, as AB's: each line a button in the order of Tab, one at a time (D26, D62).
with wave.open(str(meeting / "local.wav"), "wb") as made:
made.setparams((2, 3, 48000, 0, "NONE", "not compressed"))
made.writeframes(bytes(6 * 48000 * 10))
(meeting / "clock.jsonl").write_text('{"track":"local","sample":0,"at":0.0}\n')
record = json.loads((meeting / "session.json").read_text())
(meeting / "session.json").write_text(json.dumps(record | {"tracks": {"local": {"device": "Mic"}}}))
current = meeting / "transcript.jsonl"
current.write_text(
'{"type":"header","contract":"transcript/v1","engine":"whisper.cpp","model":"m","language":null,"context":null}\n'
'{"type":"segment","speaker":"me","track":"local","voice":null,"start":0.0,"end":1.0,"text":"On commence."}\n'
'{"type":"segment","speaker":"others","track":"remote","voice":null,"start":1.5,"end":3.0,"text":"Les tests passent."}\n'
'{"type":"segment","speaker":"others","track":"remote","voice":null,"start":3.5,"end":5.0,"text":"Je confirme pour la 2.4."}\n'
'{"type":"segment","speaker":"others","track":"remote","voice":null,"start":5.5,"end":7.0,"text":"Et la démo vendredi."}\n'
'{"type":"complete","duration":7.0}\n')
whos = "return [...document.querySelectorAll('#meeting .transcript .lines .who')].map(w => w.textContent.trim())"
held = lambda: [json.loads(line) for line in current.read_text().splitlines() if line.strip()]
voices = lambda: (json.loads((meeting / "speakers.json").read_text()) if (meeting / "speakers.json").is_file() else {}).get("voices")
panel_open = lambda b: bool(b.find_elements(By.ID, "voice-name"))
window = Window(meetings, "fr_FR.UTF-8", 'after = "nothing"\nreminder = false\n')
with window as browser:
def page():
browser.execute_script("location.hash = '#/'")
wait_for(browser, lambda b: not b.find_elements(By.ID, "meeting"), 5)
browser.execute_script("location.hash = arguments[0]", f"#/meeting/{meeting.name}")
return wait_for(browser, lambda b: b.execute_script(
"return document.querySelectorAll('#meeting .transcript .lines .who').length") > 0, 15)

# Each line's speaker by its id, never a reference held across a redraw: absent, None.
def who(index):
found = browser.execute_script("return [...document.querySelectorAll('#meeting .transcript .lines .who')].map(w => w.id)")
return found[index] if index < len(found) and found[index] else None

def focused_on(index):
return who(index) is not None and browser.execute_script("return document.activeElement?.id") == who(index)

def name(index, typed, everywhere=False, key=Keys.ENTER):
"""Line `index`'s speaker by keyboard alone: focused, Enter, the scope chosen, the name typed, `key`."""
if who(index) is None:
return False
browser.execute_script("document.getElementById(arguments[0]).focus()", who(index))
ActionChains(browser).send_keys(Keys.ENTER).perform()
if not wait_for(browser, panel_open, 5):
return False
if everywhere and browser.find_elements(By.ID, "voice-all"):
browser.execute_script("document.getElementById('voice-all').click(); document.getElementById('voice-name').focus()")
field = browser.find_element(By.ID, "voice-name")
field.send_keys(Keys.CONTROL, "a")
field.send_keys(typed)
ActionChains(browser).send_keys(key).perform()
# A name the meeting already holds is offered under the field: the first Enter takes the suggestion, as a
# combobox's does (APG), the next one saves.
if not wait_for(browser, lambda b: not panel_open(b), 1.5) and panel_open(browser):
ActionChains(browser).send_keys(key).perform()
return wait_for(browser, lambda b: not panel_open(b), 5)

page()
tags = browser.execute_script("return [...document.querySelectorAll('#meeting .transcript .lines .who')].map(w => w.tagName)")
check("each line's speaker is a button, its side as the page says it",
browser.execute_script(whos) == ["Vous", "Les autres", "Les autres", "Les autres"] and set(tags) == {"BUTTON"},
[browser.execute_script(whos), tags])
if who(2) is not None:
browser.execute_script("document.getElementById(arguments[0]).focus()", who(2))
ActionChains(browser).send_keys(Keys.ENTER).perform()
opened = wait_for(browser, panel_open, 5)
got = browser.execute_script(
"const f = document.getElementById('voice-name'); return f ? [document.activeElement.id, f.labels[0]?.textContent.trim(),"
" document.getElementById('voice-line')?.checked, document.getElementById(arguments[0] ?? '')?.getAttribute('aria-expanded')] : null", who(2))
check("Enter on a line's speaker opens « Qui parle sur cette ligne ? », its field focused and labelled, « Cette ligne seulement » chosen",
opened and got == ["voice-name", "Qui parle sur cette ligne\u202f?", True, "true"], got)
violations = axe_violations(browser) if opened else [("the field absent", None, 0, [])]
check("axe: the open field, WCAG 2.2 A and AA, no violation", violations == [], violations)
typed = "return document.getElementById('voice-name')?.value ?? null"
said_now = "const s = document.getElementById('voice-said'); return s && !s.hidden ? s.textContent : ''"
# Nothing but spaces: said under the field, what was typed kept, nothing written.
ActionChains(browser).send_keys(" ").perform()
ActionChains(browser).send_keys(Keys.ENTER).perform()
shown = wait_for(browser, lambda b: b.execute_script(said_now), 5)
check("a blank name: « Saisissez un nom, ou appuyez sur Échap pour annuler. » under the field, what was typed kept, nothing written",
shown and browser.execute_script(said_now) == "Saisissez un nom, ou appuyez sur Échap pour annuler."
and browser.execute_script(typed) == " " and all("given" not in line for line in held()) and voices() is None,
[browser.execute_script(said_now), browser.execute_script(typed), voices()])
browser.execute_script("document.getElementById('voice-name')?.select()")
ActionChains(browser).send_keys("Personne").perform()
# Back to the window while typing (window.js's focus draws the page anew): the field and what is typed stay.
browser.execute_script("window.dispatchEvent(new Event('focus'))")
time.sleep(1.5)
check("back to the window while naming: the field stays, what was typed kept",
browser.execute_script(typed) == "Personne", browser.execute_script(typed))
if browser.find_elements(By.ID, "voice-name"):
browser.execute_script("document.getElementById('voice-name').focus()")
ActionChains(browser).send_keys(Keys.ESCAPE).perform()
closed = wait_for(browser, lambda b: not panel_open(b), 5)
check("Escape closes it as it was: nothing written, the focus back on the line's speaker",
closed and all("given" not in line for line in held()) and voices() is None
and focused_on(2),
[closed, voices(), browser.execute_script("return document.activeElement?.className")])

# Criterion 1: one line named, that line alone.
done = name(2, "Maya")
lines = held()
check("a name given to one line: that line alone takes it, its voice the person's own (#1), given the instant",
done and browser.execute_script(whos) == ["Vous", "Les autres", "Maya", "Les autres"]
and [line.get("voice") for line in lines[1:5]] == [None, None, "#1", None]
and bool(lines[3].get("given")) and voices() == {"remote/#1": "Maya"},
[browser.execute_script(whos), [line.get("voice") for line in lines[1:5]], voices()])
check("saved: the focus back on that line's speaker", focused_on(2), browser.execute_script("return document.activeElement?.id"))
named = browser.execute_script("return document.getElementById(arguments[0] ?? '')?.getAttribute('aria-label') ?? null", who(2))
check("its accessible name holds the name shown, then what pressing it does (WCAG 2.5.3)",
named == "Maya\u00a0: changer qui parle à 00:03", named)
# D62's order of Tab: one line in it, its speaker with it; the arrows move both.
tabs = ("return [...document.querySelectorAll('#meeting .transcript .lines li')].map(l => [l.getAttribute('role'), l.tabIndex,"
" l.querySelector('button.who')?.tabIndex])")
rows = browser.execute_script(tabs)
browser.execute_script("document.querySelector('#meeting .transcript .lines li[tabindex=\"0\"]')?.focus()")
ActionChains(browser).send_keys(Keys.ARROW_DOWN).perform()
moved = browser.execute_script(tabs)
check("each line's speaker follows its line in the order of Tab, one line at a time, the arrows moving both (D62)",
bool(rows) and all(role == "button" for role, *_ in rows) and all(line == who_ for _, line, who_ in rows)
and [line for _, line, _ in rows].count(0) == 1 and all(line == who_ for _, line, who_ in moved) and moved != rows,
[rows, moved])

done = name(3, "Maya")
check("the same name on another line is the same voice",
done and [line.get("voice") for line in held()[1:5]] == [None, None, "#1", "#1"]
and browser.execute_script(whos) == ["Vous", "Les autres", "Maya", "Maya"], browser.execute_script(whos))

# Criterion 2: a voice named, every line of it.
done = name(3, "Maya Durand", everywhere=True)
check("« Toutes les lignes de cette voix »: every line of it takes the name, the others as they were",
done and browser.execute_script(whos) == ["Vous", "Les autres", "Maya Durand", "Maya Durand"]
and voices() == {"remote/#1": "Maya Durand"}, [browser.execute_script(whos), voices()])
page()
check("read again with the meeting: the names stay",
browser.execute_script(whos) == ["Vous", "Les autres", "Maya Durand", "Maya Durand"], browser.execute_script(whos))
logs = WORK / "state" / "kitokey" / "logs"
logged = [line for log in sorted(logs.glob("*.jsonl")) for line in log.read_text().splitlines()]
given = [line for line in logged if "shell.voice_given" in line]
check("each naming is logged, never a name", len(given) >= 3 and not any(n in line for line in logged for n in ("Maya", "Sarah", "Personne")),
[len(given), [line for line in logged if any(n in line for n in ("Maya", "Sarah", "Personne"))][:3]])


def example_tried(now: dt.datetime) -> None:
"""CR. D126: « Essayer sur un exemple » from the empty window. The example of the window's language, bundled
with Kitokey, is placed as a meeting of its own — its two tracks, its title saying it is an example — and runs
Expand Down Expand Up @@ -18223,6 +18376,7 @@ def aside(folder):
confidential_sent(now)
example_tried(now)
speakers_named(now)
speakers_by_line(now)
waveform_drawn(now)
settings_version(now)
settings_narrow_without_model(now)
Expand Down
4 changes: 2 additions & 2 deletions modules/shell/src/correction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn tidy(text: &str) -> Option<String> {
}

/// The speaker a track's segments are written under (`transcript/v1`).
fn speaker(track: &str) -> &'static str {
pub(crate) fn speaker(track: &str) -> &'static str {
if track == "local" { "me" } else { "others" }
}

Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn correct(file: &Path, track: &str, start: f64, text: &str, when: &str) ->
}

/// Writes `content` beside `file`, then renames it over: read at any moment, the file is whole.
fn replace(file: &Path, content: &str) -> io::Result<()> {
pub(crate) fn replace(file: &Path, content: &str) -> io::Result<()> {
let beside = file.with_extension("jsonl.part");
let written = fs::write(&beside, content).and_then(|()| fs::rename(&beside, file));
if written.is_err() {
Expand Down
1 change: 1 addition & 0 deletions modules/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ pub mod spoken;
pub mod summarising;
pub mod transcription;
pub mod trial;
pub mod voices;
pub mod words;
48 changes: 47 additions & 1 deletion modules/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use kitokey_shell::{
spoken,
summarising::{self, Summarising},
transcription::{self, Hearer, Made, Transcription},
trial,
trial, voices,
words::{self, Failure, Language, Notice, Refusal, Told, Trouble},
};

Expand Down Expand Up @@ -436,6 +436,8 @@ fn main() {
summary_sent,
transcript_redo,
transcript_corrected,
line_named,
voice_named,
transcript_asked,
example_tried,
transcript_again,
Expand Down Expand Up @@ -1800,6 +1802,8 @@ struct Opened {
/// The names the user gave its two sides (#1205); none where the meeting cannot hold them — before
/// session-audio/v3 —: the page then offers no naming.
speakers: Option<SpeakersShown>,
/// The voices a person gave lines, keyed `<track>/<voice>`: their names (D131).
voices: std::collections::BTreeMap<String, String>,
/// The last transcript a redo replaced, the same way (D113).
previous_transcript: Option<Previous>,
/// The summary shown was made on the other version of the transcript, not the one shown (#1070):
Expand Down Expand Up @@ -1935,6 +1939,7 @@ fn opened(shell: State<'_, Shell>, name: String) -> Result<Opened, Told> {
_ => None,
},
speakers: speakers::offered(&folder).then(|| SpeakersShown::from(speakers::read(&folder))),
voices: speakers::voices(&folder),
previous_transcript: match meeting::previous(&folder) {
Read::Present(kept) => Some(Previous {
made: kept.made,
Expand Down Expand Up @@ -1967,6 +1972,47 @@ fn speakers_named(shell: State<'_, Shell>, name: String, me: Option<String>, oth
Ok(SpeakersShown::from(kept))
}

/// Who spoke on one line of a meeting's transcript, named on the user's word (D131): that line alone given a voice
/// of the person's own when `everywhere` is false, else every line of its voice. Once complete, never while it is
/// made, waits to be made again or its minutes are written — as a correction (D62). No name is logged.
fn voice_given(shell: &Shell, name: &str, track: &str, start: f64, who: &str, everywhere: bool) -> Result<(), Told> {
let folder = session_folder(shell, name)?;
let running = shell.transcription.lock().unwrap();
let hearing = shell.hearing.lock().unwrap().as_deref() == Some(folder.as_path());
let waits = shell.waiting.lock().unwrap().iter().any(|(queued, ..)| *queued == folder);
if (running.is_some() && hearing) || waits {
return Err(shell.told(Failure::Busy, format!("the transcript of {name} is being made")));
}
if shell.writing_minutes.lock().unwrap().as_deref() == Some(folder.as_path()) {
return Err(shell.told(Failure::Busy, format!("the minutes of {name} are being written")));
}
let when = chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false);
let given = if everywhere {
voices::voice_named(&folder, track, start, who, &when)
} else {
voices::line_named(&folder, track, start, who, &when).map(|_| ())
};
given.map_err(|refused| match refused {
voices::Refused::NotComplete => shell.told(Failure::NotComplete, format!("the transcript of {name} is not complete")),
voices::Refused::NoSuchLine => shell.told(Failure::Unexpected, "no line of the transcript starts there"),
voices::Refused::Name | voices::Refused::NotOffered => shell.told(Failure::Unexpected, "a name or a meeting the page never offers"),
voices::Refused::File(why) => shell.told(Failure::MeetingFile, why),
})?;
drop(running);
tracing::info!(track, everywhere, "shell.voice_given");
Ok(())
}

#[tauri::command]
fn line_named(shell: State<'_, Shell>, name: String, track: String, start: f64, who: String) -> Result<(), Told> {
voice_given(&shell, &name, &track, start, &who, false)
}

#[tauri::command]
fn voice_named(shell: State<'_, Shell>, name: String, track: String, start: f64, who: String) -> Result<(), Told> {
voice_given(&shell, &name, &track, start, &who, true)
}

/// The steps whose own model a meeting chose and cannot have now (D91).
fn gone_of(settings: &Settings, folder: &Path) -> Vec<meeting_models::Step> {
let chosen = meeting_models::read(folder);
Expand Down
Loading
Loading