From 90ae1690ab88392439b161253211ebe40770d5f7 Mon Sep 17 00:00:00 2001 From: sudoeren Date: Thu, 27 Aug 2026 21:37:15 +0300 Subject: [PATCH] Fix the cleanup prompt language and harden detection parsing Review found the detected language was only switching the glossary rule, not the base prompt: a detected Turkish recording with an English interface got the English cleanup prompt with a Turkish glossary footnote. Both now follow the spoken language, and the detected-language value is guarded against a server that returns something other than a string. The record reply is covered by a CLI test. --- dikte/api.py | 3 ++- dikte/config.py | 6 ++++-- tests/test_cli.py | 7 +++++++ tests/test_config.py | 6 ++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dikte/api.py b/dikte/api.py index 04a0473..c83be1b 100644 --- a/dikte/api.py +++ b/dikte/api.py @@ -476,8 +476,9 @@ def transcribe_detected(target, audio_path, language="", prompt="", timeout=300, text = _local_text(data.get("text") or "").strip() if not text: raise ApiError(t("Transcript came back empty.")) + detected = data.get("detected_language") code = _DETECTED_TO_CODE.get( - (data.get("detected_language") or "").strip().lower(), "") + detected.strip().lower(), "") if isinstance(detected, str) else "" return text, code text = transcribe(target, audio_path, language=language, prompt=prompt, timeout=timeout, aborter=aborter) diff --git a/dikte/config.py b/dikte/config.py index 8534ad1..b46f7b2 100644 --- a/dikte/config.py +++ b/dikte/config.py @@ -717,9 +717,11 @@ class Config: turkish = (speech == "tr") if speech else i18n.language() == "tr" if subtitles: prompt = (self["file_cleanup_prompt"].strip() - or default_file_cleanup_prompt()) + or (FILE_CLEANUP_PROMPT_TR if turkish + else FILE_CLEANUP_PROMPT_EN)) else: - prompt = self["cleanup_prompt"].strip() or default_cleanup_prompt() + prompt = (self["cleanup_prompt"].strip() + or (CLEANUP_PROMPT_TR if turkish else CLEANUP_PROMPT_EN)) glossary = self["transcribe_prompt"].strip() if with_speakers: glossary = "\n".join(x for x in (glossary, self.participants()) if x) diff --git a/tests/test_cli.py b/tests/test_cli.py index dc06388..5d30d9a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -722,6 +722,13 @@ class Replies(DikteTest): self.assertEqual(code, 0) self.assertEqual(out.strip(), "Book it for Thursday.") + def test_the_json_answer_carries_the_detected_language(self): + code, out, _ = self.run_verb( + ["--json", "record"], + {"ok": True, "text": "Selam", "speech_language": "tr"}) + self.assertEqual(code, 0) + self.assertEqual(json.loads(out)["speech_language"], "tr") + def test_a_dictation_that_failed(self): code, out, err = self.run_verb(["stop", "--wait"], {"ok": False, "error": "No speech detected"}) diff --git a/tests/test_config.py b/tests/test_config.py index 13a1550..692cbca 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -264,8 +264,10 @@ class CleanupPrompt(DikteTest): than the interface language.""" self.write_config({"ui_language": "en", "transcribe_prompt": "Paraşüt"}) conf = cfg.Config() - self.assertIn("KONUŞMACININ KULLANDIĞI İSİM VE TERİMLER", - conf.cleanup_prompt(speech="tr")) + prompt = conf.cleanup_prompt(speech="tr") + self.assertEqual(prompt, cfg.CLEANUP_PROMPT_TR + + cfg.GLOSSARY_RULE_TR.format(glossary="Paraşüt")) + self.assertIn("KONUŞMACININ KULLANDIĞI İSİM VE TERİMLER", prompt) self.assertIn("NAMES AND TERMS THE SPEAKER USES", conf.cleanup_prompt(speech="de"))