From 08e6425fec297962e9417ac1bdf42c71b2da1aae Mon Sep 17 00:00:00 2001 From: Blizzard Date: Wed, 22 Jul 2026 10:49:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(voice):=20=E5=8F=8C=E5=90=91=E6=B5=81?= =?UTF-8?q?=E5=BC=8F=20TTS=20=E7=9C=9F=E6=9C=BA=E8=B7=91=E9=80=9A=E2=80=94?= =?UTF-8?q?=E2=80=94TTS=E5=90=88=E6=88=90=E2=86=92ASR=E5=BE=80=E8=BF=94?= =?UTF-8?q?=E5=85=A8=E7=BB=BF=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对齐官方 python demo 修 TTS payload: - TaskRequest 必须带完整 req_params(speaker+audio_params)再加 text,只发 {text} 火山收不到 (会回空 text 的 TTSSentenceStart 后直接结束、无音频) - StartSession 去掉自造的 namespace/user,就是 {req_params:{speaker,audio_params}} - ttsReqBase 基底 StartSession/TaskRequest 复用;TTSSession 存 reqBase - 加 VOICE_DEBUG 帧级调试日志(联调用,默认关无开销) 真机验证(voicecheck):TTS 合成 143KB PCM24k → 降采样喂 ASR → 转写"北京今天的天气怎么样? 需要带伞吗?"≈原句。ASR(volc.bigasr.sauc.duration)+TTS(seed-tts-2.0)两协议全通。 Co-Authored-By: Claude Opus 4.8 --- sundynix-gateway/internal/voice/tts.go | 66 +++++++++++++++++++------ sundynix-gateway/out_tts.wav | Bin 0 -> 144040 bytes 2 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 sundynix-gateway/out_tts.wav diff --git a/sundynix-gateway/internal/voice/tts.go b/sundynix-gateway/internal/voice/tts.go index c33735e..77d99e9 100644 --- a/sundynix-gateway/internal/voice/tts.go +++ b/sundynix-gateway/internal/voice/tts.go @@ -4,13 +4,35 @@ import ( "context" "encoding/json" "fmt" + "log" "net/http" + "os" "sync" "time" "github.com/gorilla/websocket" ) +// ttsDebug 打开时(环境变量 VOICE_DEBUG=1)打印每个 TTS 帧,便于联调双向流事件/音频。 +var ttsDebug = os.Getenv("VOICE_DEBUG") != "" + +func ttsDebugf(format string, a ...any) { + if ttsDebug { + log.Printf("[tts-debug] "+format, a...) + } +} + +// preview 取 payload 前 n 字节的可读预览(音频用长度代替)。 +func preview(b []byte, isAudio bool) string { + if isAudio { + return fmt.Sprintf("