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 // 是否为最后一片 +}