diff --git a/app/main.py b/app/main.py index 5080544..a746dad 100644 --- a/app/main.py +++ b/app/main.py @@ -25,10 +25,12 @@ import config logging.basicConfig( level=logging.INFO, - format="%(asctime)s [%(levelname)s] %(message)s", - datefmt="%Y-%m-%d %H:%M:%S", + format="%(asctime)s %(message)s", + datefmt="%H:%M:%S", ) -logger = logging.getLogger("tts-proxy") +logger = logging.getLogger("tts") +# 静默 httpx 内部日志 +logging.getLogger("httpx").setLevel(logging.WARNING) # ── Text Segmentation ───────────────────────────────────────────────────── @@ -152,7 +154,7 @@ async def call_mimo_tts(text: str, style: str = "", voice: str = "") -> bytes: elapsed = round(time.time() - t0, 2) if resp.status_code != 200: - logger.error(f"MiMo TTS HTTP {resp.status_code}, {elapsed}s, {resp.text[:200]}") + logger.error(f"TTS FAIL http={resp.status_code} {elapsed}s") err = HTTPException(502, f"MiMo TTS API 错误: HTTP {resp.status_code}") if resp.status_code >= 500 and attempt < MAX_TTS_RETRIES: last_exc = err @@ -166,14 +168,14 @@ async def call_mimo_tts(text: str, style: str = "", voice: str = "") -> bytes: audio_b64 = data["choices"][0]["message"]["audio"]["data"] wav_bytes = base64.b64decode(audio_b64) - logger.info(f"MiMo TTS OK: {len(wav_bytes)} bytes, {elapsed}s (attempt {attempt})") + logger.info(f"TTS OK {len(wav_bytes)//1024}KB {elapsed}s") return wav_bytes except HTTPException: raise except Exception as e: elapsed = round(time.time() - t0, 2) - logger.error(f"MiMo TTS 异常: {e}, {elapsed}s, attempt {attempt}") + logger.error(f"TTS ERR {e} {elapsed}s") last_exc = HTTPException(502, f"MiMo TTS 异常: {e}") if attempt < MAX_TTS_RETRIES: await asyncio.sleep(1.5 * attempt) @@ -205,7 +207,7 @@ async def generate_mp3(text: str, style: str = "", voice: str = "") -> bytes: return mp3_bytes # 多段 - logger.info(f"文本 {len(text)} 字, 分 {len(chunks)} 段生成") + logger.info(f"SPLIT {len(text)}字 → {len(chunks)}段") mp3_paths = [] for chunk in chunks: wav_bytes = await call_mimo_tts(chunk, style, voice)