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 ¶
const ( KindFile = "file" KindTranscription = "transcription" )
Object kinds.
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 (*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 ¶
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.
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 ¶
MarshalJSON writes ProcessingFor as a Go duration string.
func (*Script) UnmarshalJSON ¶
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.