feat: 添加豆包 ASR 热词功能支持
- 在 config.yaml 中添加 hotwords 配置项,支持本地管理热词列表
- 实现热词解析、格式化和表名生成工具(internal/asr/hotwords.go)
- 在 ASR 连接建立时自动将热词发送给豆包(boosting_table_name 参数)
- 支持热词权重配置(1-10,默认 4),格式:"词|权重" 或 "词"
- 支持配置热重载,修改热词后新连接自动生效
- 为未来动态热词功能预留扩展接口
热词格式示例:
hotwords:
- 张三|8
- VoicePaste|10
- 人工智能|6
This commit is contained in:
@@ -22,7 +22,8 @@ const (
|
||||
type Config struct {
|
||||
AppID string
|
||||
AccessToken string
|
||||
ResourceID string
|
||||
ResourceID string
|
||||
Hotwords []string // 热词列表,格式 "词|权重" 或 "词"
|
||||
}
|
||||
|
||||
// Client manages a single ASR session with Doubao.
|
||||
@@ -57,6 +58,21 @@ func Dial(cfg Config, resultCh chan<- wsMsg.ServerMsg) (*Client, error) {
|
||||
closeCh: make(chan struct{}),
|
||||
log: slog.With("conn_id", connID),
|
||||
}
|
||||
// Parse hotwords configuration
|
||||
var boostingTableName string
|
||||
if len(cfg.Hotwords) > 0 {
|
||||
entries, err := ParseHotwords(cfg.Hotwords)
|
||||
if err != nil {
|
||||
slog.Warn("invalid hotwords config, skipping", "err", err)
|
||||
} else {
|
||||
boostingTableName = GenerateTableName(entries)
|
||||
tableContent := FormatHotwordsTable(entries)
|
||||
slog.Info("hotwords enabled",
|
||||
"count", len(entries),
|
||||
"table_name", boostingTableName,
|
||||
"content", tableContent)
|
||||
}
|
||||
}
|
||||
// Send FullClientRequest
|
||||
req := &FullClientRequest{
|
||||
User: UserMeta{UID: connID},
|
||||
@@ -68,14 +84,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,
|
||||
ModelName: "seedasr-2.0",
|
||||
EnableITN: true,
|
||||
EnablePUNC: true,
|
||||
EnableDDC: true,
|
||||
ShowUtterances: true,
|
||||
ResultType: "full",
|
||||
EnableNonstream: true,
|
||||
EndWindowSize: 800,
|
||||
BoostingTableName: boostingTableName,
|
||||
},
|
||||
}
|
||||
data, err := EncodeFullClientRequest(req)
|
||||
|
||||
Reference in New Issue
Block a user