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
@@ -15,17 +15,17 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
||||
)
|
||||
|
||||
// cloudMaxResponseBytes caps how much of a cloud voice response is read, so an
|
||||
// oversized or malformed response cannot exhaust memory. The request timeout
|
||||
// bounds a single call.
|
||||
// cloudMaxResponseBytes 限制读取云端语音响应的体积,使过大
|
||||
// 或畸形的响应无法耗尽内存。请求超时
|
||||
// 约束单次调用。
|
||||
const (
|
||||
cloudMaxResponseBytes = 8 << 20
|
||||
cloudHTTPTimeout = 180 * time.Second
|
||||
)
|
||||
|
||||
// HTTPSTT transcribes audio by POSTing a JSON body to a cloud endpoint and
|
||||
// reading {"text": "..."} back. It is the stubbed default STT implementation;
|
||||
// the real DashScope/whisper-facing adapter is an adaptation point.
|
||||
// HTTPSTT 通过向云端 endpoint POST 一个 JSON 请求体并
|
||||
// 读回 {"text": "..."} 来转写音频。它是桩式的默认 STT 实现;
|
||||
// 真正面向 DashScope/whisper 的适配器是一个适配点。
|
||||
type HTTPSTT struct {
|
||||
endpoint string
|
||||
apiKey string
|
||||
@@ -33,8 +33,8 @@ type HTTPSTT struct {
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// HTTPTTS synthesizes speech by POSTing a JSON body and reading the returned
|
||||
// base64 audio. It is the stubbed default TTS implementation.
|
||||
// HTTPTTS 通过 POST 一个 JSON 请求体并读取返回的
|
||||
// base64 音频来合成语音。它是桩式的默认 TTS 实现。
|
||||
type HTTPTTS struct {
|
||||
endpoint string
|
||||
apiKey string
|
||||
@@ -42,7 +42,7 @@ type HTTPTTS struct {
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// HTTPOption customizes the client and logger of an HTTPSTT/HTTPTTS.
|
||||
// HTTPOption 定制 HTTPSTT/HTTPTTS 的 client 与日志器。
|
||||
type HTTPOption func(*httpConfig)
|
||||
|
||||
type httpConfig struct {
|
||||
@@ -50,7 +50,7 @@ type httpConfig struct {
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// WithHTTPClient sets the *http.Client used for the call; nil keeps the default.
|
||||
// WithHTTPClient 设置该调用所用的 *http.Client;nil 表示保持默认。
|
||||
func WithHTTPClient(c *http.Client) HTTPOption {
|
||||
return func(o *httpConfig) {
|
||||
if c != nil {
|
||||
@@ -59,7 +59,7 @@ func WithHTTPClient(c *http.Client) HTTPOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogger sets the logger used on failures; nil keeps a discard logger.
|
||||
// WithLogger 设置失败时使用的日志器;nil 表示保持丢弃日志器。
|
||||
func WithLogger(l *slog.Logger) HTTPOption {
|
||||
return func(o *httpConfig) {
|
||||
if l != nil {
|
||||
@@ -68,7 +68,7 @@ func WithLogger(l *slog.Logger) HTTPOption {
|
||||
}
|
||||
}
|
||||
|
||||
// NewHTTPSTT builds an HTTPSTT for the given endpoint and API key.
|
||||
// NewHTTPSTT 为给定 endpoint 与 API key 构造一个 HTTPSTT。
|
||||
func NewHTTPSTT(endpoint, apiKey string, opts ...HTTPOption) *HTTPSTT {
|
||||
h := &httpConfig{client: defaultHTTPClient(), log: discardLogger()}
|
||||
for _, o := range opts {
|
||||
@@ -77,7 +77,7 @@ func NewHTTPSTT(endpoint, apiKey string, opts ...HTTPOption) *HTTPSTT {
|
||||
return &HTTPSTT{endpoint: strings.TrimRight(endpoint, "/"), apiKey: apiKey, client: h.client, log: h.log}
|
||||
}
|
||||
|
||||
// NewHTTPTTS builds an HTTPTTS for the given endpoint and API key.
|
||||
// NewHTTPTTS 为给定 endpoint 与 API key 构造一个 HTTPTTS。
|
||||
func NewHTTPTTS(endpoint, apiKey string, opts ...HTTPOption) *HTTPTTS {
|
||||
h := &httpConfig{client: defaultHTTPClient(), log: discardLogger()}
|
||||
for _, o := range opts {
|
||||
@@ -86,19 +86,19 @@ func NewHTTPTTS(endpoint, apiKey string, opts ...HTTPOption) *HTTPTTS {
|
||||
return &HTTPTTS{endpoint: strings.TrimRight(endpoint, "/"), apiKey: apiKey, client: h.client, log: h.log}
|
||||
}
|
||||
|
||||
// sttRequest is the JSON body sent to the STT endpoint.
|
||||
// sttRequest 是发往 STT endpoint 的 JSON 请求体。
|
||||
type sttRequest struct {
|
||||
Audio string `json:"audio"`
|
||||
Format string `json:"format"`
|
||||
}
|
||||
|
||||
// sttResponse is the transcription returned by the STT endpoint.
|
||||
// sttResponse 是 STT endpoint 返回的转写。
|
||||
type sttResponse struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// STT posts the audio and returns the recognized text. A blank endpoint returns
|
||||
// ErrNotConfigured so the chain degrades.
|
||||
// STT 发送音频并返回识别出的文字。endpoint 为空时返回
|
||||
// ErrNotConfigured,链随之降级。
|
||||
func (s *HTTPSTT) STT(ctx context.Context, audio Audio) (string, error) {
|
||||
if s.endpoint == "" {
|
||||
return "", ErrNotConfigured
|
||||
@@ -122,19 +122,19 @@ func (s *HTTPSTT) STT(ctx context.Context, audio Audio) (string, error) {
|
||||
return decoded.Text, nil
|
||||
}
|
||||
|
||||
// ttsRequest is the JSON body sent to the TTS endpoint.
|
||||
// ttsRequest 是发往 TTS endpoint 的 JSON 请求体。
|
||||
type ttsRequest struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// ttsResponse is the synthesized audio returned by the TTS endpoint.
|
||||
// ttsResponse 是 TTS endpoint 返回的合成音频。
|
||||
type ttsResponse struct {
|
||||
Audio string `json:"audio"`
|
||||
Format string `json:"format"`
|
||||
}
|
||||
|
||||
// TTS posts the text and returns the decoded audio. A blank endpoint returns
|
||||
// ErrNotConfigured so the chain degrades.
|
||||
// TTS 发送文本并返回解码后的音频。endpoint 为空时返回
|
||||
// ErrNotConfigured,链随之降级。
|
||||
func (s *HTTPTTS) TTS(ctx context.Context, text string) (Audio, error) {
|
||||
if s.endpoint == "" {
|
||||
return Audio{}, ErrNotConfigured
|
||||
@@ -169,7 +169,7 @@ func (s *HTTPTTS) TTS(ctx context.Context, text string) (Audio, error) {
|
||||
return Audio{Format: format, Data: data}, nil
|
||||
}
|
||||
|
||||
// postJSON POSTs a JSON payload, wires auth, and checks the status code.
|
||||
// postJSON POST 一个 JSON 载荷,接好鉴权并检查状态码。
|
||||
func postJSON(ctx context.Context, client *http.Client, apiKey, url string, payload []byte) (*http.Response, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(payload))
|
||||
if err != nil {
|
||||
@@ -190,41 +190,41 @@ func postJSON(ctx context.Context, client *http.Client, apiKey, url string, payl
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// defaultHTTPClient builds a client with a request timeout. A fresh client is
|
||||
// returned per call rather than a package global, which the constraints forbid.
|
||||
// defaultHTTPClient 构造一个带请求超时的 client。这里每次调用
|
||||
// 返回新 client,而不是包级全局变量——后者为约束所禁止。
|
||||
func defaultHTTPClient() *http.Client {
|
||||
return &http.Client{Transport: http.DefaultTransport, Timeout: cloudHTTPTimeout}
|
||||
}
|
||||
|
||||
// discardLogger returns a logger that drops all output.
|
||||
// discardLogger 返回一个丢弃全部输出的日志器。
|
||||
func discardLogger() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
}
|
||||
|
||||
// newDashboardSTT returns the cloud STT adapter for a DashScope config. A call
|
||||
// returns ErrNotConfigured when no API key is set so the chain degrades.
|
||||
// newDashboardSTT 为 DashScope 配置返回云端 STT 适配器。未设置
|
||||
// API key 时调用会返回 ErrNotConfigured,链随之降级。
|
||||
func newDashboardSTT(cfg config.VoiceConfig) STT {
|
||||
return NewDashscopeSTT(cfg)
|
||||
}
|
||||
|
||||
// newDashboardTTS returns the cloud TTS adapter for a DashScope config.
|
||||
// newDashboardTTS 为 DashScope 配置返回云端 TTS 适配器。
|
||||
func newDashboardTTS(cfg config.VoiceConfig) TTS {
|
||||
return NewDashscopeTTS(cfg)
|
||||
}
|
||||
|
||||
// newDashboardCloner returns the cloud voice-enrollment cloner for a DashScope
|
||||
// config, used by the create_voice (声音复刻) endpoint.
|
||||
// newDashboardCloner 为 DashScope 配置返回云端音色注册 cloner,
|
||||
// 供 create_voice(声音复刻)endpoint 使用。
|
||||
func newDashboardCloner(cfg config.VoiceConfig) VoiceCloner {
|
||||
return NewDashscopeCloner(cfg)
|
||||
}
|
||||
|
||||
// newEdgeTTS returns the edge-tts adapter point (not yet implemented).
|
||||
// newEdgeTTS 返回 edge-tts 适配点(尚未实现)。
|
||||
func newEdgeTTS() TTS { return notImplementedTTS{} }
|
||||
|
||||
// newEspeak returns the espeak adapter point (not yet implemented).
|
||||
// newEspeak 返回 espeak 适配点(尚未实现)。
|
||||
func newEspeak() TTS { return notImplementedTTS{} }
|
||||
|
||||
// notImplementedTTS is an adaptation point that always degrades.
|
||||
// notImplementedTTS 是一个总是降级的适配点。
|
||||
type notImplementedTTS struct{}
|
||||
|
||||
func (notImplementedTTS) TTS(_ context.Context, _ string) (Audio, error) {
|
||||
|
||||
Reference in new issue
Block a user