feat: 添加 TTS 语音名称常量并更新 TTS 服务逻辑

- 在 constants.py 中新增 TTS_VOICE_NAMES 列表,包含多个语音名称。
- 更新 tts_service.py 中的语音配置逻辑,确保使用请求中的语音名称(如果有效),否则回退到默认配置。
This commit is contained in:
snaily
2025-07-10 01:03:20 +08:00
parent eed62caa78
commit f6d64dd850
2 changed files with 14 additions and 2 deletions

View File

@@ -76,4 +76,15 @@ DEFAULT_SAFETY_SETTINGS = [
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "OFF"},
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "OFF"},
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "BLOCK_NONE"},
]
]
TTS_VOICE_NAMES = [
"Zephyr", "Puck", "Charon", "Kore",
"Fenrir", "Leda", "Orus", "Aoede",
"Callirhoe", "Autonoe", "Enceladus", "Iapetus",
"Umbriel", "Algieba", "Despina", "Erinome",
"Algenib", "Rasalgethi", "Laomedeia", "Achernar",
"Alnilam", "Schedar", "Gacrux", "Pulcherrima",
"Achird", "Zubenelgenubi", "Vindemiatrix", "Sadachbia",
"Sadaltager", "Sulafat"
]

View File

@@ -8,6 +8,7 @@ from typing import Optional
from google import genai
from app.config.config import settings
from app.core.constants import TTS_VOICE_NAMES
from app.database.services import add_error_log, add_request_log
from app.domain.openai_models import TTSRequest
from app.log.logger import get_openai_logger
@@ -47,7 +48,7 @@ class TTSService:
"speech_config": {
"voice_config": {
"prebuilt_voice_config": {
"voice_name": settings.TTS_VOICE_NAME
"voice_name": request.voice if request.voice in TTS_VOICE_NAMES else settings.TTS_VOICE_NAME
}
}
},