- 在 config.yaml 中添加 hotwords 配置项,支持本地管理热词列表
- 实现热词解析、格式化和表名生成工具(internal/asr/hotwords.go)
- 在 ASR 连接建立时自动将热词发送给豆包(boosting_table_name 参数)
- 支持热词权重配置(1-10,默认 4),格式:"词|权重" 或 "词"
- 支持配置热重载,修改热词后新连接自动生效
- 为未来动态热词功能预留扩展接口
热词格式示例:
hotwords:
- 张三|8
- VoicePaste|10
- 人工智能|6
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"sync/atomic"
|
|
)
|
|
|
|
// DoubaoConfig holds 火山引擎豆包 ASR credentials.
|
|
type DoubaoConfig struct {
|
|
AppID string `yaml:"app_id"`
|
|
AccessToken string `yaml:"access_token"`
|
|
ResourceID string `yaml:"resource_id"`
|
|
Hotwords []string `yaml:"hotwords"` // 热词列表,格式 "词|权重" 或 "词"
|
|
}
|
|
|
|
// SecurityConfig holds authentication settings.
|
|
type SecurityConfig struct {
|
|
Token string `yaml:"token"`
|
|
}
|
|
|
|
// ServerConfig holds server settings.
|
|
type ServerConfig struct {
|
|
Port int `yaml:"port"`
|
|
TLSAuto bool `yaml:"tls_auto"`
|
|
}
|
|
|
|
// Config is the top-level configuration.
|
|
type Config struct {
|
|
Doubao DoubaoConfig `yaml:"doubao"`
|
|
Server ServerConfig `yaml:"server"`
|
|
Security SecurityConfig `yaml:"security"`
|
|
}
|
|
|
|
// defaults returns a Config with default values.
|
|
func defaults() Config {
|
|
return Config{
|
|
Doubao: DoubaoConfig{
|
|
ResourceID: "volc.seedasr.sauc.duration",
|
|
},
|
|
Server: ServerConfig{
|
|
Port: 8443,
|
|
TLSAuto: true,
|
|
},
|
|
}
|
|
}
|
|
|
|
// global holds the current config atomically for concurrent reads.
|
|
var global atomic.Value
|
|
|
|
// Get returns the current config snapshot. Safe for concurrent use.
|
|
func Get() Config {
|
|
if v := global.Load(); v != nil {
|
|
return v.(Config)
|
|
}
|
|
return defaults()
|
|
}
|
|
|
|
// store updates the global config.
|
|
func store(cfg Config) {
|
|
global.Store(cfg)
|
|
}
|