refactor: replace Kokoro-82M with suno/bark for TTS, update HF cache path, and add model warmup on startup.
This commit is contained in:
+10
-9
@@ -283,8 +283,9 @@ def _check_model_cached(model_id: str) -> bool:
|
||||
return True # 非离线模式,不检查缓存
|
||||
|
||||
try:
|
||||
from transformers import file_utils
|
||||
cache_dir = file_utils.default_cache_path
|
||||
import os
|
||||
from huggingface_hub.constants import HF_HUB_CACHE
|
||||
cache_dir = HF_HUB_CACHE
|
||||
|
||||
# 简单的缓存检查:查找模型目录
|
||||
model_name = model_id.replace("/", "--")
|
||||
@@ -350,14 +351,14 @@ async def _load_tts_pipeline_with_retry(max_retries: int = 2) -> bool:
|
||||
device_to_use = _device_arg()
|
||||
torch_dtype = _get_torch_dtype()
|
||||
|
||||
model_id = "hexgrad/Kokoro-82M"
|
||||
model_id = "suno/bark"
|
||||
|
||||
# 离线模式检查
|
||||
if TTS_ASR_OFFLINE_MODE and not _check_model_cached(model_id):
|
||||
logger.error("[TTS] 离线模式下模型 %s 未缓存", model_id)
|
||||
return False
|
||||
|
||||
logger.info("[TTS] 加载 Kokoro-82M 模型 (尝试 %d/%d, 设备: %s)...",
|
||||
logger.info("[TTS] 加载 suno/bark 模型 (尝试 %d/%d, 设备: %s)...",
|
||||
attempt + 1, max_retries, device_to_use)
|
||||
|
||||
_tts_pipeline = await asyncio.to_thread(
|
||||
@@ -370,7 +371,7 @@ async def _load_tts_pipeline_with_retry(max_retries: int = 2) -> bool:
|
||||
)
|
||||
)
|
||||
|
||||
logger.info("[TTS] Kokoro-82M 模型加载完成")
|
||||
logger.info("[TTS] suno/bark 模型加载完成")
|
||||
return True
|
||||
|
||||
except RuntimeError as e:
|
||||
@@ -552,7 +553,7 @@ async def _warmup_tts() -> bool:
|
||||
|
||||
def warmup_inference():
|
||||
try:
|
||||
result = tts(TTS_WARMUP_TEXT, voice="af_bella")
|
||||
result = tts(TTS_WARMUP_TEXT)
|
||||
if isinstance(result, dict):
|
||||
audio = result.get("audio")
|
||||
if hasattr(audio, "cpu"):
|
||||
@@ -759,7 +760,7 @@ async def _tts_sync_with_retry(text: str, voice: str = "af_bella", rate: float =
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
def inference():
|
||||
result = tts(text, voice=voice)
|
||||
result = tts(text)
|
||||
audio = None
|
||||
sr = sample_rate
|
||||
|
||||
@@ -770,7 +771,7 @@ async def _tts_sync_with_retry(text: str, voice: str = "af_bella", rate: float =
|
||||
audio = result[0]
|
||||
|
||||
if audio is None:
|
||||
raise RuntimeError("Kokoro 未返回音频数据")
|
||||
raise RuntimeError("TTS模型未返回音频数据")
|
||||
|
||||
if hasattr(audio, "cpu"):
|
||||
audio = audio.cpu().numpy()
|
||||
@@ -1017,7 +1018,7 @@ async def get_config(api_key: str = Security(get_api_key)):
|
||||
"cuda_memory_limit_mb": caps.cuda_memory_limit_mb,
|
||||
},
|
||||
"model": {
|
||||
"tts": "hexgrad/Kokoro-82M",
|
||||
"tts": "suno/bark",
|
||||
"asr_current_size": _asr_model_size,
|
||||
"asr_recommended_size": caps.recommended_model_size,
|
||||
"available_sizes": list(WHISPER_MODEL_SIZES.keys()),
|
||||
|
||||
Reference in New Issue
Block a user