fix: ChatTTS检测改用同步requests,解决async问题
This commit is contained in:
Binary file not shown.
BIN
logs/server.log
BIN
logs/server.log
Binary file not shown.
@@ -2,4 +2,5 @@ fastapi==0.110.0
|
|||||||
uvicorn==0.27.1
|
uvicorn==0.27.1
|
||||||
python-multipart==0.0.9
|
python-multipart==0.0.9
|
||||||
aiohttp==3.9.3
|
aiohttp==3.9.3
|
||||||
edge-tts==6.1.9
|
edge-tts==6.1.9
|
||||||
|
requests==2.31.0
|
||||||
@@ -145,24 +145,13 @@ class ChatTTSProvider(TTSProvider):
|
|||||||
"""检查 ChatTTS 是否可用"""
|
"""检查 ChatTTS 是否可用"""
|
||||||
if self._available is None:
|
if self._available is None:
|
||||||
try:
|
try:
|
||||||
import aiohttp
|
import requests
|
||||||
import asyncio
|
resp = requests.get(f"{self.CHATTTS_URL}/health", timeout=5)
|
||||||
|
if resp.status_code == 200:
|
||||||
async def check():
|
data = resp.json()
|
||||||
try:
|
self._available = data.get("status") == "ok"
|
||||||
async with aiohttp.ClientSession() as session:
|
else:
|
||||||
async with session.get(
|
self._available = False
|
||||||
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())
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"ChatTTS check failed: {e}")
|
logger.warning(f"ChatTTS check failed: {e}")
|
||||||
self._available = False
|
self._available = False
|
||||||
|
|||||||
Reference in New Issue
Block a user