From fb753ce1b11d5fa1ec0e7b749c0f38cfa8ccf4ed Mon Sep 17 00:00:00 2001 From: sunruiling Date: Fri, 27 Mar 2026 15:24:25 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?=EF=BC=8C=E9=9D=99=E9=BB=98=20httpx=20=E5=86=85=E9=83=A8?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=8C=E7=B2=BE=E7=AE=80=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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)