feat(i18n): persist language preference and thread through chat, memoir, TTS

- Add users.language_preference (Alembic 0018, default zh); capture at signup/SMS
  only; expose on auth and profile APIs
- Lite English prompts for chat and memoir; localized stage labels and agent
  names (Life Echo / 岁月知己)
- Tencent TTS: language-aware synthesis, ModelType=1 for 501004, English chunking
- WebSocket pipeline: emit all AGENT_RESPONSE segments when TTS cancels; INFO logs
  for tts_this_turn and TTS decisions; on-demand TTS logging
- Expo: device language on auth, i18n tiers/agent name, [SPLIT] streaming UX fixes
- Tests for migration, prompts, pipeline, router tts_this_turn, reply segments

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin
2026-05-11 16:16:49 +08:00
parent 5ce29aad64
commit ccdc4e4277
64 changed files with 3233 additions and 208 deletions

View File

@@ -41,13 +41,16 @@ def _polish_story_title(
llm,
*,
chapter_category: str,
language: str = "zh",
) -> bool:
"""Re-generate title if current title is a placeholder. Returns True if updated."""
from app.features.memoir.story_pipeline_sync import _placeholder_title
current = (story.title or "").strip()
placeholder = _placeholder_title(chapter_category)
if current and current != placeholder:
placeholder_zh = _placeholder_title(chapter_category, language="zh")
placeholder_en = _placeholder_title(chapter_category, language="en")
placeholder = _placeholder_title(chapter_category, language=language)
if current and current not in (placeholder_zh, placeholder_en):
return False
body = (story.canonical_markdown or "").strip()
@@ -63,9 +66,10 @@ def _polish_story_title(
user_profile="",
birth_year=None,
llm=llm,
language=language,
)
new_title = (new_title or "").strip()
if not new_title or new_title == placeholder:
if not new_title or new_title in (placeholder_zh, placeholder_en, placeholder):
return False
story.title = new_title
@@ -138,6 +142,16 @@ def memoir_quality_pass(
chapters_dirtied: set[str] = set()
with get_sync_db() as db:
from app.features.user.models import User
user_obj = db.get(User, user_id)
user_language = (
"en"
if user_obj is not None
and str(getattr(user_obj, "language_preference", "zh") or "zh").lower()
== "en"
else "zh"
)
for sid in story_ids:
story = db.get(Story, sid)
if not story or story.user_id != user_id:
@@ -145,7 +159,11 @@ def memoir_quality_pass(
chapter_category = story.stage or "summary"
if _polish_story_title(
db, story, llm, chapter_category=chapter_category
db,
story,
llm,
chapter_category=chapter_category,
language=user_language,
):
titles_polished += 1
stmt = select(Chapter.id).where(