Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4562e44df | ||
|
|
1d3e0add86 | ||
|
|
24cebd7e71 | ||
|
|
9e53d0b390 | ||
|
|
48000f47eb | ||
|
|
79e31d5331 | ||
|
|
20eb53af4b | ||
|
|
6183feaf82 | ||
|
|
f38550f3aa | ||
|
|
ad73e901a0 | ||
|
|
0b735b2e98 | ||
|
|
9ded4f14d4 | ||
|
|
5751684ef8 |
Generated
+1
-1
@@ -445,7 +445,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "call-recorder"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"chrono",
|
||||
|
||||
@@ -179,14 +179,26 @@ pub struct CallDetail {
|
||||
/// Whether retention deleted the call's audio (as opposed to the files
|
||||
/// being missing for another reason).
|
||||
pub audio_deleted: bool,
|
||||
/// The call's language, or the last-used one for a call without its
|
||||
/// own yet ([`preselect_language`]): what the language picker next to
|
||||
/// "Transkribieren"/"Erneut versuchen" starts on.
|
||||
pub language: String,
|
||||
}
|
||||
|
||||
/// The language the picker starts on for `call`: the one it was
|
||||
/// transcribed in, else `last_used` (the settings' `language`).
|
||||
pub fn preselect_language(call: &Call, last_used: &str) -> String {
|
||||
call.language
|
||||
.clone()
|
||||
.unwrap_or_else(|| last_used.to_string())
|
||||
}
|
||||
|
||||
impl CallDetail {
|
||||
/// `segments` are the stored ones; `merges` the stored speaker merges
|
||||
/// (source key → target key); `backend_url` is this build's backend
|
||||
/// (see [`CallListItem::of`]); `language` is the call-language setting
|
||||
/// in effect now (not necessarily what the call was transcribed with),
|
||||
/// used to apply [`correct_segment_text`] to each segment's text —
|
||||
/// (see [`CallListItem::of`]); `last_used_language` is the settings'
|
||||
/// `language` (see [`preselect_language`]). The call's language picks
|
||||
/// the [`correct_segment_text`] applied to each segment's text —
|
||||
/// non-destructively, so it also corrects transcripts from before the
|
||||
/// correction existed.
|
||||
pub fn of(
|
||||
@@ -195,8 +207,11 @@ impl CallDetail {
|
||||
speaker_names: BTreeMap<String, String>,
|
||||
merges: &BTreeMap<String, String>,
|
||||
backend_url: &str,
|
||||
language: &str,
|
||||
last_used_language: &str,
|
||||
) -> Self {
|
||||
// A call with segments always has its language (see the store's
|
||||
// schema v5); the fallback only covers a call not transcribed yet.
|
||||
let language = preselect_language(call, last_used_language);
|
||||
let segments = merge::apply_merges(segments, merges)
|
||||
.iter()
|
||||
.map(|segment| SegmentView {
|
||||
@@ -204,7 +219,7 @@ impl CallDetail {
|
||||
label: merge::label(&segment.speaker, &speaker_names),
|
||||
start: segment.start,
|
||||
end: segment.end,
|
||||
text: correct_segment_text(&segment.text, language),
|
||||
text: correct_segment_text(&segment.text, &language),
|
||||
})
|
||||
.collect();
|
||||
Self {
|
||||
@@ -219,6 +234,7 @@ impl CallDetail {
|
||||
audio_available: false,
|
||||
audio_deleted: call.audio_deleted,
|
||||
speaker_names,
|
||||
language,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -347,6 +363,7 @@ mod tests {
|
||||
title: None,
|
||||
crm_transcript_id: None,
|
||||
crm_base_url: None,
|
||||
language: None,
|
||||
uploaded_at: None,
|
||||
}
|
||||
}
|
||||
@@ -657,19 +674,22 @@ mod tests {
|
||||
"uploading": false,
|
||||
"audio_available": false,
|
||||
"audio_deleted": false,
|
||||
"language": "de",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/// With German as the last-used language (what matters for a call
|
||||
/// without its own, see `CallDetail::of`).
|
||||
fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail {
|
||||
detail_with_language(c, segments, names, "de")
|
||||
detail_last_used(c, segments, names, "de")
|
||||
}
|
||||
|
||||
fn detail_with_language(
|
||||
fn detail_last_used(
|
||||
c: &Call,
|
||||
segments: &[Segment],
|
||||
names: &[(&str, &str)],
|
||||
language: &str,
|
||||
last_used_language: &str,
|
||||
) -> CallDetail {
|
||||
CallDetail::of(
|
||||
c,
|
||||
@@ -677,7 +697,7 @@ mod tests {
|
||||
keys(names),
|
||||
&keys(&[("remote:2", "remote:1")]),
|
||||
BACKEND,
|
||||
language,
|
||||
last_used_language,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -757,14 +777,38 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn corrections_are_not_applied_outside_german_calls() {
|
||||
let c = call(Some(at(10, 15, 0)));
|
||||
let mut c = call(Some(at(10, 15, 0)));
|
||||
c.language = Some("en".into());
|
||||
let segments = [segment(Speaker::Me, 0.0, "Cheers!")];
|
||||
|
||||
let detail = detail_with_language(&c, &segments, &[], "en");
|
||||
// German was used last, but this call is English.
|
||||
let detail = detail_last_used(&c, &segments, &[], "de");
|
||||
|
||||
assert_eq!(detail.segments[0].text, "Cheers!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn corrections_follow_the_calls_language_not_the_last_used_one() {
|
||||
let mut c = call(Some(at(10, 15, 0)));
|
||||
c.language = Some("de".into());
|
||||
let segments = [segment(Speaker::Me, 0.0, "Cheers!")];
|
||||
|
||||
let detail = detail_last_used(&c, &segments, &[], "en");
|
||||
|
||||
assert_eq!(detail.segments[0].text, "Tschüss!");
|
||||
assert_eq!(detail.language, "de");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_preselected_language_is_the_calls_own_else_the_last_used() {
|
||||
let mut c = call(None);
|
||||
assert_eq!(preselect_language(&c, "fr"), "fr");
|
||||
|
||||
c.language = Some("it".into());
|
||||
assert_eq!(preselect_language(&c, "fr"), "it");
|
||||
assert_eq!(detail_last_used(&c, &[], &[], "fr").language, "it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_upload_text_uses_the_corrected_segment_text() {
|
||||
let c = call(Some(at(10, 46, 0)));
|
||||
|
||||
@@ -48,6 +48,9 @@ pub struct Call {
|
||||
pub crm_base_url: Option<String>,
|
||||
/// When the transcript was last uploaded.
|
||||
pub uploaded_at: Option<DateTime<Local>>,
|
||||
/// The language (ISO 639-1 code) the call is transcribed in, chosen
|
||||
/// when its transcription was started; `None` before that.
|
||||
pub language: Option<String>,
|
||||
}
|
||||
|
||||
/// A single transcribed word with its timing and speaker attribution.
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::transcribe::{TranscribeError, TranscribeOptions, Transcriber};
|
||||
/// Settings a pipeline run uses.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PipelineOptions {
|
||||
/// ISO 639-1 code, or `"auto"`.
|
||||
/// The call's language, one of [`crate::settings::CALL_LANGUAGES`].
|
||||
pub language: String,
|
||||
pub deepscript_model: String,
|
||||
/// Custom words/names submitted with both tracks (DeepScript's
|
||||
|
||||
@@ -166,6 +166,7 @@ mod tests {
|
||||
title: None,
|
||||
crm_transcript_id: None,
|
||||
crm_base_url: None,
|
||||
language: None,
|
||||
uploaded_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ mod tests {
|
||||
title: None,
|
||||
crm_transcript_id: None,
|
||||
crm_base_url: None,
|
||||
language: None,
|
||||
uploaded_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
+133
-5
@@ -26,6 +26,8 @@ pub const START_AFTER_SECS: RangeInclusive<u64> = 1..=30;
|
||||
/// Allowed mic release before a call counts as ended, in seconds. Too short
|
||||
/// splits a call, e.g. when the headset is switched.
|
||||
pub const END_AFTER_SECS: RangeInclusive<u64> = 3..=120;
|
||||
/// Allowed retention period, in days (the settings UI checks the same).
|
||||
pub const RETENTION_DAYS: RangeInclusive<u32> = 1..=3650;
|
||||
|
||||
/// The only `deepscript_model` values the settings UI offers (DeepScript's
|
||||
/// OpenAPI spec also lists `"standard"`, not offered here). An older
|
||||
@@ -33,6 +35,20 @@ pub const END_AFTER_SECS: RangeInclusive<u64> = 3..=120;
|
||||
/// default on load (see [`Settings::load`]) rather than failing.
|
||||
pub const DEEPSCRIPT_MODELS: [&str; 2] = ["premium", "premium_jade"];
|
||||
|
||||
/// The languages (ISO 639-1) a call can be transcribed in, chosen per call
|
||||
/// when its transcription is started. All are in DeepScript's
|
||||
/// `GET /v1/languages`; its `"auto"` is not offered.
|
||||
pub const CALL_LANGUAGES: [&str; 5] = ["de", "en", "es", "fr", "it"];
|
||||
|
||||
/// Checks a call language chosen in the UI; the error is shown as is.
|
||||
pub fn check_call_language(language: &str) -> Result<(), String> {
|
||||
if CALL_LANGUAGES.contains(&language) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("Unbekannte Sprache: {language}"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Default custom-vocabulary terms: short standalone German words/names
|
||||
/// DeepScript otherwise tends to mistranscribe or drop.
|
||||
const DEFAULT_VOCABULARY: [&str; 5] = ["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"];
|
||||
@@ -54,6 +70,9 @@ pub struct Settings {
|
||||
pub allowlist: Vec<String>,
|
||||
pub mic_device: Option<String>,
|
||||
pub output_device: Option<String>,
|
||||
/// The language of the transcription started last (one of
|
||||
/// [`CALL_LANGUAGES`]), preselected for the next call. Set by the app
|
||||
/// when a transcription is started, not by the settings page.
|
||||
pub language: String,
|
||||
pub deepscript_model: String,
|
||||
/// Custom words/names submitted with every transcription (DeepScript's
|
||||
@@ -113,6 +132,13 @@ impl Settings {
|
||||
END_AFTER_SECS.end()
|
||||
));
|
||||
}
|
||||
if !RETENTION_DAYS.contains(&self.retention_days) {
|
||||
return Err(format!(
|
||||
"Aufbewahrung: {}–{} Tage",
|
||||
RETENTION_DAYS.start(),
|
||||
RETENTION_DAYS.end()
|
||||
));
|
||||
}
|
||||
if !DEEPSCRIPT_MODELS.contains(&self.deepscript_model.as_str()) {
|
||||
return Err(format!(
|
||||
"Transkriptionsmodell: nur {} möglich",
|
||||
@@ -137,12 +163,14 @@ impl Settings {
|
||||
}
|
||||
|
||||
/// The settings after the user saved `edited` over these: normalized
|
||||
/// (see [`normalize_vocabulary`]), checked, with the backend login
|
||||
/// (which only the app changes) kept, so a settings page loaded before
|
||||
/// a login cannot undo it.
|
||||
/// (see [`normalize_vocabulary`]), checked, with the backend login and
|
||||
/// the last-used language (which only the app changes) kept, so a
|
||||
/// settings page loaded before a login or a transcription cannot undo
|
||||
/// them.
|
||||
pub fn edited(&self, mut edited: Settings) -> Result<Settings, String> {
|
||||
edited.vocabulary = normalize_vocabulary(edited.vocabulary);
|
||||
edited.validate()?;
|
||||
edited.language = self.language.clone();
|
||||
edited.backend_username = self.backend_username.clone();
|
||||
edited.backend_key_expires_at = self.backend_key_expires_at;
|
||||
edited.backend_key_base_url = self.backend_key_base_url.clone();
|
||||
@@ -152,8 +180,10 @@ impl Settings {
|
||||
/// Reads the settings file. A missing or unreadable file yields the
|
||||
/// defaults; fields missing from the file take their default value. A
|
||||
/// `deepscript_model` outside [`DEEPSCRIPT_MODELS`] (e.g. an older
|
||||
/// file's `"standard"`) falls back to the default instead of failing;
|
||||
/// `vocabulary` is normalized (see [`normalize_vocabulary`]).
|
||||
/// file's `"standard"`) falls back to the default instead of failing, and
|
||||
/// so does a `retention_days` outside [`RETENTION_DAYS`] and a
|
||||
/// `language` outside [`CALL_LANGUAGES`]; `vocabulary` is normalized
|
||||
/// (see [`normalize_vocabulary`]).
|
||||
pub fn load(path: &Path) -> Settings {
|
||||
let mut settings: Settings = fs::read_to_string(path)
|
||||
.ok()
|
||||
@@ -162,6 +192,13 @@ impl Settings {
|
||||
if !DEEPSCRIPT_MODELS.contains(&settings.deepscript_model.as_str()) {
|
||||
settings.deepscript_model = Settings::default().deepscript_model;
|
||||
}
|
||||
if check_call_language(&settings.language).is_err() {
|
||||
settings.language = Settings::default().language;
|
||||
}
|
||||
// 0 would delete all audio on the next pass.
|
||||
if !RETENTION_DAYS.contains(&settings.retention_days) {
|
||||
settings.retention_days = Settings::default().retention_days;
|
||||
}
|
||||
settings.vocabulary = normalize_vocabulary(settings.vocabulary);
|
||||
settings
|
||||
}
|
||||
@@ -275,6 +312,51 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_five_call_languages_are_accepted() {
|
||||
for language in CALL_LANGUAGES {
|
||||
assert_eq!(check_call_language(language), Ok(()), "{language}");
|
||||
}
|
||||
assert_eq!(CALL_LANGUAGES, ["de", "en", "es", "fr", "it"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn another_call_language_is_refused() {
|
||||
assert_eq!(
|
||||
check_call_language("auto"),
|
||||
Err("Unbekannte Sprache: auto".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
check_call_language("pt"),
|
||||
Err("Unbekannte Sprache: pt".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_stored_language_falls_back_to_the_default() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("settings.json");
|
||||
fs::write(&path, r#"{"language": "auto"}"#).unwrap();
|
||||
assert_eq!(Settings::load(&path).language, "de");
|
||||
|
||||
fs::write(&path, r#"{"language": "it"}"#).unwrap();
|
||||
assert_eq!(Settings::load(&path).language, "it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_keeps_the_last_used_language_which_only_the_app_changes() {
|
||||
let current = Settings {
|
||||
language: "fr".into(),
|
||||
..Settings::default()
|
||||
};
|
||||
let edited = Settings {
|
||||
language: "de".into(),
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
assert_eq!(current.edited(edited).unwrap().language, "fr");
|
||||
}
|
||||
|
||||
fn logged_in() -> Settings {
|
||||
Settings {
|
||||
backend_username: Some("hinrichs".into()),
|
||||
@@ -354,6 +436,52 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_checks_the_retention_period() {
|
||||
for days in [1, 3650] {
|
||||
let s = Settings {
|
||||
retention_days: days,
|
||||
..Settings::default()
|
||||
};
|
||||
assert_eq!(s.validate(), Ok(()), "{days} days");
|
||||
}
|
||||
for days in [0, 3651] {
|
||||
let s = Settings {
|
||||
retention_days: days,
|
||||
..Settings::default()
|
||||
};
|
||||
assert_eq!(
|
||||
s.validate(),
|
||||
Err("Aufbewahrung: 1–3650 Tage".to_string()),
|
||||
"{days} days"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_retention_period_out_of_range_falls_back_to_the_default_on_load() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("settings.json");
|
||||
for days in [0, 3651] {
|
||||
fs::write(
|
||||
&path,
|
||||
format!(
|
||||
r#"{{"retention_days": {days}, "mic_device": "headset", "backend_key_base_url": "https://crm.example"}}"#
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
Settings::load(&path),
|
||||
Settings {
|
||||
mic_device: Some("headset".into()),
|
||||
backend_key_base_url: Some("https://crm.example".into()),
|
||||
..Settings::default()
|
||||
},
|
||||
"{days} days"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_rejects_a_model_outside_the_offered_two() {
|
||||
for model in ["standard", "nonsense", ""] {
|
||||
|
||||
+101
-8
@@ -130,9 +130,25 @@ ALTER TABLE calls ADD COLUMN crm_base_url TEXT;
|
||||
UPDATE calls SET crm_base_url = 'https://test.euvinopro.eu' WHERE crm_transcript_id IS NOT NULL;
|
||||
";
|
||||
|
||||
/// Version 5: the language a call is transcribed in, chosen per call when
|
||||
/// its transcription is started. Before this version every transcription
|
||||
/// used the then default German: backfilled for the calls one was started
|
||||
/// for, so their corrections (`call_view`) stay as they were; a call still
|
||||
/// waiting gets its language when the user decides.
|
||||
const SCHEMA_V5_SQL: &str = "
|
||||
ALTER TABLE calls ADD COLUMN language TEXT;
|
||||
UPDATE calls SET language = 'de' WHERE status NOT IN ('recording', 'awaiting_decision');
|
||||
";
|
||||
|
||||
/// Schema steps by `PRAGMA user_version`: entry `i` takes a database from
|
||||
/// version `i` to `i + 1`. A new database runs all of them.
|
||||
const MIGRATIONS: &[&str] = &[SCHEMA_V1_SQL, SCHEMA_V2_SQL, SCHEMA_V3_SQL, SCHEMA_V4_SQL];
|
||||
const MIGRATIONS: &[&str] = &[
|
||||
SCHEMA_V1_SQL,
|
||||
SCHEMA_V2_SQL,
|
||||
SCHEMA_V3_SQL,
|
||||
SCHEMA_V4_SQL,
|
||||
SCHEMA_V5_SQL,
|
||||
];
|
||||
|
||||
/// SQLite-backed store for calls and everything derived from them.
|
||||
pub struct Store {
|
||||
@@ -390,6 +406,16 @@ impl Store {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets the language (ISO 639-1 code) the call is transcribed in.
|
||||
pub fn set_language(&self, id: CallId, language: &str) -> Result<()> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
conn.execute(
|
||||
"UPDATE calls SET language = ?1 WHERE id = ?2",
|
||||
params![language, id],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn mark_transcribed(&self, id: CallId, at: DateTime<Local>) -> Result<()> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
conn.execute(
|
||||
@@ -549,9 +575,9 @@ fn ids_with_status(conn: &rusqlite::Connection, status: CallStatus) -> Result<Ve
|
||||
Ok(ids)
|
||||
}
|
||||
|
||||
const SELECT_ALL_CALLS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at, crm_base_url FROM calls";
|
||||
const SELECT_ALL_CALLS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at, crm_base_url, language FROM calls";
|
||||
|
||||
const SELECT_CALL_COLUMNS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at, crm_base_url FROM calls WHERE id = ?1";
|
||||
const SELECT_CALL_COLUMNS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at, crm_base_url, language FROM calls WHERE id = ?1";
|
||||
|
||||
fn row_to_call(row: &Row) -> Result<Call> {
|
||||
let id: CallId = row.get(0)?;
|
||||
@@ -569,6 +595,7 @@ fn row_to_call(row: &Row) -> Result<Call> {
|
||||
let crm_transcript_id: Option<String> = row.get(12)?;
|
||||
let uploaded_at: Option<String> = row.get(13)?;
|
||||
let crm_base_url: Option<String> = row.get(14)?;
|
||||
let language: Option<String> = row.get(15)?;
|
||||
|
||||
Ok(Call {
|
||||
id,
|
||||
@@ -586,6 +613,7 @@ fn row_to_call(row: &Row) -> Result<Call> {
|
||||
crm_transcript_id,
|
||||
crm_base_url,
|
||||
uploaded_at: opt_dt_from_str(uploaded_at)?,
|
||||
language,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -715,6 +743,14 @@ CREATE TABLE speaker_merges (
|
||||
const RELEASED_V3_STEP_SQL: &str = "
|
||||
ALTER TABLE calls ADD COLUMN crm_transcript_id TEXT;
|
||||
ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||
";
|
||||
|
||||
/// The schema of user_version 4, exactly as release 0.2.2 created it
|
||||
/// (copied from `SCHEMA_V4_SQL` at `HEAD`): version 3 plus these
|
||||
/// statements.
|
||||
const RELEASED_V4_STEP_SQL: &str = "
|
||||
ALTER TABLE calls ADD COLUMN crm_base_url TEXT;
|
||||
UPDATE calls SET crm_base_url = 'https://test.euvinopro.eu' WHERE crm_transcript_id IS NOT NULL;
|
||||
";
|
||||
|
||||
fn user_version(path: &Path) -> i64 {
|
||||
@@ -738,7 +774,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_database_starts_at_version_4() {
|
||||
fn a_new_database_starts_at_version_5() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("calls.sqlite");
|
||||
let store = Store::open(&path).unwrap();
|
||||
@@ -750,7 +786,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||
.unwrap();
|
||||
drop(store);
|
||||
|
||||
assert_eq!(user_version(&path), 4);
|
||||
assert_eq!(user_version(&path), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -807,7 +843,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||
store.set_title(1, Some("Lieferung März")).unwrap();
|
||||
store.set_speaker_merge(1, "remote:2", "remote:1").unwrap();
|
||||
drop(store);
|
||||
assert_eq!(user_version(&path), 4);
|
||||
assert_eq!(user_version(&path), 5);
|
||||
let store = Store::open(&path).unwrap();
|
||||
let call = store.get_call(1).unwrap().unwrap();
|
||||
assert_eq!(call.title.as_deref(), Some("Lieferung März"));
|
||||
@@ -861,7 +897,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||
.set_uploaded(1, "crm-1", "https://backend.example", uploaded)
|
||||
.unwrap();
|
||||
drop(store);
|
||||
assert_eq!(user_version(&path), 4);
|
||||
assert_eq!(user_version(&path), 5);
|
||||
let store = Store::open(&path).unwrap();
|
||||
let call = store.get_call(1).unwrap().unwrap();
|
||||
assert_eq!(call.crm_transcript_id.as_deref(), Some("crm-1"));
|
||||
@@ -915,7 +951,64 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||
assert_eq!(not_uploaded.crm_transcript_id, None);
|
||||
assert_eq!(not_uploaded.crm_base_url, None);
|
||||
|
||||
assert_eq!(user_version(&path), 4);
|
||||
assert_eq!(user_version(&path), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_version_4_database_is_upgraded_backfilling_german_for_started_transcriptions() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("calls.sqlite");
|
||||
let started = "2026-11-05T10:14:00+01:00";
|
||||
{
|
||||
let conn = rusqlite::Connection::open(&path).unwrap();
|
||||
conn.execute_batch(RELEASED_V1_SCHEMA_SQL).unwrap();
|
||||
conn.execute_batch(RELEASED_V2_STEP_SQL).unwrap();
|
||||
conn.execute_batch(RELEASED_V3_STEP_SQL).unwrap();
|
||||
conn.execute_batch(RELEASED_V4_STEP_SQL).unwrap();
|
||||
conn.execute_batch("PRAGMA user_version = 4;").unwrap();
|
||||
for (app, status) in [
|
||||
("Microsoft Teams", "done"),
|
||||
("Zoom", "failed"),
|
||||
("MicroSIP", "awaiting_decision"),
|
||||
] {
|
||||
conn.execute(
|
||||
"INSERT INTO calls \
|
||||
(app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted) \
|
||||
VALUES (?1, ?2, ?2, ?3, 0, NULL, '/rec/mic.wav', '/rec/out.wav', NULL, 0)",
|
||||
rusqlite::params![app, started, status],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let store = Store::open(&path).unwrap();
|
||||
|
||||
// Transcriptions started before this version all used the then
|
||||
// default German; a call still waiting has no language yet.
|
||||
let languages: Vec<_> = (1..=3)
|
||||
.map(|id| store.get_call(id).unwrap().unwrap().language)
|
||||
.collect();
|
||||
assert_eq!(
|
||||
languages,
|
||||
[Some("de".to_string()), Some("de".to_string()), None]
|
||||
);
|
||||
assert_eq!(user_version(&path), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_language_is_stored_per_call() {
|
||||
let store = Store::open_in_memory().unwrap();
|
||||
let id = new_call(&store);
|
||||
let other = new_call(&store);
|
||||
assert_eq!(store.get_call(id).unwrap().unwrap().language, None);
|
||||
|
||||
store.set_language(id, "fr").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
store.get_call(id).unwrap().unwrap().language.as_deref(),
|
||||
Some("fr")
|
||||
);
|
||||
assert_eq!(store.get_call(other).unwrap().unwrap().language, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"version": "0.2.4",
|
||||
"pub_date": "2026-11-10T11:50:14Z",
|
||||
"version": "0.4.0",
|
||||
"pub_date": "2026-11-18T10:48:28Z",
|
||||
"platforms": {
|
||||
"windows-x86_64": {
|
||||
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUdGpRa1ZvalU2SUJzeVppQWszcm5oN2s1Q2xIenE4U0lUWkhKbEVhVncyZkhtZzFPeFdjajVqOXRuZCswSVhhVHlhenJhL2Z5UzYwbFFRWUVQbDJPZmtWZm5MUkNvV1FZPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzk0MzExMzkxCWZpbGU6R2VzcHLDpGNoc3Jla29yZGVyXzAuMi40X3g2NC1zZXR1cC5leGUJdmVyc2lvbjowLjIuNApmOGpXV2pWb1Fsem9lUlpVYmtoSFdlU2ovSGtYdDNINnlSa3A2Qm5WL0VDeDdVdldLWnlzb3hxOEtCRm1BUEtnYXNNaUk2ZUhZUCt3Vm9Ua0tLeGhDUT09Cg==",
|
||||
"url": "https://gitea.euvino.eu/public/call-recorder/releases/download/v0.2.4/Gespraechsrekorder_0.2.4_x64-setup.exe"
|
||||
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUdGpRa1ZvalU2SUZxOUFRY3BBVnphWnBYN2lnZ2xNV0FzQnpWdWt6S1pHcXg2VUovZFF6MmtuODNaWjNwRWRWbTZONDZYVWthYndrR0w5cjJPWVU4MHMwK0pXVnFHVmdVPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzk0OTk4ODc4CWZpbGU6R2VzcHLDpGNoc3Jla29yZGVyXzAuNC4wX3g2NC1zZXR1cC5leGUJdmVyc2lvbjowLjQuMApVSTh5ejJFcGRsbEJMRC9EVnQzRjBHbWVoZTM5cHh1TXhtemdTd1JUVkZoM0dOZ3FLUmdUSy9zVTN3Szg4ZDRsZHNHL3hBZStOQndKeW9wd1p3dDJDQT09Cg==",
|
||||
"url": "https://gitea.euvino.eu/public/call-recorder/releases/download/v0.4.0/Gespraechsrekorder_0.4.0_x64-setup.exe"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "call-recorder"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
description = "Gesprächsrekorder desktop app"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ pub async fn discard_call(app: AppHandle, id: CallId) -> CmdResult<()> {
|
||||
processing::delete_leftover_jobs(app, vec![id]);
|
||||
return Err(e.to_string());
|
||||
}
|
||||
Err(e @ DiscardError::Other(_)) => return Err(e.to_string()),
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
prompt_queue_changed(app);
|
||||
Ok(())
|
||||
@@ -250,16 +250,17 @@ pub async fn discard_call(app: AppHandle, id: CallId) -> CmdResult<()> {
|
||||
}
|
||||
|
||||
/// Transkribieren in the end-of-call prompt: starts processing in the
|
||||
/// background and returns at once; the call leaves the prompt.
|
||||
/// background in the chosen `language` and returns at once; the call
|
||||
/// leaves the prompt.
|
||||
#[tauri::command]
|
||||
pub async fn transcribe_call(app: AppHandle, id: CallId) -> CmdResult<()> {
|
||||
blocking(app, move |app| processing::start(app, id, false)).await
|
||||
pub async fn transcribe_call(app: AppHandle, id: CallId, language: String) -> CmdResult<()> {
|
||||
blocking(app, move |app| processing::start(app, id, false, language)).await
|
||||
}
|
||||
|
||||
/// Processes a failed (or still undecided) call again.
|
||||
/// Processes a failed (or still undecided) call again, in `language`.
|
||||
#[tauri::command]
|
||||
pub async fn retry_call(app: AppHandle, id: CallId) -> CmdResult<()> {
|
||||
blocking(app, move |app| processing::start(app, id, true)).await
|
||||
pub async fn retry_call(app: AppHandle, id: CallId, language: String) -> CmdResult<()> {
|
||||
blocking(app, move |app| processing::start(app, id, true, language)).await
|
||||
}
|
||||
|
||||
/// After a call left the prompt queue: hides the prompt if no call waits
|
||||
|
||||
@@ -3,6 +3,7 @@ mod commands;
|
||||
mod detection;
|
||||
mod playback;
|
||||
mod processing;
|
||||
mod retention;
|
||||
mod state;
|
||||
mod tray;
|
||||
mod updater;
|
||||
@@ -129,6 +130,9 @@ pub fn run() {
|
||||
create_windows(app.handle())?;
|
||||
commands::apply_autostart(app.handle(), autostart);
|
||||
processing::delete_leftover_jobs(app.handle(), leftover_jobs);
|
||||
// After the startup recovery and the cache clears, with the
|
||||
// windows there to hear what it deleted.
|
||||
retention::spawn(app.handle().clone());
|
||||
|
||||
tray::create(app.handle())?;
|
||||
detection::spawn(app.handle().clone());
|
||||
|
||||
@@ -9,6 +9,7 @@ use std::path::PathBuf;
|
||||
use recorder_core::model::{CallId, CallStatus};
|
||||
use recorder_core::pipeline::{self, PipelineOptions};
|
||||
use recorder_core::secrets::Service;
|
||||
use recorder_core::settings::check_call_language;
|
||||
use recorder_core::transcribe::deepscript::DeepScript;
|
||||
use recorder_core::transcribe::TranscribeError;
|
||||
use serde::Serialize;
|
||||
@@ -57,13 +58,22 @@ impl Drop for Claim {
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts processing call `id` in the background and returns at once; the
|
||||
/// call leaves the end-of-call prompt. `retry` also allows failed calls.
|
||||
/// Without a DeepScript key nothing starts: the call is marked failed and
|
||||
/// the error returned. Reads the keyring, so call it off the UI thread.
|
||||
pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> {
|
||||
/// Starts processing call `id` in `language` in the background and returns
|
||||
/// at once; the call leaves the end-of-call prompt. `retry` also allows
|
||||
/// failed calls. The language is stored with the call and remembered for
|
||||
/// the next one; one outside `CALL_LANGUAGES` is refused before anything
|
||||
/// changes. Without a DeepScript key nothing starts: the call is marked
|
||||
/// failed and the error returned. Reads the keyring, so call it off the UI
|
||||
/// thread.
|
||||
pub fn start(app: &AppHandle, id: CallId, retry: bool, language: String) -> Result<(), String> {
|
||||
check_call_language(&language)?;
|
||||
let claim = Claim::take(app, id, retry)?;
|
||||
let state = app.state::<AppState>();
|
||||
state
|
||||
.store
|
||||
.set_language(id, &language)
|
||||
.map_err(|e| format!("Interner Fehler: {e}"))?;
|
||||
state.remember_language(&language);
|
||||
|
||||
let Some(key) = deepscript_key(&state) else {
|
||||
let msg = TranscribeError::MissingKey.user_message();
|
||||
@@ -76,7 +86,7 @@ pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> {
|
||||
let work_dir = upload_dir(app)?;
|
||||
let settings = state.settings();
|
||||
let opts = PipelineOptions {
|
||||
language: settings.language,
|
||||
language,
|
||||
deepscript_model: settings.deepscript_model,
|
||||
vocabulary: settings.vocabulary,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,504 @@
|
||||
//! The scheduled retention job: once at startup and then every hour (by the
|
||||
//! wall clock, so also right after standby) it deletes what the retention
|
||||
//! period (`retention_days` in the settings, read anew for every pass) has
|
||||
//! run out for, as planned by [`plan_retention`]: the audio of transcribed
|
||||
//! calls N days after the transcription (transcript, title, speaker names
|
||||
//! and merges, CRM upload stay), and undecided recordings with their row N
|
||||
//! days after the call ended. Failed calls keep their audio. A call that is
|
||||
//! in use (recorded, processed, uploaded, played, or its DeepScript jobs
|
||||
//! still on record) is skipped and tried again by the next pass; errors are
|
||||
//! logged, never fatal.
|
||||
|
||||
use std::panic::{self, AssertUnwindSafe};
|
||||
use std::slice;
|
||||
use std::thread;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
use recorder_core::model::{Call, CallId};
|
||||
use recorder_core::retention::{plan_retention, RetentionAction};
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::commands;
|
||||
use crate::processing;
|
||||
use crate::state::{AppState, AudioDeleteError, DiscardError};
|
||||
|
||||
/// How often a pass runs.
|
||||
const PASS_INTERVAL: Duration = Duration::from_secs(60 * 60);
|
||||
/// How often the job looks at the wall clock to see whether a pass is due.
|
||||
const WAKE_INTERVAL: Duration = Duration::from_secs(60);
|
||||
|
||||
/// What one pass did, per call.
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct PassReport {
|
||||
pub audio_deleted: Vec<CallId>,
|
||||
pub calls_deleted: Vec<CallId>,
|
||||
/// In use or changed since planned; tried again by the next pass.
|
||||
pub skipped: Vec<CallId>,
|
||||
/// Those of `skipped` whose DeepScript jobs are still on record.
|
||||
pub cleanup_pending: Vec<CallId>,
|
||||
pub failed: Vec<CallId>,
|
||||
}
|
||||
|
||||
impl PassReport {
|
||||
/// The calls whose row or audio changed.
|
||||
fn changed(&self) -> impl Iterator<Item = CallId> + '_ {
|
||||
self.audio_deleted
|
||||
.iter()
|
||||
.chain(&self.calls_deleted)
|
||||
.copied()
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self == &PassReport::default()
|
||||
}
|
||||
|
||||
/// "2 audio deleted, 1 call deleted, 1 skipped, 0 failed" for the log.
|
||||
fn summary(&self) -> String {
|
||||
let calls = self.calls_deleted.len();
|
||||
format!(
|
||||
"{} audio deleted, {calls} {} deleted, {} skipped, {} failed",
|
||||
self.audio_deleted.len(),
|
||||
if calls == 1 { "call" } else { "calls" },
|
||||
self.skipped.len(),
|
||||
self.failed.len()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts the job: a pass right away and then every [`PASS_INTERVAL`].
|
||||
/// Call once the startup recovery, the cache clears and the windows are
|
||||
/// done. One thread runs every pass, so two never run at once.
|
||||
pub fn spawn(app: AppHandle) {
|
||||
let started = thread::Builder::new()
|
||||
.name("retention".into())
|
||||
.spawn(move || {
|
||||
let mut last_pass = None;
|
||||
loop {
|
||||
let now = SystemTime::now();
|
||||
if pass_due(last_pass, now) {
|
||||
last_pass = Some(now);
|
||||
// A panic must not end the job: the next pass retries.
|
||||
if panic::catch_unwind(AssertUnwindSafe(|| run(&app))).is_err() {
|
||||
log::error!("retention: the pass panicked");
|
||||
}
|
||||
}
|
||||
thread::sleep(WAKE_INTERVAL);
|
||||
}
|
||||
});
|
||||
if let Err(e) = started {
|
||||
log::error!("retention: could not start the job: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
/// One pass, and tells the UI what changed: `call-updated` per call (the
|
||||
/// list and an open detail refresh; the player shows the retention note),
|
||||
/// and the prompt, if an undecided call it waits for was deleted.
|
||||
fn run(app: &AppHandle) {
|
||||
let report = run_pass(&app.state::<AppState>(), Local::now());
|
||||
for id in report.changed() {
|
||||
processing::emit_updated(app, id);
|
||||
}
|
||||
if !report.calls_deleted.is_empty() {
|
||||
commands::prompt_queue_changed(app);
|
||||
}
|
||||
// As "Verwerfen" does: once their jobs are gone, a later pass can
|
||||
// delete them.
|
||||
processing::delete_leftover_jobs(app, report.cleanup_pending.clone());
|
||||
if !report.is_empty() {
|
||||
log::info!("retention: {}", report.summary());
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs one pass over all calls as of `now`, with the retention period
|
||||
/// currently set.
|
||||
pub fn run_pass(state: &AppState, now: DateTime<Local>) -> PassReport {
|
||||
let calls = match state.store.list_calls() {
|
||||
Ok(calls) => calls,
|
||||
Err(e) => {
|
||||
log::error!("retention: could not list the calls: {e}");
|
||||
return PassReport::default();
|
||||
}
|
||||
};
|
||||
let retention_days = state.settings().retention_days;
|
||||
let plan = plan_retention(&calls, now, retention_days);
|
||||
execute(state, &plan, now, retention_days)
|
||||
}
|
||||
|
||||
/// Carries out `plan`, made as of `now` for `retention_days`. Each call is
|
||||
/// planned again from its row as it is when the action runs, while nothing
|
||||
/// else can take it: a call that changed since (e.g. a "Transkribieren"
|
||||
/// that failed meanwhile, so it keeps its audio) is skipped. A call deleted
|
||||
/// meanwhile is ignored.
|
||||
fn execute(
|
||||
state: &AppState,
|
||||
plan: &[RetentionAction],
|
||||
now: DateTime<Local>,
|
||||
retention_days: u32,
|
||||
) -> PassReport {
|
||||
let mut report = PassReport::default();
|
||||
for &action in plan {
|
||||
let still_planned =
|
||||
|call: &Call| plan_retention(slice::from_ref(call), now, retention_days) == [action];
|
||||
match action {
|
||||
RetentionAction::DeleteAudio(id) => match state.delete_audio(id, still_planned) {
|
||||
Ok(()) => report.audio_deleted.push(id),
|
||||
Err(AudioDeleteError::Busy(why)) => {
|
||||
log::info!("retention: call {id}: audio kept for now: {why}");
|
||||
report.skipped.push(id);
|
||||
}
|
||||
Err(AudioDeleteError::NotFound) => {
|
||||
log::info!("retention: call {id}: already deleted");
|
||||
}
|
||||
Err(AudioDeleteError::Failed(e)) => {
|
||||
log::error!("retention: call {id}: audio not deleted: {e}");
|
||||
report.failed.push(id);
|
||||
}
|
||||
},
|
||||
// The same path, and refusals, as "Verwerfen".
|
||||
RetentionAction::DeleteCall(id) => match state.discard_call_if(id, still_planned) {
|
||||
Ok(_) => report.calls_deleted.push(id),
|
||||
Err(e @ DiscardError::Busy(_)) => {
|
||||
log::info!("retention: call {id}: kept for now: {e}");
|
||||
report.skipped.push(id);
|
||||
}
|
||||
Err(e @ DiscardError::CleanupPending) => {
|
||||
log::info!("retention: call {id}: kept for now: {e}");
|
||||
report.skipped.push(id);
|
||||
report.cleanup_pending.push(id);
|
||||
}
|
||||
Err(DiscardError::NotFound) => {
|
||||
log::info!("retention: call {id}: already deleted");
|
||||
}
|
||||
Err(DiscardError::Other(e)) => {
|
||||
log::error!("retention: call {id}: not deleted: {e}");
|
||||
report.failed.push(id);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
report
|
||||
}
|
||||
|
||||
/// Whether the next pass is due at `now`, given when the last one started
|
||||
/// (`None`: none yet). Uses the wall clock, which keeps running in standby;
|
||||
/// a clock that went back makes the pass due.
|
||||
fn pass_due(last: Option<SystemTime>, now: SystemTime) -> bool {
|
||||
let Some(last) = last else {
|
||||
return true;
|
||||
};
|
||||
now.duration_since(last)
|
||||
.map_or(true, |elapsed| elapsed >= PASS_INTERVAL)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use chrono::Duration as Days;
|
||||
use recorder_core::model::CallStatus;
|
||||
use recorder_core::secrets::MemorySecrets;
|
||||
use recorder_core::store::Store;
|
||||
|
||||
use super::*;
|
||||
|
||||
struct Fixture {
|
||||
state: AppState,
|
||||
dir: tempfile::TempDir,
|
||||
}
|
||||
|
||||
fn fixture() -> Fixture {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let state = AppState::new(
|
||||
Store::open_in_memory().unwrap(),
|
||||
Box::new(MemorySecrets::default()),
|
||||
dir.path().join("settings.json"),
|
||||
dir.path().join("recordings"),
|
||||
dir.path().join("playback"),
|
||||
);
|
||||
Fixture { state, dir }
|
||||
}
|
||||
|
||||
/// A call with both track files that ended `ended_days_ago` and, if
|
||||
/// `transcribed_days_ago` is given, was transcribed then (status
|
||||
/// `Done`); otherwise it awaits the decision.
|
||||
fn call(
|
||||
f: &Fixture,
|
||||
name: &str,
|
||||
now: DateTime<Local>,
|
||||
ended_days_ago: i64,
|
||||
transcribed_days_ago: Option<i64>,
|
||||
) -> CallId {
|
||||
let mic = f.dir.path().join(format!("{name}-mic.wav"));
|
||||
let out = f.dir.path().join(format!("{name}-out.wav"));
|
||||
fs::write(&mic, b"mic").unwrap();
|
||||
fs::write(&out, b"out").unwrap();
|
||||
let store = &f.state.store;
|
||||
let ended = now - Days::days(ended_days_ago);
|
||||
let id = store
|
||||
.create_call("Microsoft Teams", ended - Days::minutes(5), &mic, &out)
|
||||
.unwrap();
|
||||
store.finish_recording(id, ended, false).unwrap();
|
||||
if let Some(days) = transcribed_days_ago {
|
||||
store.set_status(id, CallStatus::Done, None).unwrap();
|
||||
store.mark_transcribed(id, now - Days::days(days)).unwrap();
|
||||
}
|
||||
id
|
||||
}
|
||||
|
||||
fn tracks(f: &Fixture, id: CallId) -> [PathBuf; 2] {
|
||||
let call = f.state.store.get_call(id).unwrap().unwrap();
|
||||
[call.mic_path, call.out_path]
|
||||
}
|
||||
|
||||
fn has_audio(f: &Fixture, id: CallId) -> bool {
|
||||
let call = f.state.store.get_call(id).unwrap().unwrap();
|
||||
!call.audio_deleted && tracks(f, id).iter().all(|p| p.exists())
|
||||
}
|
||||
|
||||
fn sorted(mut ids: Vec<CallId>) -> Vec<CallId> {
|
||||
ids.sort();
|
||||
ids
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pass_does_exactly_what_the_plan_says_and_skips_calls_in_use() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let done_old = call(&f, "done-old", now, 9, Some(8));
|
||||
let done_new = call(&f, "done-new", now, 3, Some(2));
|
||||
let undecided_old = call(&f, "undecided-old", now, 8, None);
|
||||
let undecided_new = call(&f, "undecided-new", now, 6, None);
|
||||
let failed_old = call(&f, "failed-old", now, 30, None);
|
||||
f.state
|
||||
.store
|
||||
.set_status(failed_old, CallStatus::Failed, Some("Fehler"))
|
||||
.unwrap();
|
||||
let uploading = call(&f, "uploading", now, 9, Some(8));
|
||||
let upload = f.state.claim_upload(uploading).unwrap();
|
||||
// Its DeepScript jobs are still on record: not deleted yet.
|
||||
let cleanup = call(&f, "cleanup", now, 8, None);
|
||||
f.state
|
||||
.store
|
||||
.record_remote_job(cleanup, "mic", "job-1")
|
||||
.unwrap();
|
||||
let undecided_old_tracks = tracks(&f, undecided_old);
|
||||
let store = &f.state.store;
|
||||
store.set_speaker_name(done_old, "me", "Hauke").unwrap();
|
||||
store
|
||||
.set_speaker_merge(done_old, "remote:2", "remote:1")
|
||||
.unwrap();
|
||||
store.set_title(done_old, Some("Bestellung")).unwrap();
|
||||
|
||||
let report = run_pass(&f.state, now);
|
||||
|
||||
assert_eq!(
|
||||
PassReport {
|
||||
audio_deleted: sorted(report.audio_deleted),
|
||||
calls_deleted: report.calls_deleted,
|
||||
skipped: sorted(report.skipped),
|
||||
cleanup_pending: report.cleanup_pending,
|
||||
failed: report.failed,
|
||||
},
|
||||
PassReport {
|
||||
audio_deleted: vec![done_old],
|
||||
calls_deleted: vec![undecided_old],
|
||||
skipped: sorted(vec![uploading, cleanup]),
|
||||
cleanup_pending: vec![cleanup],
|
||||
failed: vec![],
|
||||
}
|
||||
);
|
||||
assert!(!has_audio(&f, done_old));
|
||||
let kept = store.get_call(done_old).unwrap().unwrap();
|
||||
assert_eq!(kept.title.as_deref(), Some("Bestellung"));
|
||||
assert_eq!(
|
||||
store
|
||||
.speaker_names(done_old)
|
||||
.unwrap()
|
||||
.get("me")
|
||||
.map(String::as_str),
|
||||
Some("Hauke")
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.speaker_merges(done_old)
|
||||
.unwrap()
|
||||
.get("remote:2")
|
||||
.map(String::as_str),
|
||||
Some("remote:1")
|
||||
);
|
||||
assert_eq!(f.state.store.get_call(undecided_old).unwrap(), None);
|
||||
assert!(undecided_old_tracks.iter().all(|p| !p.exists()));
|
||||
for kept in [done_new, undecided_new, failed_old, uploading, cleanup] {
|
||||
assert!(has_audio(&f, kept), "call {kept} keeps its audio");
|
||||
}
|
||||
assert_eq!(f.state.store.remote_jobs(cleanup).unwrap().len(), 1);
|
||||
|
||||
// The next pass tries the skipped call again; nothing is done twice.
|
||||
drop(upload);
|
||||
let report = run_pass(&f.state, now);
|
||||
assert_eq!(report.audio_deleted, vec![uploading]);
|
||||
assert_eq!(report.calls_deleted, Vec::<CallId>::new());
|
||||
assert_eq!(report.skipped, vec![cleanup]);
|
||||
assert!(!has_audio(&f, uploading));
|
||||
}
|
||||
|
||||
/// The plan for the calls as they are now, with 7 days.
|
||||
fn plan(f: &Fixture, now: DateTime<Local>) -> Vec<RetentionAction> {
|
||||
plan_retention(&f.state.store.list_calls().unwrap(), now, 7)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_undecided_call_that_changed_after_planning_is_kept() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let failed = call(&f, "failed", now, 8, None);
|
||||
let processing = call(&f, "processing", now, 8, None);
|
||||
let transcribed = call(&f, "transcribed", now, 8, None);
|
||||
let plan = plan(&f, now);
|
||||
assert_eq!(plan.len(), 3);
|
||||
|
||||
// "Transkribieren" without a key marks the call failed (and lets go
|
||||
// of it) between planning and the delete.
|
||||
let store = &f.state.store;
|
||||
store
|
||||
.set_status(failed, CallStatus::Failed, Some("Kein API-Schlüssel"))
|
||||
.unwrap();
|
||||
store
|
||||
.set_status(processing, CallStatus::Processing, None)
|
||||
.unwrap();
|
||||
store
|
||||
.set_status(transcribed, CallStatus::Done, None)
|
||||
.unwrap();
|
||||
store.mark_transcribed(transcribed, now).unwrap();
|
||||
|
||||
let report = execute(&f.state, &plan, now, 7);
|
||||
assert_eq!(report.calls_deleted, Vec::<CallId>::new());
|
||||
assert_eq!(
|
||||
sorted(report.skipped),
|
||||
sorted(vec![failed, processing, transcribed])
|
||||
);
|
||||
for id in [failed, processing, transcribed] {
|
||||
assert!(has_audio(&f, id), "call {id} keeps its audio");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_transcribed_call_that_changed_after_planning_keeps_its_audio() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let failed = call(&f, "failed", now, 9, Some(8));
|
||||
let undecided = call(&f, "undecided", now, 9, Some(8));
|
||||
let plan = plan(&f, now);
|
||||
assert_eq!(plan.len(), 2);
|
||||
assert!(plan
|
||||
.iter()
|
||||
.all(|action| matches!(action, RetentionAction::DeleteAudio(_))));
|
||||
let store = &f.state.store;
|
||||
store
|
||||
.set_status(failed, CallStatus::Failed, Some("Fehler"))
|
||||
.unwrap();
|
||||
store
|
||||
.set_status(undecided, CallStatus::AwaitingDecision, None)
|
||||
.unwrap();
|
||||
|
||||
let report = execute(&f.state, &plan, now, 7);
|
||||
assert_eq!(report.audio_deleted, Vec::<CallId>::new());
|
||||
assert_eq!(sorted(report.skipped), sorted(vec![failed, undecided]));
|
||||
assert!(has_audio(&f, failed));
|
||||
assert!(has_audio(&f, undecided));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_deleted_after_planning_is_ignored() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let done = call(&f, "done", now, 9, Some(8));
|
||||
let undecided = call(&f, "undecided", now, 8, None);
|
||||
let plan = plan(&f, now);
|
||||
f.state.discard_call(done).unwrap();
|
||||
f.state.discard_call(undecided).unwrap();
|
||||
|
||||
assert_eq!(execute(&f.state, &plan, now, 7), PassReport::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_that_fails_does_not_stop_the_pass() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let broken = call(&f, "broken", now, 9, Some(8));
|
||||
// A directory where the mic track should be: removing it fails.
|
||||
let [mic, _] = tracks(&f, broken);
|
||||
fs::remove_file(&mic).unwrap();
|
||||
fs::create_dir(&mic).unwrap();
|
||||
let fine = call(&f, "fine", now, 9, Some(8));
|
||||
|
||||
let report = run_pass(&f.state, now);
|
||||
assert_eq!(report.failed, vec![broken]);
|
||||
assert_eq!(report.audio_deleted, vec![fine]);
|
||||
assert!(
|
||||
!f.state
|
||||
.store
|
||||
.get_call(broken)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.audio_deleted
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_changed_retention_period_applies_to_the_next_pass() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let id = call(&f, "a", now, 4, Some(3));
|
||||
assert_eq!(run_pass(&f.state, now), PassReport::default());
|
||||
|
||||
let mut settings = f.state.settings();
|
||||
settings.retention_days = 2;
|
||||
f.state.save_settings(settings).unwrap();
|
||||
assert_eq!(run_pass(&f.state, now).audio_deleted, vec![id]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_summary_counts_each_outcome() {
|
||||
let report = PassReport {
|
||||
audio_deleted: vec![1, 2],
|
||||
calls_deleted: vec![3],
|
||||
skipped: vec![4],
|
||||
cleanup_pending: vec![],
|
||||
failed: vec![],
|
||||
};
|
||||
assert_eq!(
|
||||
report.summary(),
|
||||
"2 audio deleted, 1 call deleted, 1 skipped, 0 failed"
|
||||
);
|
||||
}
|
||||
|
||||
const MIN: Duration = Duration::from_secs(60);
|
||||
|
||||
fn t0() -> SystemTime {
|
||||
SystemTime::UNIX_EPOCH + Duration::from_secs(1_800_000_000)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_first_pass_is_due_at_once() {
|
||||
assert!(pass_due(None, t0()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_next_pass_is_due_an_hour_later() {
|
||||
assert!(!pass_due(Some(t0()), t0() + 59 * MIN));
|
||||
assert!(pass_due(Some(t0()), t0() + 60 * MIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pass_is_due_after_standby_by_the_wall_clock() {
|
||||
assert!(pass_due(Some(t0()), t0() + 48 * 60 * MIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pass_is_due_when_the_clock_went_back() {
|
||||
assert!(pass_due(Some(t0()), t0() - 60 * MIN));
|
||||
}
|
||||
}
|
||||
+457
-13
@@ -40,6 +40,10 @@ const TEST_DURATION: Duration = Duration::from_secs(5);
|
||||
const TEST_POLL: Duration = Duration::from_millis(50);
|
||||
const ALREADY_PROCESSING: &str = "Wird bereits verarbeitet";
|
||||
const ALREADY_UPLOADING: &str = "Wird bereits hochgeladen";
|
||||
const BEING_RECORDED: &str = "Das Gespräch wird gerade aufgenommen";
|
||||
const PLAYING: &str = "Das Gespräch wird gerade abgespielt";
|
||||
const CHANGED: &str = "Das Gespräch hat sich inzwischen geändert";
|
||||
const NOT_FOUND: &str = "Gespräch nicht gefunden";
|
||||
|
||||
/// Why [`AppState::discard_call`] refused.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -47,6 +51,10 @@ pub enum DiscardError {
|
||||
/// DeepScript jobs of the call are still on record; their delete has to
|
||||
/// succeed first, or the cascade would forget them.
|
||||
CleanupPending,
|
||||
/// The call is recorded, processed or uploaded right now, or no longer
|
||||
/// what the caller expected ([`AppState::discard_call_if`]).
|
||||
Busy(&'static str),
|
||||
NotFound,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
@@ -56,6 +64,8 @@ impl std::fmt::Display for DiscardError {
|
||||
DiscardError::CleanupPending => f.write_str(
|
||||
"Daten bei DeepScript werden noch gelöscht – bitte später erneut versuchen.",
|
||||
),
|
||||
DiscardError::Busy(msg) => f.write_str(msg),
|
||||
DiscardError::NotFound => f.write_str(NOT_FOUND),
|
||||
DiscardError::Other(msg) => f.write_str(msg),
|
||||
}
|
||||
}
|
||||
@@ -67,6 +77,16 @@ impl From<String> for DiscardError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Why [`AppState::delete_audio`] did not delete a call's audio.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum AudioDeleteError {
|
||||
/// The call is in use, or no longer what the caller expected; the next
|
||||
/// retention pass tries again.
|
||||
Busy(&'static str),
|
||||
NotFound,
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
/// Payload of the `recording-state` event.
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
#[serde(tag = "state", rename_all = "lowercase")]
|
||||
@@ -102,16 +122,21 @@ pub struct CallBrief {
|
||||
pub started_at: DateTime<Local>,
|
||||
pub ended_at: Option<DateTime<Local>>,
|
||||
pub duration_secs: i64,
|
||||
/// What the language picker starts on
|
||||
/// ([`call_view::preselect_language`]).
|
||||
pub language: String,
|
||||
}
|
||||
|
||||
impl CallBrief {
|
||||
fn of(call: &Call) -> Self {
|
||||
/// `last_used_language` is the settings' `language`.
|
||||
fn of(call: &Call, last_used_language: &str) -> Self {
|
||||
Self {
|
||||
id: call.id,
|
||||
app: call.app.clone(),
|
||||
started_at: call.started_at,
|
||||
ended_at: call.ended_at,
|
||||
duration_secs: call_view::duration_secs(call),
|
||||
language: call_view::preselect_language(call, last_used_language),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,6 +444,15 @@ impl AppState {
|
||||
lock(&self.upload_confirmed_unsaved).insert(id);
|
||||
}
|
||||
|
||||
/// Remembers `language` as the last used one, preselected for the next
|
||||
/// call. Not saving it is only logged: the transcription it was chosen
|
||||
/// for goes ahead regardless.
|
||||
pub fn remember_language(&self, language: &str) {
|
||||
if let Err(e) = self.update_settings(|s| s.language = language.to_string()) {
|
||||
log::error!("could not remember the call language: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Changes and saves settings the app manages itself; saves only if
|
||||
/// something changed.
|
||||
fn update_settings(&self, change: impl FnOnce(&mut Settings)) -> Result<(), String> {
|
||||
@@ -626,7 +660,7 @@ impl AppState {
|
||||
match self.store.get_call(id) {
|
||||
Ok(Some(call)) => {
|
||||
return Some(PendingPrompt {
|
||||
brief: CallBrief::of(&call),
|
||||
brief: CallBrief::of(&call, &self.settings().language),
|
||||
more_waiting: queue.len() - 1,
|
||||
})
|
||||
}
|
||||
@@ -656,7 +690,10 @@ impl AppState {
|
||||
}
|
||||
|
||||
pub fn call_brief(&self, id: CallId) -> Result<CallBrief, String> {
|
||||
Ok(CallBrief::of(&self.find_call(id)?))
|
||||
Ok(CallBrief::of(
|
||||
&self.find_call(id)?,
|
||||
&self.settings().language,
|
||||
))
|
||||
}
|
||||
|
||||
/// All calls for the main window's list, newest first.
|
||||
@@ -723,8 +760,8 @@ impl AppState {
|
||||
}
|
||||
|
||||
/// Removes call `id`'s cached mix whoever holds it: with the call, and
|
||||
/// once its audio is deleted. The retention job, when it deletes a
|
||||
/// call's audio, calls this too.
|
||||
/// once its audio is deleted ([`AppState::delete_audio`] does the same
|
||||
/// while it holds the leases).
|
||||
pub fn remove_playback(&self, id: CallId) {
|
||||
let mut leases = lock(&self.playback);
|
||||
leases.latest.remove(&id);
|
||||
@@ -817,30 +854,44 @@ impl AppState {
|
||||
/// ([`AppState::claim_upload`]), or while its DeepScript jobs are still
|
||||
/// on record ([`DiscardError::CleanupPending`]).
|
||||
pub fn discard_call(&self, id: CallId) -> Result<usize, DiscardError> {
|
||||
self.discard_call_if(id, |_| true)
|
||||
}
|
||||
|
||||
/// Like [`AppState::discard_call`], but only if the call, read while
|
||||
/// nothing else can take it, still passes `still_wanted`; otherwise
|
||||
/// nothing is deleted ([`DiscardError::Busy`]).
|
||||
pub fn discard_call_if(
|
||||
&self,
|
||||
id: CallId,
|
||||
still_wanted: impl FnOnce(&Call) -> bool,
|
||||
) -> Result<usize, DiscardError> {
|
||||
if lock(&self.current)
|
||||
.as_ref()
|
||||
.is_some_and(|cur| cur.call_id == id)
|
||||
{
|
||||
return Err("Das Gespräch wird gerade aufgenommen".to_string().into());
|
||||
return Err(DiscardError::Busy(BEING_RECORDED));
|
||||
}
|
||||
// Both held until the call is gone, so neither a pipeline run nor an
|
||||
// upload can claim it meanwhile (same uploading -> store lock order
|
||||
// as `claim_upload`, so this can never deadlock against it).
|
||||
let processing = lock(&self.processing);
|
||||
if processing.contains(&id) {
|
||||
return Err(ALREADY_PROCESSING.to_string().into());
|
||||
return Err(DiscardError::Busy(ALREADY_PROCESSING));
|
||||
}
|
||||
let uploading = lock(&self.uploading);
|
||||
if uploading.contains(&id) {
|
||||
return Err(ALREADY_UPLOADING.to_string().into());
|
||||
return Err(DiscardError::Busy(ALREADY_UPLOADING));
|
||||
}
|
||||
let call = self
|
||||
.store
|
||||
.get_call(id)
|
||||
.map_err(|e| e.to_string())?
|
||||
.ok_or_else(|| "Gespräch nicht gefunden".to_string())?;
|
||||
.ok_or(DiscardError::NotFound)?;
|
||||
if call.status == CallStatus::Processing {
|
||||
return Err(ALREADY_PROCESSING.to_string().into());
|
||||
return Err(DiscardError::Busy(ALREADY_PROCESSING));
|
||||
}
|
||||
if !still_wanted(&call) {
|
||||
return Err(DiscardError::Busy(CHANGED));
|
||||
}
|
||||
let remote_jobs = self.store.remote_jobs(id).map_err(|e| e.to_string())?;
|
||||
if !remote_jobs.is_empty() {
|
||||
@@ -880,6 +931,79 @@ impl AppState {
|
||||
Ok(self.prompts_waiting())
|
||||
}
|
||||
|
||||
/// Deletes a transcribed (`Done`) call's audio for the retention job:
|
||||
/// both track files and its cached mix, then marks the row
|
||||
/// (`audio_deleted`). Transcript, title, speaker names and merges and the
|
||||
/// CRM upload stay. Refused ([`AudioDeleteError::Busy`]) while the call
|
||||
/// is recorded, processed (or its remote jobs cleaned up), uploaded or a
|
||||
/// player holds its mix, and unless the row, read while nothing else can
|
||||
/// take the call, is `Done` with its audio not yet deleted and passes
|
||||
/// `still_due`.
|
||||
/// Already missing files are fine; a file that cannot be deleted leaves
|
||||
/// the row unmarked, so the next pass tries again.
|
||||
pub fn delete_audio(
|
||||
&self,
|
||||
id: CallId,
|
||||
still_due: impl FnOnce(&Call) -> bool,
|
||||
) -> Result<(), AudioDeleteError> {
|
||||
if lock(&self.current)
|
||||
.as_ref()
|
||||
.is_some_and(|cur| cur.call_id == id)
|
||||
{
|
||||
return Err(AudioDeleteError::Busy(BEING_RECORDED));
|
||||
}
|
||||
// All held until the row is marked, so no run, upload or player can
|
||||
// take the call meanwhile (same processing -> uploading -> playback
|
||||
// -> store lock order as `discard_call` and `prepare_playback`).
|
||||
let processing = lock(&self.processing);
|
||||
if processing.contains(&id) {
|
||||
return Err(AudioDeleteError::Busy(ALREADY_PROCESSING));
|
||||
}
|
||||
let uploading = lock(&self.uploading);
|
||||
if uploading.contains(&id) {
|
||||
return Err(AudioDeleteError::Busy(ALREADY_UPLOADING));
|
||||
}
|
||||
let mut leases = lock(&self.playback);
|
||||
if leases.latest.contains_key(&id) {
|
||||
return Err(AudioDeleteError::Busy(PLAYING));
|
||||
}
|
||||
let call = self
|
||||
.store
|
||||
.get_call(id)
|
||||
.map_err(|e| AudioDeleteError::Failed(e.to_string()))?
|
||||
.ok_or(AudioDeleteError::NotFound)?;
|
||||
match call.status {
|
||||
CallStatus::Recording => return Err(AudioDeleteError::Busy(BEING_RECORDED)),
|
||||
CallStatus::Processing => return Err(AudioDeleteError::Busy(ALREADY_PROCESSING)),
|
||||
// Failed and undecided calls keep their audio.
|
||||
CallStatus::Done if !call.audio_deleted && still_due(&call) => {}
|
||||
_ => return Err(AudioDeleteError::Busy(CHANGED)),
|
||||
}
|
||||
// Every file is tried, so as little audio as possible stays behind.
|
||||
let mut failed = None;
|
||||
for path in [&call.mic_path, &call.out_path] {
|
||||
if path.as_os_str().is_empty() {
|
||||
continue;
|
||||
}
|
||||
match fs::remove_file(path) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.kind() == ErrorKind::NotFound => {}
|
||||
Err(e) => {
|
||||
log::error!("call {id}: could not delete {}: {e}", path.display());
|
||||
failed = Some(format!("Audiodatei konnte nicht gelöscht werden: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(msg) = failed {
|
||||
return Err(AudioDeleteError::Failed(msg));
|
||||
}
|
||||
leases.latest.remove(&id);
|
||||
playback::remove_cached(&self.playback_dir, id);
|
||||
self.store
|
||||
.mark_audio_deleted(id)
|
||||
.map_err(|e| AudioDeleteError::Failed(format!("Löschen nicht vermerkt: {e}")))
|
||||
}
|
||||
|
||||
/// Reserves `id` for one pipeline run; release it with
|
||||
/// [`AppState::release_processing`] when the run ends. A call that waits
|
||||
/// for the decision can be processed; a failed one only on `retry`, or
|
||||
@@ -1091,11 +1215,36 @@ mod tests {
|
||||
started_at: at(10, 14, 0),
|
||||
ended_at: Some(at(10, 46, 30)),
|
||||
duration_secs: 32 * 60 + 30,
|
||||
language: "de".into(),
|
||||
}
|
||||
);
|
||||
assert!(f.state.call_brief(id + 1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_brief_preselects_the_calls_language_else_the_last_used() {
|
||||
let f = fixture();
|
||||
let (id, _, _) = finished_call(&f, "a");
|
||||
f.state.remember_language("fr");
|
||||
assert_eq!(f.state.call_brief(id).unwrap().language, "fr");
|
||||
|
||||
f.state.store.set_language(id, "it").unwrap();
|
||||
assert_eq!(f.state.call_brief(id).unwrap().language, "it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_last_used_language_is_remembered_across_restarts() {
|
||||
let f = fixture();
|
||||
|
||||
f.state.remember_language("es");
|
||||
|
||||
assert_eq!(f.state.settings().language, "es");
|
||||
assert_eq!(
|
||||
Settings::load(&f.dir.path().join("settings.json")).language,
|
||||
"es"
|
||||
);
|
||||
}
|
||||
|
||||
fn queued(f: &Fixture) -> Option<(CallId, usize)> {
|
||||
f.state
|
||||
.pending_prompt()
|
||||
@@ -1212,7 +1361,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
f.state.discard_call(id),
|
||||
Err(DiscardError::Other("Wird bereits verarbeitet".to_string()))
|
||||
Err(DiscardError::Busy("Wird bereits verarbeitet"))
|
||||
);
|
||||
f.state.release_processing(id);
|
||||
f.state
|
||||
@@ -1221,7 +1370,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
f.state.discard_call(id),
|
||||
Err(DiscardError::Other("Wird bereits verarbeitet".to_string()))
|
||||
Err(DiscardError::Busy("Wird bereits verarbeitet"))
|
||||
);
|
||||
|
||||
assert!(mic.exists());
|
||||
@@ -1283,7 +1432,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
f.state.discard_call(id),
|
||||
Err(DiscardError::Other("Wird bereits hochgeladen".to_string()))
|
||||
Err(DiscardError::Busy("Wird bereits hochgeladen"))
|
||||
);
|
||||
assert!(mic.exists());
|
||||
assert!(out.exists());
|
||||
@@ -2138,4 +2287,299 @@ mod tests {
|
||||
assert!(!f.dir.path().join("playback").exists());
|
||||
f.state.clear_playback_cache(); // nothing left: no error
|
||||
}
|
||||
|
||||
/// A transcribed (`Done`) call with both tracks, a transcript, a title,
|
||||
/// a CRM upload and a cached mix nobody holds.
|
||||
fn transcribed_call_with_audio(f: &Fixture) -> CallId {
|
||||
let id = transcribed_call(f);
|
||||
let store = &f.state.store;
|
||||
store.set_status(id, CallStatus::Done, None).unwrap();
|
||||
store.mark_transcribed(id, at(11, 0, 0)).unwrap();
|
||||
store.set_title(id, Some("Weinbestellung")).unwrap();
|
||||
f.state.mark_uploaded(id, "4711").unwrap();
|
||||
fs::create_dir_all(f.dir.path().join("playback")).unwrap();
|
||||
fs::write(playback_file(f, id), b"mix").unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
/// Asserts that `delete_audio` left call `id` (`mic`, `out`) untouched.
|
||||
fn assert_audio_kept(f: &Fixture, id: CallId) {
|
||||
let call = f.state.store.get_call(id).unwrap().unwrap();
|
||||
assert!(call.mic_path.exists());
|
||||
assert!(call.out_path.exists());
|
||||
assert!(!call.audio_deleted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleting_audio_keeps_the_transcript_title_and_upload() {
|
||||
let f = fixture();
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
let before = f.state.store.get_call(id).unwrap().unwrap();
|
||||
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
|
||||
let after = f.state.store.get_call(id).unwrap().unwrap();
|
||||
assert!(!before.mic_path.exists());
|
||||
assert!(!before.out_path.exists());
|
||||
assert!(!playback_file(&f, id).exists());
|
||||
assert!(after.audio_deleted);
|
||||
assert_eq!(after.status, CallStatus::Done);
|
||||
assert_eq!(after.title.as_deref(), Some("Weinbestellung"));
|
||||
assert_eq!(after.crm_transcript_id.as_deref(), Some("4711"));
|
||||
assert_eq!(after.transcribed_at, before.transcribed_at);
|
||||
assert_eq!(f.state.store.segments(id).unwrap().len(), 3);
|
||||
let detail = f.state.call_detail(id).unwrap();
|
||||
assert!(detail.audio_deleted);
|
||||
assert!(!detail.audio_available);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_already_missing_is_still_marked_deleted() {
|
||||
let f = fixture();
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
let call = f.state.store.get_call(id).unwrap().unwrap();
|
||||
fs::remove_file(&call.mic_path).unwrap();
|
||||
fs::remove_file(&call.out_path).unwrap();
|
||||
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
assert!(f.state.store.get_call(id).unwrap().unwrap().audio_deleted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_is_not_deleted_while_the_call_is_uploaded() {
|
||||
let f = fixture();
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
// Another backend's upload, so this build can upload it again.
|
||||
f.state
|
||||
.store
|
||||
.set_uploaded(id, "1", "https://other.example", at(12, 0, 0))
|
||||
.unwrap();
|
||||
let claim = f.state.claim_upload(id).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(ALREADY_UPLOADING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
drop(claim);
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_is_not_deleted_while_the_call_is_processed() {
|
||||
let f = fixture();
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
// A cleanup of its remote jobs reserves a call of any status.
|
||||
assert!(f.state.reserve_processing(id));
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(ALREADY_PROCESSING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
f.state.release_processing(id);
|
||||
|
||||
f.state
|
||||
.store
|
||||
.set_status(id, CallStatus::Processing, None)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(ALREADY_PROCESSING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_is_not_deleted_while_the_call_is_recorded() {
|
||||
let f = fixture();
|
||||
let dir = f.dir.path();
|
||||
let (mic, out) = (dir.join("r-mic.wav"), dir.join("r-out.wav"));
|
||||
fs::write(&mic, b"mic").unwrap();
|
||||
fs::write(&out, b"out").unwrap();
|
||||
let id = f
|
||||
.state
|
||||
.store
|
||||
.create_call("Microsoft Teams", at(10, 0, 0), &mic, &out)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(BEING_RECORDED))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_is_not_deleted_while_a_player_holds_its_mix() {
|
||||
let f = fixture();
|
||||
let id = playable_call(&f, "a");
|
||||
f.state
|
||||
.store
|
||||
.set_status(id, CallStatus::Done, None)
|
||||
.unwrap();
|
||||
let lease = f.state.prepare_playback(id).unwrap().lease;
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(PLAYING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
assert!(playback_file(&f, id).exists());
|
||||
|
||||
f.state.release_playback(id, lease);
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_that_cannot_be_deleted_stays_unmarked() {
|
||||
let f = fixture();
|
||||
let dir = f.dir.path();
|
||||
// A directory where the mic track should be: removing it fails.
|
||||
let mic = dir.join("x-mic.wav");
|
||||
fs::create_dir(&mic).unwrap();
|
||||
let out = dir.join("x-out.wav");
|
||||
fs::write(&out, b"out").unwrap();
|
||||
let store = &f.state.store;
|
||||
let id = store
|
||||
.create_call("Microsoft Teams", at(10, 0, 0), &mic, &out)
|
||||
.unwrap();
|
||||
store.finish_recording(id, at(10, 5, 0), false).unwrap();
|
||||
store.set_status(id, CallStatus::Done, None).unwrap();
|
||||
|
||||
assert!(matches!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Failed(_))
|
||||
));
|
||||
assert!(!f.state.store.get_call(id).unwrap().unwrap().audio_deleted);
|
||||
// What could be deleted is gone.
|
||||
assert!(!out.exists());
|
||||
|
||||
fs::remove_dir(&mic).unwrap();
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
assert!(f.state.store.get_call(id).unwrap().unwrap().audio_deleted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_call_is_not_found() {
|
||||
let f = fixture();
|
||||
assert_eq!(
|
||||
f.state.delete_audio(999, |_| true),
|
||||
Err(AudioDeleteError::NotFound)
|
||||
);
|
||||
assert_eq!(f.state.discard_call(999), Err(DiscardError::NotFound));
|
||||
assert_eq!(
|
||||
DiscardError::NotFound.to_string(),
|
||||
"Gespräch nicht gefunden"
|
||||
);
|
||||
}
|
||||
|
||||
/// A capture source that starts and then delivers nothing.
|
||||
struct SilentSource;
|
||||
|
||||
impl CaptureSource for SilentSource {
|
||||
fn start(
|
||||
&mut self,
|
||||
_on_data: recorder_core::capture::DataCallback,
|
||||
) -> Result<recorder_core::capture::StreamFormat, recorder_core::capture::CaptureError>
|
||||
{
|
||||
Ok(recorder_core::capture::StreamFormat {
|
||||
rate: 16_000,
|
||||
channels: 1,
|
||||
})
|
||||
}
|
||||
|
||||
fn stop(&mut self) {}
|
||||
|
||||
fn failure(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_of_the_running_recording_is_not_deleted() {
|
||||
let f = fixture();
|
||||
// A row that looks deletable: only `current` says it records.
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
let dir = f.dir.path();
|
||||
let recorder = Recorder::start(
|
||||
Box::new(SilentSource),
|
||||
Box::new(SilentSource),
|
||||
&dir.join("live-mic.wav"),
|
||||
&dir.join("live-out.wav"),
|
||||
)
|
||||
.unwrap();
|
||||
*lock(&f.state.current) = Some(CurrentRecording {
|
||||
call_id: id,
|
||||
app: "Microsoft Teams".into(),
|
||||
started_at: at(10, 0, 0),
|
||||
detected: false,
|
||||
recorder,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(BEING_RECORDED))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
lock(&f.state.current).take().unwrap().recorder.discard();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_the_audio_of_a_transcribed_call_is_deleted() {
|
||||
let f = fixture();
|
||||
let (undecided, _, _) = finished_call(&f, "u");
|
||||
let (failed, _, _) = finished_call(&f, "f");
|
||||
f.state
|
||||
.store
|
||||
.set_status(failed, CallStatus::Failed, Some("Fehler"))
|
||||
.unwrap();
|
||||
for id in [undecided, failed] {
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(CHANGED))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_the_caller_no_longer_wants_deleted_is_kept() {
|
||||
let f = fixture();
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
let mut seen = None;
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |call| {
|
||||
seen = Some(call.id);
|
||||
false
|
||||
}),
|
||||
Err(AudioDeleteError::Busy(CHANGED))
|
||||
);
|
||||
assert_eq!(seen, Some(id));
|
||||
assert_audio_kept(&f, id);
|
||||
assert!(playback_file(&f, id).exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_the_caller_no_longer_wants_deleted_is_kept() {
|
||||
let f = fixture();
|
||||
let (id, mic, out) = finished_call(&f, "a");
|
||||
f.state.queue_prompt(id);
|
||||
|
||||
assert_eq!(
|
||||
f.state
|
||||
.discard_call_if(id, |call| call.status == CallStatus::Failed),
|
||||
Err(DiscardError::Busy(CHANGED))
|
||||
);
|
||||
assert!(mic.exists());
|
||||
assert!(out.exists());
|
||||
assert!(f.state.store.get_call(id).unwrap().is_some());
|
||||
assert_eq!(f.state.prompts_waiting(), 1);
|
||||
|
||||
assert_eq!(
|
||||
f.state
|
||||
.discard_call_if(id, |call| call.status == CallStatus::AwaitingDecision),
|
||||
Ok(0)
|
||||
);
|
||||
assert_eq!(f.state.store.get_call(id).unwrap(), None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Gesprächsrekorder",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"identifier": "eu.euvino.callrecorder",
|
||||
"build": {
|
||||
"frontendDist": "../ui/dist",
|
||||
@@ -36,7 +36,7 @@
|
||||
"label": "prompt",
|
||||
"title": "Gespräch beendet",
|
||||
"url": "index.html#/prompt",
|
||||
"width": 340,
|
||||
"width": 400,
|
||||
"height": 180,
|
||||
"alwaysOnTop": true,
|
||||
"visible": false,
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ui",
|
||||
"private": true,
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { CALL_LANGUAGES } from './api'
|
||||
|
||||
// The language a call is transcribed in, picked next to "Transkribieren"
|
||||
// and "Erneut versuchen".
|
||||
let { value = $bindable(), disabled = false }: { value: string; disabled?: boolean } = $props()
|
||||
</script>
|
||||
|
||||
<select bind:value {disabled} title="Sprache des Gesprächs" aria-label="Sprache des Gesprächs">
|
||||
{#each CALL_LANGUAGES as language (language.code)}
|
||||
<option value={language.code}>{language.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
@@ -78,6 +78,9 @@
|
||||
}
|
||||
return !destroyed
|
||||
} catch (err) {
|
||||
// A retry creates a new blob: this one is of no use any more.
|
||||
if (blobUrl) URL.revokeObjectURL(blobUrl)
|
||||
blobUrl = null
|
||||
if (destroyed) return false
|
||||
error = err instanceof MediaError ? LOAD_FAILED : errorText(err)
|
||||
loading = null // a later click tries again
|
||||
|
||||
+18
-2
@@ -5,10 +5,20 @@ import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||
|
||||
export type CallId = number
|
||||
|
||||
/** The languages a call can be transcribed in (the backend's `CALL_LANGUAGES`). */
|
||||
export const CALL_LANGUAGES = [
|
||||
{ code: 'de', label: 'Deutsch' },
|
||||
{ code: 'en', label: 'Englisch' },
|
||||
{ code: 'es', label: 'Spanisch' },
|
||||
{ code: 'fr', label: 'Französisch' },
|
||||
{ code: 'it', label: 'Italienisch' },
|
||||
] as const
|
||||
|
||||
export interface Settings {
|
||||
allowlist: string[]
|
||||
mic_device: string | null
|
||||
output_device: string | null
|
||||
/** Language of the transcription started last; set by the app, not the settings page. */
|
||||
language: string
|
||||
deepscript_model: string
|
||||
/** Custom words/names submitted with every transcription. */
|
||||
@@ -72,6 +82,8 @@ export interface CallBrief {
|
||||
started_at: string
|
||||
ended_at: string | null
|
||||
duration_secs: number
|
||||
/** What the language picker starts on: the call's own language, else the last used. */
|
||||
language: string
|
||||
}
|
||||
|
||||
/** The call the end-of-call prompt shows, and how many wait behind it. */
|
||||
@@ -144,6 +156,8 @@ export interface CallDetail {
|
||||
audio_available: boolean
|
||||
/** Retention deleted the call's audio (not just: the files are missing). */
|
||||
audio_deleted: boolean
|
||||
/** What the language picker starts on: the call's own language, else the last used. */
|
||||
language: string
|
||||
}
|
||||
|
||||
/** A call's two tracks mixed into one file, ready to play from
|
||||
@@ -197,8 +211,10 @@ export const stopRecording = () => invoke<void>('stop_recording')
|
||||
export const discardCurrentRecording = () => invoke<void>('discard_current_recording')
|
||||
export const getPendingPrompt = () => invoke<PendingPrompt | null>('get_pending_prompt')
|
||||
export const getCallBrief = (id: CallId) => invoke<CallBrief>('get_call_brief', { id })
|
||||
export const transcribeCall = (id: CallId) => invoke<void>('transcribe_call', { id })
|
||||
export const retryCall = (id: CallId) => invoke<void>('retry_call', { id })
|
||||
export const transcribeCall = (id: CallId, language: string) =>
|
||||
invoke<void>('transcribe_call', { id, language })
|
||||
export const retryCall = (id: CallId, language: string) =>
|
||||
invoke<void>('retry_call', { id, language })
|
||||
export const discardCall = (id: CallId) => invoke<void>('discard_call', { id })
|
||||
/** Mixes the call's tracks (or reuses the cached mix); refused while the
|
||||
* call is recorded or processed and once its audio is gone. */
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
} from '../lib/api'
|
||||
import CallList from '../lib/CallList.svelte'
|
||||
import { formatDateTime, formatDetailTime, formatMinutes } from '../lib/format'
|
||||
import LanguageSelect from '../lib/LanguageSelect.svelte'
|
||||
import Player from '../lib/Player.svelte'
|
||||
import { segmentAt } from '../lib/playback'
|
||||
import StatusPill from '../lib/StatusPill.svelte'
|
||||
@@ -45,6 +46,8 @@
|
||||
let selectedId = $state<CallId | null>(null)
|
||||
let detail = $state<CallDetail | null>(null)
|
||||
let detailError = $state('')
|
||||
/** The language picked for the shown call's transcription. */
|
||||
let language = $state('de')
|
||||
let actionError = $state('')
|
||||
let busy = $state(false)
|
||||
|
||||
@@ -68,6 +71,7 @@
|
||||
let follow = $state(true)
|
||||
/** For "… werden N Tage nach der Transkription gelöscht". */
|
||||
let retentionDays = $state<number | null>(null)
|
||||
let retentionPeriod = $derived(retentionDays === 1 ? '1 Tag' : `${retentionDays} Tage`)
|
||||
|
||||
let editingTitle = $state(false)
|
||||
let titleDraft = $state('')
|
||||
@@ -108,6 +112,12 @@
|
||||
try {
|
||||
const next = await getCall(id)
|
||||
if (request === detailRequest && id === selectedId) {
|
||||
// A refresh of the same call keeps what the user picked, unless the
|
||||
// backend's suggestion changed (e.g. it was transcribed from the
|
||||
// prompt in another language and failed).
|
||||
if (next.call.id !== detail?.call.id || next.language !== detail?.language) {
|
||||
language = next.language
|
||||
}
|
||||
detail = next
|
||||
detailError = ''
|
||||
}
|
||||
@@ -218,8 +228,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
const transcribe = () => run(transcribeCall)
|
||||
const retry = () => run(retryCall)
|
||||
const transcribe = () => run((id) => transcribeCall(id, language))
|
||||
const retry = () => run((id) => retryCall(id, language))
|
||||
const discard = () =>
|
||||
run(discardCall, () => {
|
||||
clearSelection()
|
||||
@@ -465,9 +475,11 @@
|
||||
{/if}
|
||||
<span class="actions">
|
||||
{#if call.status === 'awaiting_decision'}
|
||||
<LanguageSelect bind:value={language} disabled={busy} />
|
||||
<button class="btn primary" disabled={busy} onclick={transcribe}>Transkribieren</button>
|
||||
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
||||
{:else if call.status === 'failed'}
|
||||
<LanguageSelect bind:value={language} disabled={busy} />
|
||||
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
|
||||
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
||||
{:else if call.status === 'done'}
|
||||
@@ -519,7 +531,7 @@
|
||||
</div>
|
||||
{:else if detail.audio_deleted && retentionDays !== null}
|
||||
<p class="muted no-audio">
|
||||
Audio nicht mehr vorhanden – Aufnahmen werden {retentionDays} Tage nach der
|
||||
Audio nicht mehr vorhanden – Aufnahmen werden {retentionPeriod} nach der
|
||||
Transkription gelöscht (<a href="#/settings">Einstellungen</a>).
|
||||
</p>
|
||||
{:else if detail.audio_deleted}
|
||||
|
||||
@@ -11,13 +11,21 @@
|
||||
type PendingPrompt,
|
||||
} from '../lib/api'
|
||||
import { formatMinutes, formatTimeRange } from '../lib/format'
|
||||
import LanguageSelect from '../lib/LanguageSelect.svelte'
|
||||
|
||||
let brief = $state<PendingPrompt | null>(null)
|
||||
let busy = $state(false)
|
||||
let error = $state('')
|
||||
let language = $state('de')
|
||||
|
||||
function show(next: PendingPrompt | null) {
|
||||
if (next?.id !== brief?.id) error = ''
|
||||
// A refresh of the same call keeps what the user picked, unless the
|
||||
// backend's suggestion changed (e.g. a transcription started from the
|
||||
// main window in another language).
|
||||
if (next && (next.id !== brief?.id || next.language !== brief?.language)) {
|
||||
language = next.language
|
||||
}
|
||||
brief = next
|
||||
}
|
||||
|
||||
@@ -54,6 +62,8 @@
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
|
||||
const transcribe = () => run((id) => transcribeCall(id, language))
|
||||
</script>
|
||||
|
||||
<main class="prompt">
|
||||
@@ -64,7 +74,8 @@
|
||||
<div class="muted">Weitere Gespräche warten: {brief.more_waiting}</div>
|
||||
{/if}
|
||||
<div class="actions">
|
||||
<button class="btn primary" disabled={busy} onclick={() => run(transcribeCall)}>
|
||||
<LanguageSelect bind:value={language} disabled={busy} />
|
||||
<button class="btn primary" disabled={busy} onclick={transcribe}>
|
||||
Transkribieren
|
||||
</button>
|
||||
<button class="btn danger" disabled={busy} onclick={() => run(discardCall)}>Verwerfen</button>
|
||||
|
||||
@@ -266,13 +266,23 @@
|
||||
settings ? delayError(settings.start_after_secs, 1, 30, 'Start nach') : '',
|
||||
)
|
||||
let endError = $derived(settings ? delayError(settings.end_after_secs, 3, 120, 'Ende nach') : '')
|
||||
/** The range the backend accepts (`RETENTION_DAYS`). */
|
||||
function retentionValid(days: number | null | undefined): days is number {
|
||||
return typeof days === 'number' && Number.isInteger(days) && days >= 1 && days <= 3650
|
||||
}
|
||||
|
||||
/** The retention period in the hint ("7 Tage", "1 Tag"; "N Tage" while
|
||||
* the field holds no valid value). */
|
||||
let retentionShown = $derived.by(() => {
|
||||
const days = settings?.retention_days
|
||||
if (!retentionValid(days)) return 'N Tage'
|
||||
return days === 1 ? '1 Tag' : `${days} Tage`
|
||||
})
|
||||
|
||||
async function persist() {
|
||||
if (!settings) return
|
||||
if (startError || endError) throw startError || endError
|
||||
if (!Number.isInteger(settings.retention_days) || settings.retention_days < 1) {
|
||||
throw 'Aufbewahrung: bitte eine ganze Zahl ab 1 eingeben'
|
||||
}
|
||||
if (!retentionValid(settings.retention_days)) throw 'Aufbewahrung: 1–3650 Tage'
|
||||
settings.vocabulary = vocabularyText.split('\n')
|
||||
await saveSettings($state.snapshot(settings))
|
||||
// Re-read: the backend trims/dedupes the vocabulary, so the textarea
|
||||
@@ -472,13 +482,13 @@
|
||||
<section class="card">
|
||||
<h2>Allgemein</h2>
|
||||
<div class="grid">
|
||||
<label for="language">Sprache der Gespräche</label>
|
||||
<select id="language" bind:value={settings.language}>
|
||||
<option value="de">Deutsch</option>
|
||||
<option value="en">Englisch</option>
|
||||
</select>
|
||||
<label for="retention">Aufbewahrung der Audiodateien</label>
|
||||
<span><input id="retention" type="number" min="1" bind:value={settings.retention_days} /> Tage</span>
|
||||
<span><input id="retention" type="number" min="1" max="3650" bind:value={settings.retention_days} /> Tage</span>
|
||||
<span></span>
|
||||
<span class="muted">
|
||||
Audio wird {retentionShown} nach der Transkription gelöscht, nicht transkribierte
|
||||
Aufnahmen {retentionShown} nach dem Gespräch; das Transkript bleibt.
|
||||
</span>
|
||||
<label for="autostart">Beim Anmelden starten</label>
|
||||
<input id="autostart" type="checkbox" bind:checked={settings.autostart} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user