mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 10:56:10 +00:00
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.
This commit is contained in:
+2
-1
@@ -476,8 +476,9 @@ def transcribe_detected(target, audio_path, language="", prompt="", timeout=300,
|
|||||||
text = _local_text(data.get("text") or "").strip()
|
text = _local_text(data.get("text") or "").strip()
|
||||||
if not text:
|
if not text:
|
||||||
raise ApiError(t("Transcript came back empty."))
|
raise ApiError(t("Transcript came back empty."))
|
||||||
|
detected = data.get("detected_language")
|
||||||
code = _DETECTED_TO_CODE.get(
|
code = _DETECTED_TO_CODE.get(
|
||||||
(data.get("detected_language") or "").strip().lower(), "")
|
detected.strip().lower(), "") if isinstance(detected, str) else ""
|
||||||
return text, code
|
return text, code
|
||||||
text = transcribe(target, audio_path, language=language, prompt=prompt,
|
text = transcribe(target, audio_path, language=language, prompt=prompt,
|
||||||
timeout=timeout, aborter=aborter)
|
timeout=timeout, aborter=aborter)
|
||||||
|
|||||||
+4
-2
@@ -717,9 +717,11 @@ class Config:
|
|||||||
turkish = (speech == "tr") if speech else i18n.language() == "tr"
|
turkish = (speech == "tr") if speech else i18n.language() == "tr"
|
||||||
if subtitles:
|
if subtitles:
|
||||||
prompt = (self["file_cleanup_prompt"].strip()
|
prompt = (self["file_cleanup_prompt"].strip()
|
||||||
or default_file_cleanup_prompt())
|
or (FILE_CLEANUP_PROMPT_TR if turkish
|
||||||
|
else FILE_CLEANUP_PROMPT_EN))
|
||||||
else:
|
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()
|
glossary = self["transcribe_prompt"].strip()
|
||||||
if with_speakers:
|
if with_speakers:
|
||||||
glossary = "\n".join(x for x in (glossary, self.participants()) if x)
|
glossary = "\n".join(x for x in (glossary, self.participants()) if x)
|
||||||
|
|||||||
@@ -722,6 +722,13 @@ class Replies(DikteTest):
|
|||||||
self.assertEqual(code, 0)
|
self.assertEqual(code, 0)
|
||||||
self.assertEqual(out.strip(), "Book it for Thursday.")
|
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):
|
def test_a_dictation_that_failed(self):
|
||||||
code, out, err = self.run_verb(["stop", "--wait"],
|
code, out, err = self.run_verb(["stop", "--wait"],
|
||||||
{"ok": False, "error": "No speech detected"})
|
{"ok": False, "error": "No speech detected"})
|
||||||
|
|||||||
@@ -264,8 +264,10 @@ class CleanupPrompt(DikteTest):
|
|||||||
than the interface language."""
|
than the interface language."""
|
||||||
self.write_config({"ui_language": "en", "transcribe_prompt": "Paraşüt"})
|
self.write_config({"ui_language": "en", "transcribe_prompt": "Paraşüt"})
|
||||||
conf = cfg.Config()
|
conf = cfg.Config()
|
||||||
self.assertIn("KONUŞMACININ KULLANDIĞI İSİM VE TERİMLER",
|
prompt = conf.cleanup_prompt(speech="tr")
|
||||||
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",
|
self.assertIn("NAMES AND TERMS THE SPEAKER USES",
|
||||||
conf.cleanup_prompt(speech="de"))
|
conf.cleanup_prompt(speech="de"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user