From 450c2c66c356819b35db2cab74dd0e0dc44c64c6 Mon Sep 17 00:00:00 2001 From: hhs <386998068@qq.com> Date: Sat, 13 Jun 2026 15:46:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9A=E4=B9=89=20TTS=20Service=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=88SynthesizeStream=20+=20Options/Chunk?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/ai/tts/tts.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 backend/internal/ai/tts/tts.go diff --git a/backend/internal/ai/tts/tts.go b/backend/internal/ai/tts/tts.go new file mode 100644 index 0000000..9b08d0e --- /dev/null +++ b/backend/internal/ai/tts/tts.go @@ -0,0 +1,25 @@ +package tts + +import "context" + +// Service 语音合成服务契约。 +type Service interface { + // SynthesizeStream 流式合成。 + // textStream 接收句子级文本(由 Orchestrator 的句子切分器产出), + // 返回的 channel 持续输出 MP3 音频 chunk。 + SynthesizeStream(ctx context.Context, textStream <-chan string, opts Options) (<-chan Chunk, error) +} + +// Options 合成参数。 +type Options struct { + Voice string // "alloy" | "nova" | "shimmer" 等 + Speed float64 // 1.0 为正常语速 + OutputFmt string // "mp3" — 固定使用 MP3 + SampleRate int // 24000 +} + +// Chunk 一个音频片段。 +type Chunk struct { + Audio []byte // MP3 音频数据(未 Base64 编码) + IsLast bool // 是否为最后一片 +}