fix: TTS 服务去除重复默认值,新增 httpClientTimeout 参数
- 去除 model/voice/endpoint 的 fallback 默认值 - HTTP Client 超时从 config 传入
This commit is contained in:
@@ -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},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user