fix: ChatTTS检测改用同步requests,解决async问题

This commit is contained in:
2026-04-22 18:16:17 +08:00
parent 2208a1a7d4
commit dbafd4fb73
4 changed files with 9 additions and 19 deletions

Binary file not shown.

View File

@@ -2,4 +2,5 @@ fastapi==0.110.0
uvicorn==0.27.1
python-multipart==0.0.9
aiohttp==3.9.3
edge-tts==6.1.9
edge-tts==6.1.9
requests==2.31.0

View File

@@ -145,24 +145,13 @@ class ChatTTSProvider(TTSProvider):
"""检查 ChatTTS 是否可用"""
if self._available is None:
try:
import aiohttp
import asyncio
async def check():
try:
async with aiohttp.ClientSession() as session:
async with session.get(
f"{self.CHATTTS_URL}/health",
timeout=aiohttp.ClientTimeout(total=5)
) as resp:
if resp.status == 200:
data = await resp.json()
return data.get("status") == "ok"
except:
pass
return False
self._available = asyncio.get_event_loop().run_until_complete(check())
import requests
resp = requests.get(f"{self.CHATTTS_URL}/health", timeout=5)
if resp.status_code == 200:
data = resp.json()
self._available = data.get("status") == "ok"
else:
self._available = False
except Exception as e:
logger.warning(f"ChatTTS check failed: {e}")
self._available = False