chore: 优化日志,静默 httpx 内部日志,精简输出格式
This commit is contained in:
16
app/main.py
16
app/main.py
@@ -25,10 +25,12 @@ import config
|
|||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format="%(asctime)s [%(levelname)s] %(message)s",
|
format="%(asctime)s %(message)s",
|
||||||
datefmt="%Y-%m-%d %H:%M:%S",
|
datefmt="%H:%M:%S",
|
||||||
)
|
)
|
||||||
logger = logging.getLogger("tts-proxy")
|
logger = logging.getLogger("tts")
|
||||||
|
# 静默 httpx 内部日志
|
||||||
|
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||||
|
|
||||||
# ── Text Segmentation ─────────────────────────────────────────────────────
|
# ── Text Segmentation ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -152,7 +154,7 @@ async def call_mimo_tts(text: str, style: str = "", voice: str = "") -> bytes:
|
|||||||
elapsed = round(time.time() - t0, 2)
|
elapsed = round(time.time() - t0, 2)
|
||||||
|
|
||||||
if resp.status_code != 200:
|
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}")
|
err = HTTPException(502, f"MiMo TTS API 错误: HTTP {resp.status_code}")
|
||||||
if resp.status_code >= 500 and attempt < MAX_TTS_RETRIES:
|
if resp.status_code >= 500 and attempt < MAX_TTS_RETRIES:
|
||||||
last_exc = err
|
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"]
|
audio_b64 = data["choices"][0]["message"]["audio"]["data"]
|
||||||
wav_bytes = base64.b64decode(audio_b64)
|
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
|
return wav_bytes
|
||||||
|
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
elapsed = round(time.time() - t0, 2)
|
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}")
|
last_exc = HTTPException(502, f"MiMo TTS 异常: {e}")
|
||||||
if attempt < MAX_TTS_RETRIES:
|
if attempt < MAX_TTS_RETRIES:
|
||||||
await asyncio.sleep(1.5 * attempt)
|
await asyncio.sleep(1.5 * attempt)
|
||||||
@@ -205,7 +207,7 @@ async def generate_mp3(text: str, style: str = "", voice: str = "") -> bytes:
|
|||||||
return mp3_bytes
|
return mp3_bytes
|
||||||
|
|
||||||
# 多段
|
# 多段
|
||||||
logger.info(f"文本 {len(text)} 字, 分 {len(chunks)} 段生成")
|
logger.info(f"SPLIT {len(text)}字 → {len(chunks)}段")
|
||||||
mp3_paths = []
|
mp3_paths = []
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
wav_bytes = await call_mimo_tts(chunk, style, voice)
|
wav_bytes = await call_mimo_tts(chunk, style, voice)
|
||||||
|
|||||||
Reference in New Issue
Block a user