feat: 实现本地热词管理,移除平台绑定
- 使用 corpus.context 参数直接传递热词列表(豆包文档支持)
- 移除 boosting_table_id 配置,避免绑定火山引擎控制台
- 实现 BuildHotwordsContext 函数,将本地热词转换为 JSON 格式
- 热词配置完全本地化,便于迁移到其他 ASR 平台
配置示例:
hotwords:
- 张三
- 李四
- VoicePaste
程序自动转换为豆包 API 要求的格式:
{"hotwords":[{"word":"张三"},{"word":"李四"},{"word":"VoicePaste"}]}
This commit is contained in:
43
internal/asr/hotwords.go
Normal file
43
internal/asr/hotwords.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package asr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// HotwordEntry represents a single hotword for context JSON.
|
||||
type HotwordEntry struct {
|
||||
Word string `json:"word"`
|
||||
}
|
||||
|
||||
// HotwordsContext represents the context JSON structure for hotwords.
|
||||
type HotwordsContext struct {
|
||||
Hotwords []HotwordEntry `json:"hotwords"`
|
||||
}
|
||||
|
||||
// BuildHotwordsContext converts a list of hotword strings to context JSON string.
|
||||
// Returns empty string if hotwords list is empty.
|
||||
func BuildHotwordsContext(hotwords []string) (string, error) {
|
||||
if len(hotwords) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
entries := make([]HotwordEntry, 0, len(hotwords))
|
||||
for _, word := range hotwords {
|
||||
if word != "" {
|
||||
entries = append(entries, HotwordEntry{Word: word})
|
||||
}
|
||||
}
|
||||
|
||||
if len(entries) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
ctx := HotwordsContext{Hotwords: entries}
|
||||
data, err := json.Marshal(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("marshal hotwords context: %w", err)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
Reference in New Issue
Block a user