diff --git a/backend/internal/ai/tts/mimo.go b/backend/internal/ai/tts/mimo.go index 208d301..5e80cbb 100644 --- a/backend/internal/ai/tts/mimo.go +++ b/backend/internal/ai/tts/mimo.go @@ -27,20 +27,16 @@ type MiMoService struct { } // NewMiMoService 创建 MiMo TTS 服务。 -func NewMiMoService(apiKey, model, voice, endpoint string, timeoutSec int, logger *zap.SugaredLogger) *MiMoService { - if model == "" { - model = "mimo-v2.5-tts" - } - if voice == "" { - voice = "冰糖" - } - if endpoint == "" { - endpoint = "https://api.xiaomimimo.com/v1" - } +// model、voice、endpoint 由 config 层保证非空。 +func NewMiMoService(apiKey, model, voice, endpoint string, timeoutSec, httpClientTimeoutSec int, logger *zap.SugaredLogger) *MiMoService { timeout := time.Duration(timeoutSec) * time.Second if timeout <= 0 { timeout = 5 * time.Second } + httpClientTimeout := time.Duration(httpClientTimeoutSec) * time.Second + if httpClientTimeout <= 0 { + httpClientTimeout = 30 * time.Second + } return &MiMoService{ apiKey: apiKey, model: model, @@ -48,7 +44,7 @@ func NewMiMoService(apiKey, model, voice, endpoint string, timeoutSec int, logge endpoint: endpoint, timeout: timeout, logger: logger, - client: &http.Client{Timeout: 30 * time.Second}, + client: &http.Client{Timeout: httpClientTimeout}, } } diff --git a/backend/internal/ai/tts/openai.go b/backend/internal/ai/tts/openai.go index 6e0123e..8741ce6 100644 --- a/backend/internal/ai/tts/openai.go +++ b/backend/internal/ai/tts/openai.go @@ -25,23 +25,19 @@ type OpenAIService struct { } // NewOpenAIService 创建 OpenAI TTS 服务。 -func NewOpenAIService(apiKey, model, voice, endpoint string, speed float64, timeoutSec int, logger *zap.SugaredLogger) *OpenAIService { - if model == "" { - model = "tts-1" - } - if voice == "" { - voice = "alloy" - } +// model、voice、endpoint 由 config 层保证非空。 +func NewOpenAIService(apiKey, model, voice, endpoint string, speed float64, timeoutSec, httpClientTimeoutSec int, logger *zap.SugaredLogger) *OpenAIService { if speed <= 0 { speed = 1.0 } - if endpoint == "" { - endpoint = "https://api.openai.com/v1" - } timeout := time.Duration(timeoutSec) * time.Second if timeout <= 0 { timeout = 5 * time.Second } + httpClientTimeout := time.Duration(httpClientTimeoutSec) * time.Second + if httpClientTimeout <= 0 { + httpClientTimeout = 30 * time.Second + } return &OpenAIService{ apiKey: apiKey, model: model, @@ -50,7 +46,7 @@ func NewOpenAIService(apiKey, model, voice, endpoint string, speed float64, time endpoint: endpoint, timeout: timeout, logger: logger, - client: &http.Client{Timeout: 30 * time.Second}, + client: &http.Client{Timeout: httpClientTimeout}, } }