feat: 实现本地热词管理,移除平台绑定
- 使用 corpus.context 参数直接传递热词列表(豆包文档支持)
- 移除 boosting_table_id 配置,避免绑定火山引擎控制台
- 实现 BuildHotwordsContext 函数,将本地热词转换为 JSON 格式
- 热词配置完全本地化,便于迁移到其他 ASR 平台
配置示例:
hotwords:
- 张三
- 李四
- VoicePaste
程序自动转换为豆包 API 要求的格式:
{"hotwords":[{"word":"张三"},{"word":"李四"},{"word":"VoicePaste"}]}
This commit is contained in:
@@ -20,10 +20,10 @@ const (
|
||||
|
||||
// Config holds Doubao ASR connection parameters.
|
||||
type Config struct {
|
||||
AppID string
|
||||
AccessToken string
|
||||
ResourceID string
|
||||
BoostingTableID string // 热词表 ID(从控制台创建)
|
||||
AppID string
|
||||
AccessToken string
|
||||
ResourceID string
|
||||
Hotwords []string // 本地热词列表
|
||||
}
|
||||
|
||||
// Client manages a single ASR session with Doubao.
|
||||
@@ -58,6 +58,17 @@ func Dial(cfg Config, resultCh chan<- wsMsg.ServerMsg) (*Client, error) {
|
||||
closeCh: make(chan struct{}),
|
||||
log: slog.With("conn_id", connID),
|
||||
}
|
||||
// Build corpus configuration
|
||||
var corpus *Corpus
|
||||
if len(cfg.Hotwords) > 0 {
|
||||
contextJSON, err := BuildHotwordsContext(cfg.Hotwords)
|
||||
if err != nil {
|
||||
slog.Warn("failed to build hotwords context, skipping", "err", err)
|
||||
} else {
|
||||
corpus = &Corpus{Context: contextJSON}
|
||||
slog.Info("hotwords enabled", "count", len(cfg.Hotwords))
|
||||
}
|
||||
}
|
||||
// Send FullClientRequest
|
||||
req := &FullClientRequest{
|
||||
User: UserMeta{UID: connID},
|
||||
@@ -69,15 +80,15 @@ func Dial(cfg Config, resultCh chan<- wsMsg.ServerMsg) (*Client, error) {
|
||||
Channel: 1,
|
||||
},
|
||||
Request: RequestMeta{
|
||||
ModelName: "seedasr-2.0",
|
||||
EnableITN: true,
|
||||
EnablePUNC: true,
|
||||
EnableDDC: true,
|
||||
ShowUtterances: true,
|
||||
ResultType: "full",
|
||||
EnableNonstream: true,
|
||||
EndWindowSize: 800,
|
||||
BoostingTableID: cfg.BoostingTableID,
|
||||
ModelName: "seedasr-2.0",
|
||||
EnableITN: true,
|
||||
EnablePUNC: true,
|
||||
EnableDDC: true,
|
||||
ShowUtterances: true,
|
||||
ResultType: "full",
|
||||
EnableNonstream: true,
|
||||
EndWindowSize: 800,
|
||||
Corpus: corpus,
|
||||
},
|
||||
}
|
||||
data, err := EncodeFullClientRequest(req)
|
||||
|
||||
Reference in New Issue
Block a user