soniox

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 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 soniox is a scriptable fake of the Soniox async speech-to-text API (files and transcriptions). The fakes binary serves it for the e2e tests and unit tests import it directly, so both run against the same fake.

Index

Constants

View Source
const (
	KindFile          = "file"
	KindTranscription = "transcription"
)

Object kinds.

View Source
const (
	StatusQueued     = "queued"
	StatusProcessing = "processing"
	StatusCompleted  = "completed"
	StatusError      = "error"
)

Transcription statuses.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

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

Fake is the Soniox API fake. It is safe for concurrent use.

func New

func New() *Fake

New returns an empty Fake.

func (*Fake) Defaults

func (f *Fake) Defaults() map[string]http.HandlerFunc

Defaults returns the default answer of every Soniox route of the control server (served under /u/{upstream}), all backed by this fake. Merge it into control.Defaults() so a route without a scripted step falls through to the fake while scripted steps still win.

func (*Fake) Reset

func (f *Fake) Reset()

Reset drops every object, the script and the poll count.

func (*Fake) Seed

func (f *Fake) Seed(o Object)

Seed injects an object, such as a leftover from an earlier run. A missing ID gets a random one, a zero CreatedAt the current time, and a transcription without a status is "completed". A seeded object never changes status on its own.

func (*Fake) ServeHTTP

func (f *Fake) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the Soniox API below /v1 and the control API below /_control/soniox.

func (*Fake) SetScript

func (f *Fake) SetScript(s Script)

SetScript sets how transcriptions created from now on behave.

func (*Fake) State

func (f *Fake) State() State

State returns a snapshot of the fake.

type Object

type Object struct {
	ID                string          `json:"id"`
	Kind              string          `json:"kind"` // "file" | "transcription"
	Key               string          `json:"key"`  // the bearer that created it
	ClientReferenceID string          `json:"client_reference_id"`
	Status            string          `json:"status"` // transcriptions only
	FileID            string          `json:"file_id"`
	CreatedAt         time.Time       `json:"created_at"`
	CreateBody        json.RawMessage `json:"create_body,omitempty"` // transcriptions only: the exact JSON body received
}

Object is one file or transcription the fake holds.

type Script

type Script struct {
	Tokens          []Token       `json:"tokens"`
	Text            string        `json:"text"`
	AudioDurationMs int64         `json:"audio_duration_ms"`
	ProcessingFor   time.Duration `json:"processing_for"`     // wall time in "processing" after create (JSON: Go duration string)
	FailWith        string        `json:"fail_with"`          // non-empty: job ends status "error" with this error_message
	HTTPStatus      int           `json:"http_status"`        // non-zero: create answers this status with Soniox error body
	EchoAuthInError bool          `json:"echo_auth_in_error"` // error message includes the Authorization header value
}

Script is how the next transcriptions behave. A transcription takes the script that is set when it is created.

func (Script) MarshalJSON

func (s Script) MarshalJSON() ([]byte, error)

MarshalJSON writes ProcessingFor as a Go duration string.

func (*Script) UnmarshalJSON

func (s *Script) UnmarshalJSON(b []byte) error

UnmarshalJSON reads ProcessingFor as a Go duration string ("250ms", "1h") or as a number of nanoseconds.

type State

type State struct {
	Live    []Object `json:"live"`
	Deleted []Object `json:"deleted"`
	Polls   int      `json:"polls"`
}

State is a snapshot of the fake: live objects in creation order, deleted objects in deletion order, and the number of transcription polls.

type Token

type Token struct {
	Text              string  `json:"text"`
	StartMs           int64   `json:"start_ms"`
	EndMs             int64   `json:"end_ms"`
	Confidence        float64 `json:"confidence"`
	Speaker           string  `json:"speaker,omitempty"`
	Language          string  `json:"language,omitempty"`
	TranslationStatus string  `json:"translation_status,omitempty"`
}

Token is one transcript token as Soniox returns it.

Jump to

Keyboard shortcuts

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