fix: STT 服务去除重复默认值,新增 timeout 参数

- Deepgram/MiMo STT 超时从 config 传入
- 去除 model/endpoint 的 fallback 默认值,由 config 层保证
This commit is contained in:
hhs
2026-06-14 11:55:18 +08:00
parent f1ce28966c
commit 03b3566822
2 changed files with 17 additions and 15 deletions

View File

@@ -18,21 +18,22 @@ type DeepgramService struct {
apiKey string
model string
endpoint string
timeout time.Duration
logger *zap.SugaredLogger
}
// NewDeepgramService 创建 Deepgram STT 服务。
func NewDeepgramService(apiKey, model, endpoint string, logger *zap.SugaredLogger) *DeepgramService {
if model == "" {
model = "nova-2"
}
if endpoint == "" {
endpoint = "wss://api.deepgram.com/v1/listen"
// model、endpoint 由 config 层保证非空timeoutSec 为 0 时默认 5 秒。
func NewDeepgramService(apiKey, model, endpoint string, timeoutSec int, logger *zap.SugaredLogger) *DeepgramService {
timeout := time.Duration(timeoutSec) * time.Second
if timeout <= 0 {
timeout = 5 * time.Second
}
return &DeepgramService{
apiKey: apiKey,
model: model,
endpoint: endpoint,
timeout: timeout,
logger: logger,
}
}
@@ -57,8 +58,8 @@ func (d *DeepgramService) Recognize(ctx context.Context, audio []byte, opts Opti
// 构建 WebSocket URL附带查询参数
wsURL := d.buildURL(opts)
// 5 秒总超时
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
// 总超时
ctx, cancel := context.WithTimeout(ctx, d.timeout)
defer cancel()
// 建立 WebSocket 连接