- 在 config.yaml 中添加 hotwords 配置项,支持本地管理热词列表
- 实现热词解析、格式化和表名生成工具(internal/asr/hotwords.go)
- 在 ASR 连接建立时自动将热词发送给豆包(boosting_table_name 参数)
- 支持热词权重配置(1-10,默认 4),格式:"词|权重" 或 "词"
- 支持配置热重载,修改热词后新连接自动生效
- 为未来动态热词功能预留扩展接口
热词格式示例:
hotwords:
- 张三|8
- VoicePaste|10
- 人工智能|6
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package ws
|
|
|
|
import "encoding/json"
|
|
|
|
// ── Client → Server messages ──
|
|
|
|
// MsgType enumerates known message types.
|
|
type MsgType string
|
|
|
|
const (
|
|
MsgStart MsgType = "start" // Begin recording session
|
|
MsgStop MsgType = "stop" // End recording session
|
|
MsgPaste MsgType = "paste" // Re-paste a history item
|
|
)
|
|
|
|
// ClientMsg is a JSON control message from the phone.
|
|
type ClientMsg struct {
|
|
Type MsgType `json:"type"`
|
|
Text string `json:"text,omitempty"` // Only for "paste"
|
|
// Future extension: dynamic hotwords (Phase 2)
|
|
// Hotwords []string `json:"hotwords,omitempty"`
|
|
}
|
|
|
|
// ── Server → Client messages ──
|
|
|
|
const (
|
|
MsgPartial MsgType = "partial" // Interim ASR result
|
|
MsgFinal MsgType = "final" // Final ASR result
|
|
MsgPasted MsgType = "pasted" // Paste confirmed
|
|
MsgError MsgType = "error" // Error notification
|
|
)
|
|
|
|
// ServerMsg is a JSON message sent to the phone.
|
|
type ServerMsg struct {
|
|
Type MsgType `json:"type"`
|
|
Text string `json:"text,omitempty"`
|
|
Message string `json:"message,omitempty"` // For errors
|
|
}
|
|
|
|
func (m ServerMsg) Bytes() []byte {
|
|
b, _ := json.Marshal(m)
|
|
return b
|
|
}
|