sttproxy

package
v0.8.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package sttproxy implements the /v1/audio/transcriptions pipeline for the Go rewrite. It ports src/sse/handlers/stt.js (handleStt) + open-sse/handlers/sttCore.js (handleSttCore): parse the multipart form, resolve the provider's static STT config, dispatch by format (deepgram raw-binary, assemblyai upload→submit→poll, gemini generateContent, openai-compatible multipart passthrough), and return either the reshaped { "text": "..." } JSON or the raw upstream body for the OpenAI-compatible case (which forwards response_format unchanged).

NOT in this MVP slice (separate slices, mirroring the video/fetch scope): the multi-account fallback rotation loop (excludeConnectionIds), usage persistence (the legacy STT path never persisted usage), and on-401 token refresh. x-9gouter-connection-id is NOT returned by STT (the JS handler does not echo it — unlike video). The provider is resolved at the handler from body.model (provider/model prefix) and passed in as ProviderID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dependencies

type Dependencies struct {
	// HTTPClient performs upstream calls. Defaults to a 300s-timeout client
	// (matching the JS maxDuration=300 for large audio uploads).
	HTTPClient *http.Client
	Logger     Logger
	Config     config.Config
}

Dependencies wires the sttproxy Handler.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler runs the STT pipeline.

func New

func New(deps Dependencies) *Handler

New constructs a Handler with sane defaults.

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, req Request) Result

Handle dispatches the STT upstream call by the provider's static config.

type Logger

type Logger interface {
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
	Debugf(format string, args ...any)
}

Logger is a minimal log sink.

type Request

type Request struct {
	Ctx        context.Context
	ProviderID string
	Model      string
	// File is the uploaded audio bytes.
	File []byte
	// Filename is the upload filename (may be empty; defaults to "audio.wav").
	Filename string
	// FileMIME is the browser-provided MIME (may be empty; resolved from ext).
	FileMIME string
	// FormFields are the non-file multipart fields (model, language, prompt,
	// response_format, temperature, timestamp_granularities, ...).
	FormFields  map[string]string
	Credentials domainProv.Credentials
	UserAgent   string
}

Request is the input to Handle.

type Result

type Result struct {
	StatusCode int
	Err        error
	// Body is the response body bytes.
	Body []byte
	// ContentType is the response Content-Type to forward to the client.
	ContentType string
}

Result is the output of Handle.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL