stt

package
v0.268.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stt is muster's client for an OpenAI-style speech-to-text service: `POST /v1/audio/transcriptions`, a multipart body whose `file` part is the recording, authenticated with a bearer token.

🔴 IT EXISTS SO THE TOKEN NEVER REACHES A BROWSER. The message box's microphone records in the browser and posts the audio to muster (api's transcribe route); muster adds the credential here and answers with the text. A page that called the service itself would have to be handed the token.

🔴 ITS FAILURES ARE NAMED ERRORS, NOT A STATUS CODE AND NOT THE SERVICE'S BODY. The caller must tell "the recording is unusable" from "our credential is wrong" from "the service is not answering", and say a different thing to a different reader for each. Returning the upstream status would push that mapping into the handler, and forwarding the upstream sentence would put words written for the token's holder in front of a browser.

Index

Constants

View Source
const DefaultTimeout = 60 * time.Second

DefaultTimeout bounds one transcription: the upload, the model's run over the audio, and the answer.

It is not a network-latency figure. The service runs a model over the recording synchronously; a two-minute dictation on a warm GPU answers in a few seconds, and the same on a cold one (the first request after the model loads) has been measured at roughly a third of real time. A minute covers that with room, and is still short enough that a wedged service frees the caller's slot rather than holding it.

View Source
const TranscribePath = "/v1/audio/transcriptions"

TranscribePath is the service's endpoint.

Variables

View Source
var (
	ErrUndecodable = errors.New("stt: the service could not decode that audio")
	ErrRefused     = errors.New("stt: the service refused this server's token")
	ErrTooLong     = errors.New("stt: the audio is longer than the service accepts")
	ErrUnavailable = errors.New("stt: the service could not answer")
)

The answers Transcribe gives besides a transcript.

400            ErrUndecodable  the service could not decode the audio
401, 403       ErrRefused      the bearer token is missing or wrong
413            ErrTooLong      longer than the service accepts
anything else  ErrUnavailable  not loaded, decoder died, a 5xx, a dial
                               failure, a timeout, an unreadable 200

🔴 AN UNMAPPED STATUS IS ErrUnavailable, AND THAT DEFAULT IS THE SAFE DIRECTION: "try again in a moment" is honest and harmless for something this package does not understand, while ErrUndecodable would tell a person their recording can never work.

Functions

func StatusError

func StatusError(code int) error

StatusError maps a non-200 status onto the named errors. It is a function so the mapping — the whole contract with the service — is table-tested without a server.

Types

type Client

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

Client is a speech-to-text client. Its zero value is not usable; see New.

func New

func New(baseURL, token string, timeout time.Duration) (*Client, error)

New builds a Client for the service at baseURL (http(s)://host[:port], no path) presenting token. timeout ≤ 0 means DefaultTimeout.

🔴 NO PROXY AND NO REDIRECTS: every request carries the credential. An environment proxy would be handed it, and a redirect would carry it to wherever the answer pointed, so a 3xx is just a status that is not 200.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint is the URL Transcribe posts to (for the boot banner; it carries no credential).

func (*Client) Transcribe

func (c *Client) Transcribe(ctx context.Context, audio io.Reader, filename string) (string, error)

Transcribe sends audio and returns what the service heard ("" when it heard nothing).

🔴 filename IS LOAD-BEARING. The service names its temporary file with the name's extension and hands that file to its decoder, so webm bytes under a `.wav` name are the one input that makes a good recording undecodable. The caller sniffs the bytes and chooses it; this package cannot.

The audio is STREAMED into the request body (io.Pipe), not buffered: the caller's reader is read exactly once, as the request is sent. When the caller's reader fails, the request fails and Transcribe returns ErrUnavailable wrapping that failure — the caller, which owns the reader, is the one that can tell a size cap from a client that went away.

language and punctuation are sent explicitly although the service defaults them: a change of default on that side would otherwise silently change what lands in the message box.

func (*Client) WithModel

func (c *Client) WithModel(model string) *Client

WithModel returns a copy of c that also sends a `model` form field naming model. "" (the default) sends none.

🔴 THE FIELD IS OPTIONAL ON THE WIRE BECAUSE THE SERVICES DISAGREE. The bundled stt-cohere server serves one model and ignores it; OpenAI's API and faster-whisper servers such as speaches REFUSE a request without one (speaches answers 422, which this package reads as ErrUnavailable — "try again" for a request that can never work). So it is sent only when configured, and a cohere deployment's request body is byte-for-byte what it was before.

Jump to

Keyboard shortcuts

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