sttclient

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sttclient calls a whisper.cpp whisper-server (over llama-swap's /upstream/<model>/inference passthrough) to transcribe a 16 kHz mono WAV. It requests response_format=verbose_json so the reply carries per-segment timestamps (the {gist, segments[]} citation pattern). Audio bytes go straight to whisper-server and NEVER touch the text Gemma cascade. Pure net/http + mime/multipart; no cgo, no cloud.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SRT

func SRT(segs []Segment) string

SRT renders segments as SubRip text (1-indexed, HH:MM:SS,mmm timestamps).

Types

type Client

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

Client posts audio to whisper-server through llama-swap on base (e.g. http://127.0.0.1:11436). Every inference is serialized by the process-global inferMu (whisper-server is single-slot and crashes on overlapping requests).

func New

func New(base string, timeout time.Duration) *Client

New builds a client. timeout bounds one transcription (long audio).

func (*Client) Transcribe

func (c *Client) Transcribe(ctx context.Context, model, wavPath string, p Params) (Result, error)

Transcribe uploads wavPath to the whisper upstream `model` and returns the parsed verbose_json. The multipart body is built in memory (wavs are 16 kHz mono — ~2 MB/min — comfortable in 64 GB RAM).

func (*Client) Unload

func (c *Client) Unload(ctx context.Context, model string) error

Unload force-frees the whisper upstream's VRAM immediately (zero-always-warm), rather than waiting for the ttl:300 idle timer. Best-effort: any error is the caller's to ignore.

type Params

type Params struct {
	Language      string  // "" => auto-detect (sent as language=auto)
	BeamSize      int     // -bs; default greedy in whisper, so 5 is set explicitly
	BestOf        int     // -bo; candidates for temperature fallback
	MaxContext    int     // -mc; condition-on-previous-text cap (kills repetition loops)
	EntropyThold  float64 // -et; raise to fire the repetition detector sooner
	NoSpeechThold float64 // -nth
	Temperature   float64 // base decode temperature (fallback steps up from here)
	VAD           bool    // enable Silero VAD (server loaded with -vm)
	VADThreshold  float64 // -vt
	MaxLen        int     // -ml; subtitle-sized segments (chars)
	SplitOnWord   bool    // -sow; split at word boundaries for clean SRT
}

Params are the per-request decode knobs whisper-server accepts as form fields. Defaults (DefaultParams) are the research-tuned profile for noisy EN/ES field audio; Language is set by the caller per call.

func DefaultParams

func DefaultParams() Params

DefaultParams returns the tuned profile for noisy EN/ES field audio.

func (Params) ResponseFormat

func (Params) ResponseFormat() string

ResponseFormat is fixed: verbose_json is the ONLY format that returns segments.

type Result

type Result struct {
	Language string    `json:"language"`
	Duration float64   `json:"duration"`
	Text     string    `json:"text"`
	Segments []Segment `json:"segments"`
}

Result is the parsed whisper-server verbose_json response.

type Segment

type Segment struct {
	ID           int     `json:"id"`
	Start        float64 `json:"start"`
	End          float64 `json:"end"`
	Text         string  `json:"text"`
	Words        []Word  `json:"words"`
	AvgLogprob   float64 `json:"avg_logprob"`
	NoSpeechProb float64 `json:"no_speech_prob"`
}

Segment is one timestamped span of the transcript (start/end in seconds), plus the per-word array and decode-confidence fields whisper-server already returns. These flow through to the on-disk .segments.json (pipeline writes the full tr.Segments) for downstream consumers that need word-accurate timing and per-word confidence.

type Word

type Word struct {
	Word        string  `json:"word"`
	Start       float64 `json:"start"`
	End         float64 `json:"end"`
	Probability float64 `json:"probability"`
}

Word is one timestamped word with whisper's per-word confidence. whisper-server emits words[] in verbose_json BY DEFAULT (no extra request field needed — adding token_timestamps can segfault this build); the dataset/segmentation tooling uses these to cut only at whole-word boundaries and to drop low-confidence stumbles.

Jump to

Keyboard shortcuts

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