Documentation
¶
Overview ¶
Package transcription defines the serializable audio-to-text protocol and its single-method Model capability.
NewRequest accepts validated media audio. Options carries the shared language hint and provider extensions written through Options.Extensions.Set so they are JSON-safe. Request has no arbitrary parameter bag. Implementations and defaults live outside Core.
Example ¶
package main
import (
"fmt"
"github.com/Tangerg/scope/core/media"
"github.com/Tangerg/scope/core/transcription"
)
func main() {
audio, err := media.NewBytes("audio/wav", []byte("audio"))
if err != nil {
panic(err)
}
request, err := transcription.NewRequest(audio)
if err != nil {
panic(err)
}
options := transcription.Options{Model: "transcription-model"}
err = options.Validate()
if err != nil {
panic(err)
}
options.Language = "en"
request.Options = options
fmt.Println(request.Audio.MIME, request.Options.Language)
}
Output: audio/wav en
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model interface {
// Call transcribes one validated media request without retaining or mutating
// it. The returned provider-neutral response belongs to the caller, and
// context cancellation remains identifiable through errors.Is.
Call(ctx context.Context, request *Request) (*Response, error)
}
Model is the complete provider-neutral transcription SPI. Implementations validate requests before I/O, reject explicit options they cannot represent, and return responses that pass Validate; provider defaults and identity belong to provider construction.
type Options ¶
type Options struct {
Model string `json:"model"`
// Language is an ISO-639-1 language code (e.g. "en", "zh") hinting
// the spoken language. Empty leaves detection to the provider.
Language string `json:"language"`
Extensions metadata.Extensions `json:"extensions,omitzero"`
}
Options holds provider-neutral transcription configuration. Provider-specific controls belong in Extensions. Resolve overlays only explicitly supplied values and snapshots extension data, leaving both inputs unchanged.
func (Options) MarshalJSON ¶
func (*Options) UnmarshalJSON ¶
type Output ¶
type Output struct {
// Text may be empty for partial or silent segments.
Text string `json:"text"`
Metadata metadata.Map `json:"metadata,omitzero"`
}
func (Output) MarshalJSON ¶
func (*Output) UnmarshalJSON ¶
type Request ¶
type Request struct {
Audio *media.Media `json:"audio,omitzero"`
Options Options `json:"options,omitzero"`
}
func (Request) MarshalJSON ¶
func (*Request) UnmarshalJSON ¶
type Response ¶
type Response struct {
Output *Output `json:"output,omitzero"`
Metadata *ResponseMetadata `json:"metadata,omitzero"`
}
Response is one transcription call's output plus shared metadata. Providers may store per-segment timing in Output.Metadata while Output.Text holds the merged transcript.
func NewResponse ¶
func NewResponse(output *Output, responseMetadata *ResponseMetadata) (*Response, error)
func (Response) MarshalJSON ¶
func (*Response) UnmarshalJSON ¶
type ResponseMetadata ¶
type ResponseMetadata struct {
Model string `json:"model"`
CreatedAt time.Time `json:"created_at,omitzero"`
Extra metadata.Map `json:"extra,omitzero"`
}
func (ResponseMetadata) MarshalJSON ¶
func (r ResponseMetadata) MarshalJSON() ([]byte, error)
func (*ResponseMetadata) UnmarshalJSON ¶
func (r *ResponseMetadata) UnmarshalJSON(data []byte) error