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("