alignv1
import alignv1 "pocketone.dev/ext/contracts/llm/align/v1"
Package alignv1 is the llm.align/v1 contract: forced alignment. Given a recording and the exact words spoken in it, a model says when each line and each word is said. Nothing is transcribed or guessed: every word that comes back is one that was sent, in the order sent. For captions timed to a narration, karaoke-style highlighting, or finding a phrase in a recording.
A wire contract at /api/_c/llm.align/v1. In pb_hooks it's $llm.align.
Source: ext/contracts/llm/align/v1.
Variables
var Contract = extkit.NewContract[Align]("llm.align/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)
Contract is llm.align/v1.
var W = extkit.NewWire(Contract, "llm", func(inner Align, g *extkit.Guard[Align]) Align {
return &guardAlign{inner, g}
},
extkit.Op[Align]{
Name: "align",
Desc: "Says when each line and word of the text is said in the audio.",
Method: "POST",
Path: "align",
In: reflect.TypeOf(AlignInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Align, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in AlignInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Align(ctx, a, in)
},
},
extkit.Op[Align]{
Name: "models",
Desc: "Lists the alignment models of every provider in Settings → LLM.",
Method: "GET",
Path: "models",
Scope: "llm:read",
In: reflect.TypeOf(llm.ModelsInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Align, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in llm.ModelsInput
if err := extkit.DecodeQuery(req.Query, &in); err != nil {
return nil, err
}
return impl.Models(ctx, a, in)
},
},
)
W is llm.align/v1's wire side: routes at /api/_c/llm.align/v1/<op>, action hooks, MCP tools and the client.
Functions
OnAlign
func OnAlign(owner any, fn func(e *extkit.CallEvent, in *AlignInput) error)
OnAlign binds fn to align calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnModels
func OnModels(owner any, fn func(e *extkit.CallEvent, in *llm.ModelsInput) error)
OnModels binds fn to models calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
Types
Align
type Align interface {
// Align says when each line and word of the text is said in the audio.
//
//op: POST align
Align(ctx context.Context, a extkit.Auth, in AlignInput) (Result, error)
// Models lists the alignment models of every provider in Settings → LLM.
//
//op: GET models scope=llm:read
Models(ctx context.Context, a extkit.Auth, in llm.ModelsInput) (llm.Models, error)
}
Align times the words of a recording.
AlignInput
type AlignInput struct {
Model string `json:"model"` // "provider/model", required
Audio llm.File `json:"audio"` // its Name's extension (story.mp3) or Type tells the provider the format
// Text is the words in the audio, one line per line. A line in square brackets ([Chorus]) labels the lines under it
// and isn't timed.
Text string `json:"text"`
// Mode is "speech" for a voice recording, or "lyrics" (the provider's default) to separate a sung vocal from the
// music first.
Mode string `json:"mode,omitempty"`
// Language is the text's language as an ISO 639-1 code ("en"); empty lets the model tell.
Language string `json:"language,omitempty"`
Options llm.Options `json:"options,omitempty"`
}
AlignInput is the recording and its words.
Client
type Client struct {
// contains filtered or unexported fields
}
Client is llm.align/v1 over HTTP, for the CLI and other apps. It implements Align; the token it was made with is the credential, so the extkit.Auth argument is ignored.
NewClient
func NewClient(baseURL, token string, hc *http.Client) *Client
NewClient calls llm.align/v1 on the app at baseURL with token (a PocketBase auth token or an API token).
Client.Align
func (c *Client) Align(ctx context.Context, _ extkit.Auth, in AlignInput) (Result, error)
Client.Models
func (c *Client) Models(ctx context.Context, _ extkit.Auth, in llm.ModelsInput) (llm.Models, error)
Line
type Line struct {
Index int `json:"index"` // which line of Text, counting from 0, skipping labels and blank lines
Text string `json:"text"`
Start float64 `json:"start"` // seconds from the start of the audio to its first word
End float64 `json:"end"` // seconds to the end of its last word
// Score is the model's confidence (higher is better); Certain is its judgement that the line is placed right.
Score float64 `json:"score"`
Certain bool `json:"certain"`
// Tag is the label of the line's section ("Chorus" for [Chorus]), when there is one.
Tag string `json:"tag,omitempty"`
}
Line is one line's place in the audio.
Result
type Result struct {
// Duration is the audio's length in seconds.
Duration float64 `json:"duration"`
// Lines are the lines placed in the audio, in order (labels and blank lines aren't lines).
Lines []Line `json:"lines"`
// Words are every word of those lines, in order.
Words []Word `json:"words"`
// Unaligned are lines the model couldn't place, listed instead of left out.
Unaligned []Unaligned `json:"unaligned,omitempty"`
Model string `json:"model"`
Usage llm.Usage `json:"usage"`
}
Result is when each line and word is said.
Unaligned
type Unaligned struct {
Line int `json:"line"`
Text string `json:"text"`
Reason string `json:"reason"`
}
Unaligned is a line the model couldn't place.
Word
type Word struct {
Line int `json:"line"` // the Index of its line
Text string `json:"text"`
Start float64 `json:"start"`
End float64 `json:"end"`
Score float64 `json:"score"`
}
Word is one word's place in the audio.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.