Files
sundynix-agentix/sundynix-gateway/cmd/voiceconfig/main.go
T
Blizzard bb9c73a9b7 fix(voice): 修正火山 V3 流式端点鉴权头(真火山联调验通协议格式)
联调发现 Authorization: Bearer 不被 openspeech V3 二进制流端点接受。改用官方规范头:
- X-Api-App-Key: 固定常量 PlgvMymc7f3tQnJ6(所有客户端同值,缺它 400 "app key not found")
- X-Api-Access-Key: 新版 API Key(账号鉴权)
- X-Api-App-ID: 账号 App ID(解析资源授权,缺它 401 "grant not found")
- X-Api-Resource-Id / X-Api-Connect-Id

改动:Config 加 AppID 字段;frame.go setVolcAuthHeaders 统一挂头 + handshakeDetail
榨取握手失败的 HTTP 状态/logid/body(联调可诊断);asr/tts 共用;voicecheck 加握手探针
分别验 ASR/TTS 端点;voiceconfig/voicecheck 读 VOLC_APP_ID。

现状:协议格式已被真火山接受(过了 400 格式错,进到账号/资源授权查询)。剩 App ID +
资源开通确认(账号侧,联调补)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 09:53:26 +08:00

68 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// voiceconfig 把火山语音配置写入数据库(等价于 admin「语音设置」页保存一次)。
// 供本地联调 / 无头环境快速配好语音,免开 admin 控制台。API Key 只走环境变量、加密入库,
// 绝不进代码/git;写库前复用 gateway 同一套 AES 加密(voice.Config.EncryptedForStore)。
//
// 用法:
//
// export POSTGRES_DSN="postgres://sundynix:sundynix@localhost:5432/sundynix?sslmode=disable"
// export VOLC_API_KEY=<你的APIKey>
// export VOLC_ASR_RESOURCE_ID=volc.seedasr.sauc.duration
// export VOLC_TTS_RESOURCE_ID=seed-tts-2.0
// export VOLC_TTS_VOICE=zh_male_m191_uranus_bigtts
// # SUNDYNIX_SECRET_KEY 须与 gateway 一致(都不设=同用开发默认)
// go run ./cmd/voiceconfig
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/sundynix/sundynix-gateway/internal/store"
"github.com/sundynix/sundynix-gateway/internal/voice"
)
const settingVoice = "voice_config" // 与 handler.SettingVoice 对齐
func main() {
dsn := os.Getenv("POSTGRES_DSN")
if dsn == "" {
fatal("缺 POSTGRES_DSN")
}
cfg := voice.Config{
APIKey: os.Getenv("VOLC_API_KEY"),
AppID: os.Getenv("VOLC_APP_ID"),
ASRResourceID: os.Getenv("VOLC_ASR_RESOURCE_ID"),
TTSResourceID: os.Getenv("VOLC_TTS_RESOURCE_ID"),
TTSVoiceType: os.Getenv("VOLC_TTS_VOICE"),
}
if cfg.APIKey == "" {
fatal("缺 VOLC_API_KEY")
}
db := store.OpenPostgres(dsn)
if !db.Enabled() {
fatal("连不上数据库(检查 POSTGRES_DSN / 容器是否起)")
}
stored, err := cfg.EncryptedForStore() // AES-256-GCM 加密 APIKey(同 gateway
if err != nil {
fatal("加密失败:" + err.Error())
}
raw, _ := json.Marshal(stored)
if err := db.SetSetting(context.Background(), settingVoice, string(raw)); err != nil {
fatal("写库失败:" + err.Error())
}
fmt.Printf("✅ 语音配置已入库(%s\n", settingVoice)
fmt.Printf(" ASR resource=%q 可用=%v\n", cfg.ASRResourceID, cfg.ASREnabled())
fmt.Printf(" TTS resource=%q 音色=%q 可用=%v\n", cfg.TTSResourceID, cfg.TTSVoiceType, cfg.TTSEnabled())
fmt.Println(" 网关每次请求现读,无需重启;刷新桌面端点麦克风即可。")
}
func fatal(msg string) {
fmt.Fprintln(os.Stderr, "❌ "+msg)
os.Exit(1)
}