docs(comments): 注释中文化 · internal/runtime/multimodal(21 文件,纯替换)
- 只翻注释/文档字符串,代码零变化:go/scanner 词法流比对 21 文件 token+字面量全等,增删行数 1:1(467/467) - 刻意保留非散文英文:JSON Schema description、工具 Description() 返回值、adapter prompt、API 路径与命令示例、环境变量名 - 逐行确认代码前缀未变,未触碰其他模块
This commit is contained in:
1 parent
b9e042d07d
commit
b0fbb8bc0d
21 files changed
+467
-467
No files matched your search
@@ -1,60 +1,60 @@
|
||||
// Package voice implements asynchronous speech-to-text and text-to-speech for
|
||||
// the Cyrene runtime, following DevDocs/design/06-多模态.md §1.
|
||||
// Package voice 为 Cyrene 运行时实现异步语音转文字与文字转语音,
|
||||
// 遵循 DevDocs/design/06-多模态.md §1。
|
||||
//
|
||||
// Voice input (STT) is transcribed to text and fed into the same agent pipeline
|
||||
// as a chat message; the reply is synthesized (TTS) back to audio. Both
|
||||
// directions degrade through a provider chain — cloud → local → edge-tts/espeak
|
||||
// → silent — so an unavailable provider falls through to the next rung instead
|
||||
// of failing the whole turn. The stub default implementations are HTTP-based and
|
||||
// testable with a stdlib httptest server; real cloud/local providers remain
|
||||
// adaptation points for later milestones.
|
||||
// 语音输入(STT)被转写为文字,并作为一条 chat 消息进入同一条智能体
|
||||
// 流水线;回复则被合成(TTS)回音频。两个
|
||||
// 方向都经一条提供方链降级 —— cloud → local → edge-tts/espeak
|
||||
// → silent —— 因此某个提供方不可用时会落到下一级,而不是
|
||||
// 让整个 turn 失败。默认实现是 HTTP 桩实现,可用
|
||||
// 标准库 httptest 服务器测试;真实的云端/本地提供方仍作为
|
||||
// 后续里程碑的适配点。
|
||||
package voice
|
||||
|
||||
import "context"
|
||||
|
||||
// Audio is a piece of audio data plus its encoding.
|
||||
// Audio 是一段音频数据及其编码。
|
||||
type Audio struct {
|
||||
// Format is the encoding, e.g. "wav", "mp3", "ogg".
|
||||
// Format 是编码格式,例如 "wav"、"mp3"、"ogg"。
|
||||
Format string
|
||||
// Data is the raw audio bytes.
|
||||
// Data 是原始音频字节。
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// STT converts audio to text.
|
||||
// STT 把音频转换成文字。
|
||||
type STT interface {
|
||||
// STT transcribes audio and returns the spoken text. ctx controls
|
||||
// cancellation and must be honored.
|
||||
// STT 转写音频并返回说出的文字。ctx 控制
|
||||
// 取消,必须被遵守。
|
||||
STT(ctx context.Context, audio Audio) (string, error)
|
||||
}
|
||||
|
||||
// TTS synthesizes speech audio from text.
|
||||
// TTS 从文字合成语音音频。
|
||||
type TTS interface {
|
||||
// TTS synthesizes audio from text. ctx controls cancellation and must be
|
||||
// honored.
|
||||
// TTS 从文字合成音频。ctx 控制取消,必须
|
||||
// 被遵守。
|
||||
TTS(ctx context.Context, text string) (Audio, error)
|
||||
}
|
||||
|
||||
// VoiceCloner creates a custom voice (声音复刻) from a public reference audio URL.
|
||||
// A nil-cloner provider (no cloud rung configured) returns ErrNotConfigured.
|
||||
// VoiceCloner 从公开的参考音频 URL 创建自定义音色(声音复刻)。
|
||||
// 未配置 cloner 的提供方(云端一级未配置)返回 ErrNotConfigured。
|
||||
type VoiceCloner interface {
|
||||
// CloneVoice creates a custom voice and returns its voice_id. referenceURL is
|
||||
// a public audio URL; prefix is the voice-name prefix (≤10 alphanumeric chars).
|
||||
// CloneVoice 创建自定义音色并返回其 voice_id。referenceURL 是
|
||||
// 公开音频 URL;prefix 是音色名前缀(≤10 个字母数字字符)。
|
||||
CloneVoice(ctx context.Context, referenceURL, prefix string) (string, error)
|
||||
}
|
||||
|
||||
// ctxKeyTTSInstruction is the context key for a per-request TTS instruction.
|
||||
// The TTS interface only carries (ctx, text), so an optional instruction is
|
||||
// threaded through ctx to reach the adapter without widening the interface.
|
||||
// ctxKeyTTSInstruction 是逐请求 TTS 指令的 context 键。
|
||||
// TTS 接口只携带 (ctx, text),因此可选指令经
|
||||
// ctx 透传以抵达适配器,而无需拓宽该接口。
|
||||
type ctxKeyTTSInstruction struct{}
|
||||
|
||||
// WithTTSInstruction returns ctx carrying an optional per-request TTS instruction
|
||||
// (emotion/tone) that overrides the configured VOICE_TTS_INSTRUCTION for one call.
|
||||
// WithTTSInstruction 返回携带一条逐请求 TTS 指令
|
||||
// (情绪/语气)的 ctx,该指令对这一次调用覆盖配置里的 VOICE_TTS_INSTRUCTION。
|
||||
func WithTTSInstruction(ctx context.Context, instruction string) context.Context {
|
||||
return context.WithValue(ctx, ctxKeyTTSInstruction{}, instruction)
|
||||
}
|
||||
|
||||
// TTSInstructionFromContext returns the per-request TTS instruction set by
|
||||
// WithTTSInstruction, or "" when none is carried.
|
||||
// TTSInstructionFromContext 返回由 WithTTSInstruction 设置的逐请求
|
||||
// TTS 指令,未携带时返回 ""。
|
||||
func TTSInstructionFromContext(ctx context.Context) string {
|
||||
if v, ok := ctx.Value(ctxKeyTTSInstruction{}).(string); ok {
|
||||
return v
|
||||
|
||||
Reference in new issue
Block a user