Documentation
¶
Overview ¶
Package soniox serves OpenAI-style speech-to-text over Soniox's async API: one multipart request becomes upload, create, poll, fetch and delete, and Soniox tokens are grouped into words and speaker segments.
Index ¶
- Constants
- type APIError
- type Adapter
- type Client
- func (c *Client) CreateTranscription(ctx context.Context, key string, cr CreateRequest) (Transcription, error)
- func (c *Client) DeleteFile(ctx context.Context, key, id string) error
- func (c *Client) DeleteTranscription(ctx context.Context, key, id string) error
- func (c *Client) GetTranscript(ctx context.Context, key, id string) (Transcript, error)
- func (c *Client) GetTranscription(ctx context.Context, key, id string) (Transcription, error)
- func (c *Client) ListFiles(ctx context.Context, key string) ([]File, error)
- func (c *Client) ListTranscriptions(ctx context.Context, key string) ([]Transcription, error)
- func (c *Client) UploadFile(ctx context.Context, key, ref, filename string, body io.Reader) (File, error)
- type Config
- type CreateRequest
- type File
- type Grouping
- type KeySource
- type ParamError
- type Segment
- type SweepResult
- type Sweeper
- type Token
- type Transcript
- type Transcription
- type Usage
- type VerboseJSON
- type Word
Constants ¶
const ( DefaultBaseURL = "https://api.soniox.com" DefaultPollInterval = time.Second DefaultDeadline = 30 * time.Minute DefaultPause = time.Second DefaultMaxSegment = 30 * time.Second )
Defaults and bounds of Config.
const ( StatusQueued = "queued" StatusProcessing = "processing" StatusCompleted = "completed" StatusError = "error" )
Transcription statuses.
const DefaultMaxAge = time.Hour
DefaultMaxAge is how old a remora-tagged leftover must be before the sweeper deletes it.
const RefPrefix = "remora:"
RefPrefix starts the client_reference_id of every file and transcription remora creates; the sweeper only touches objects that carry it.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Op string // the operation, such as "create transcription"
Status int
Type string // Soniox error_type
Message string // Soniox message, redacted
}
APIError is a non-2xx answer from Soniox. Error() never contains the key.
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter serves POST /v1/audio/transcriptions (OpenAI multipart) over the Soniox async API. The Soniox key is the request's bearer token, so the adapter holds no key of its own.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the Soniox async API. The key is passed per call, so one Client serves every account.
func NewClient ¶
NewClient returns a Client for baseURL (such as "https://api.soniox.com"). A nil hc means http.DefaultClient.
func (*Client) CreateTranscription ¶
func (c *Client) CreateTranscription(ctx context.Context, key string, cr CreateRequest) (Transcription, error)
CreateTranscription starts a transcription.
func (*Client) DeleteFile ¶
DeleteFile deletes a file; a missing file counts as deleted.
func (*Client) DeleteTranscription ¶
DeleteTranscription deletes a transcription; a missing one counts as deleted.
func (*Client) GetTranscript ¶
GetTranscript fetches the transcript of a completed transcription.
func (*Client) GetTranscription ¶
GetTranscription reads a transcription's status.
func (*Client) ListFiles ¶
ListFiles lists every file of the key's account, following next_page_cursor to the end.
func (*Client) ListTranscriptions ¶
ListTranscriptions lists every transcription of the key's account, following next_page_cursor to the end.
type Config ¶
type Config struct {
BaseURL string // default "https://api.soniox.com"
PollInterval time.Duration // default 1s; clamped to [500ms, 60s]
Deadline time.Duration // default 30m; whole job from upload to transcript
Grouping Grouping // defaults 1s / 30s
HTTPClient *http.Client // default &http.Client{} (no overall timeout; contexts bound every call)
Logger *slog.Logger
}
Config configures the Adapter. Zero values take the defaults.
type CreateRequest ¶
type CreateRequest struct {
Model string `json:"model"`
FileID string `json:"file_id"`
ClientReferenceID string `json:"client_reference_id"`
LanguageHints []string `json:"language_hints,omitempty"`
LanguageHintsStrict *bool `json:"language_hints_strict,omitempty"`
EnableSpeakerDiarization *bool `json:"enable_speaker_diarization,omitempty"`
EnableLanguageIdentification *bool `json:"enable_language_identification,omitempty"`
Context json.RawMessage `json:"context,omitempty"` // a JSON string or object
Translation json.RawMessage `json:"translation,omitempty"` // a JSON object
}
CreateRequest is the body of POST /v1/transcriptions.
type File ¶
type File struct {
ID string `json:"id"`
Filename string `json:"filename"`
ClientReferenceID string `json:"client_reference_id"`
CreatedAt time.Time `json:"created_at"`
}
File is an uploaded Soniox file.
type Grouping ¶
Grouping bounds segments: a pause of at least Pause or a segment longer than MaxSegment starts a new one, but only at a word boundary.
type KeySource ¶
KeySource returns the Soniox keys to sweep, such as the enabled Soniox provider keys in the store.
type ParamError ¶
type ParamError struct{ Field, Reason string }
ParamError is a client mistake; the handler answers 400 with Error() as the message.
func (*ParamError) Error ¶
func (e *ParamError) Error() string
Error returns `unsupported parameter "<field>"` for an unknown field, else `invalid parameter "<field>": <reason>`.
type Segment ¶
type Segment struct {
ID int `json:"id"`
Speaker string `json:"speaker,omitempty"`
Start float64 `json:"start"`
End float64 `json:"end"`
Text string `json:"text"`
}
Segment is one speaker segment of the OpenAI verbose_json answer.
type SweepResult ¶
type SweepResult struct{ Transcriptions, Files int }
SweepResult counts what one sweep deleted.
type Sweeper ¶
type Sweeper struct {
Client *Client
Keys KeySource
MaxAge time.Duration // 1h, from the spec
Now func() time.Time // default time.Now
Logger *slog.Logger
}
Sweeper deletes Soniox files and transcriptions that remora created (their client_reference_id starts with RefPrefix) and that outlived MaxAge, such as leftovers of a crash. Objects without the prefix are never touched. An owned job still queued or processing past MaxAge loses its file, which makes it fail; a later sweep then deletes the failed transcription.
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"`
Language string `json:"language"`
TranslationStatus string `json:"translation_status"`
}
Token is one (often sub-word) transcript token.
type Transcript ¶
type Transcript struct {
ID string `json:"id"`
Text string `json:"text"`
Tokens []Token `json:"tokens"`
}
Transcript is the result of a completed transcription.
type Transcription ¶
type Transcription struct {
ID string `json:"id"`
Status string `json:"status"` // queued|processing|completed|error
FileID string `json:"file_id"`
ClientReferenceID string `json:"client_reference_id"`
ErrorType string `json:"error_type"`
ErrorMessage string `json:"error_message"`
AudioDurationMs int64 `json:"audio_duration_ms"`
CreatedAt time.Time `json:"created_at"`
}
Transcription is a Soniox async transcription job.
type VerboseJSON ¶
type VerboseJSON struct {
Task string `json:"task"` // "transcribe"
Language string `json:"language,omitempty"`
Duration float64 `json:"duration"`
Text string `json:"text"`
Words []Word `json:"words"`
Segments []Segment `json:"segments"`
Usage Usage `json:"usage"`
}
VerboseJSON is the OpenAI verbose_json transcription answer.