fix(voice): race slow streaming asr finalize
This commit is contained in:
@@ -607,8 +607,12 @@ def _voice_reply_with_name(language: str, reply_text: str, name: str | None) ->
|
||||
short_name = _voice_short_name(name)
|
||||
if not short_name:
|
||||
return reply_text
|
||||
reply_text = _voice_strip_reply_greeting_prefix(reply_text, name=short_name)
|
||||
prefix = _voice_disclosure_prefix(language)
|
||||
normalized_short = _voice_text_key(short_name)
|
||||
first_words = _voice_text_key(" ".join(str(reply_text or "").split()[:8])).split()
|
||||
if normalized_short in first_words:
|
||||
return reply_text
|
||||
if reply_text.startswith(prefix):
|
||||
rest = reply_text[len(prefix) :].lstrip()
|
||||
if _voice_text_key(rest).startswith(normalized_short):
|
||||
@@ -1344,6 +1348,28 @@ def _voice_is_midcall_greeting_reply(text: str | None) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def _voice_strip_reply_greeting_prefix(reply_text: str | None, *, name: str | None = None) -> str:
|
||||
text = str(reply_text or "").strip()
|
||||
if not text:
|
||||
return text
|
||||
greeting_pattern = (
|
||||
r"^\s*(?:здравствуйте|здравствуй|привет(?:ствую)?|"
|
||||
r"добрый\s+(?:день|вечер|утро)|сәлеметсіз\s+бе|сәлем)\b[\s,!.:-]*"
|
||||
)
|
||||
stripped = re.sub(greeting_pattern, "", text, count=1, flags=re.IGNORECASE).strip()
|
||||
if name and stripped != text:
|
||||
short_name = _voice_short_name(name)
|
||||
if short_name:
|
||||
stripped = re.sub(
|
||||
rf"^\s*{re.escape(short_name)}\b[\s,!.:-]*",
|
||||
"",
|
||||
stripped,
|
||||
count=1,
|
||||
flags=re.IGNORECASE,
|
||||
).strip()
|
||||
return stripped or text
|
||||
|
||||
|
||||
def _voice_contains_false_lookup_promise(text: str | None) -> bool:
|
||||
normalized = _voice_text_key(text)
|
||||
if not normalized:
|
||||
@@ -1388,15 +1414,16 @@ def _voice_postprocess_reply_text(
|
||||
prior_caller_texts = _voice_caller_context_before_current(caller_texts, transcript_text)
|
||||
active_topic_texts = _voice_service_context_texts(prior_caller_texts or caller_texts)
|
||||
active_topic_prompt = _voice_topic_prompt(language, active_topic_texts) if active_topic_texts else None
|
||||
has_assistant_context = any(segment.speaker == "assistant" for segment in transcript_window)
|
||||
if _voice_is_hearing_check_caller_text(transcript_text):
|
||||
return _voice_hearing_check_reply(language, prior_caller_texts or caller_texts)
|
||||
if _voice_contains_false_lookup_promise(normalized_reply) and not kb_results:
|
||||
return active_topic_prompt or _voice_topic_prompt(language, caller_texts) or _voice_generic_prompt(language)
|
||||
if _voice_is_midcall_greeting_reply(normalized_reply) and any(
|
||||
segment.speaker == "assistant" for segment in transcript_window
|
||||
):
|
||||
if _voice_is_midcall_greeting_reply(normalized_reply) and has_assistant_context:
|
||||
context_texts = prior_caller_texts if _voice_is_low_signal_caller_text(transcript_text) else caller_texts
|
||||
return _voice_topic_prompt(language, context_texts) or _voice_generic_prompt(language)
|
||||
if has_assistant_context or _voice_has_service_topic(transcript_text):
|
||||
normalized_reply = _voice_strip_reply_greeting_prefix(normalized_reply)
|
||||
if (
|
||||
active_topic_prompt
|
||||
and not _voice_has_service_topic(transcript_text)
|
||||
|
||||
Reference in New Issue
Block a user