customize

package
v0.68.26 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package customize defines SpeechKit's public Words/Replacements contract.

Index

Constants

View Source
const PackSchemaVersion = "speechkit.customization.pack.v1"

Variables

This section is empty.

Functions

func FoldVocabulary added in v0.61.10

func FoldVocabulary(words []Word, replacements []Replacement) (folded []Word, extras []Replacement)

FoldVocabulary attaches synonym/substitution rewrites whose output matches a Word onto that Word's sounds_like list. Remaining replacements are extras (punctuation, regex, snippets, commands).

func MaterializeVocabulary added in v0.61.10

func MaterializeVocabulary(words []Word, extras []Replacement) (merged []Word, replacements []Replacement)

MaterializeVocabulary merges Words and rebuilds alias replacements from sounds_like. extras must already be non-alias rules; derived aliases that also appear in extras are dropped so Words stay the source of truth.

func NormalizeAliasList added in v0.61.9

func NormalizeAliasList(term string, aliases []string) []string

NormalizeAliasList trims, drops empties, drops the canonical term, and de-duplicates case-insensitively while keeping first-seen spelling.

func NormalizeLanguage

func NormalizeLanguage(language string) string

func ReplacementIdentityKey added in v0.61.9

func ReplacementIdentityKey(replacement Replacement) string

ReplacementIdentityKey is the authoring identity for a Replacement. Output is intentionally not part of the key: many spoken forms may rewrite to the same canonical word.

func StableID

func StableID(prefix string, parts ...string) string

func ValidatePack

func ValidatePack(pack Pack) error

func ValidateReplacement

func ValidateReplacement(replacement Replacement) error

func ValidateWord

func ValidateWord(word Word) error

func WordIdentityKey added in v0.61.9

func WordIdentityKey(word Word) string

WordIdentityKey is the authoring identity for a Word: language + term.

Types

type Context

type Context struct {
	Mode              Mode       `json:"mode,omitempty"`
	Language          string     `json:"language,omitempty"`
	Stage             Stage      `json:"stage,omitempty"`
	Tags              []string   `json:"tags,omitempty"`
	Persona           string     `json:"persona,omitempty"`
	ActiveTemplateIDs []string   `json:"active_template_ids,omitempty"`
	ScopeOrder        []ScopeRef `json:"scope_order,omitempty"`
}

type Kind

type Kind string
const (
	KindSubstitution Kind = "substitution"
	KindSynonym      Kind = "synonym"
	KindSnippet      Kind = "snippet"
	KindCommand      Kind = "command"
	KindTemplate     Kind = "template"
)

func NormalizeKind

func NormalizeKind(kind Kind) Kind

type Lexicon

type Lexicon struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Language    string    `json:"language,omitempty"`
	WordIDs     []string  `json:"word_ids,omitempty"`
	Tags        []string  `json:"tags,omitempty"`
	Source      string    `json:"source,omitempty"`
	Scope       *ScopeRef `json:"scope,omitempty"`
	Enabled     bool      `json:"enabled"`
	CreatedAt   time.Time `json:"created_at,omitempty"`
	UpdatedAt   time.Time `json:"updated_at,omitempty"`
}

type ListOptions

type ListOptions struct {
	Language        string
	Mode            Mode
	Stage           Stage
	IncludeDisabled bool
	Source          string
	Tags            []string
}

type Match

type Match struct {
	Type          MatchType `json:"type"`
	Pattern       string    `json:"pattern"`
	CaseSensitive bool      `json:"case_sensitive,omitempty"`
	WordBoundary  bool      `json:"word_boundary,omitempty"`
}

type MatchType

type MatchType string
const (
	MatchLiteral     MatchType = "literal"
	MatchPhrase      MatchType = "phrase"
	MatchRegex       MatchType = "regex"
	MatchSpokenAlias MatchType = "spoken_alias"
)

func NormalizeMatchType

func NormalizeMatchType(matchType MatchType) MatchType

type Mode

type Mode string
const (
	ModeDictation  Mode = "dictation"
	ModeAssist     Mode = "assist"
	ModeVoiceAgent Mode = "voice_agent"
)

func NormalizeMode

func NormalizeMode(mode Mode) Mode

func WordSynonymModes added in v0.61.10

func WordSynonymModes() []Mode

WordSynonymModes is the mode set for aliases derived from a Word.

type Pack

type Pack struct {
	SchemaVersion string          `json:"schema_version"`
	ID            string          `json:"id,omitempty"`
	Name          string          `json:"name,omitempty"`
	Description   string          `json:"description,omitempty"`
	Words         []Word          `json:"words,omitempty"`
	Replacements  []Replacement   `json:"replacements,omitempty"`
	Lexicons      []Lexicon       `json:"lexicons,omitempty"`
	Rulesets      []Ruleset       `json:"rulesets,omitempty"`
	Attachments   json.RawMessage `json:"attachments,omitempty"`
	CreatedAt     time.Time       `json:"created_at,omitempty"`
}

type ReplaceOptions

type ReplaceOptions struct {
	Language string
	Source   string
}

type Replacement

type Replacement struct {
	ID         string            `json:"id"`
	Kind       Kind              `json:"kind"`
	Match      Match             `json:"match"`
	Output     ReplacementOutput `json:"output"`
	Language   string            `json:"language,omitempty"`
	Modes      []Mode            `json:"modes,omitempty"`
	Stage      Stage             `json:"stage"`
	Priority   int               `json:"priority,omitempty"`
	Tags       []string          `json:"tags,omitempty"`
	Source     string            `json:"source,omitempty"`
	Scope      *ScopeRef         `json:"scope,omitempty"`
	Enabled    bool              `json:"enabled"`
	UsageCount int               `json:"usage_count,omitempty"`
	CreatedAt  time.Time         `json:"created_at,omitempty"`
	UpdatedAt  time.Time         `json:"updated_at,omitempty"`
}

func MergeReplacements added in v0.61.9

func MergeReplacements(replacements []Replacement) []Replacement

MergeReplacements collapses exact identity duplicates. Distinct match patterns that rewrite to the same output are kept.

func SynonymReplacement added in v0.61.9

func SynonymReplacement(term, alias, language, source string) Replacement

SynonymReplacement builds the derived rewrite for a Word alias.

func WithDefaultsReplacement

func WithDefaultsReplacement(replacement Replacement) Replacement

type ReplacementOutput

type ReplacementOutput struct {
	Text     string         `json:"text,omitempty"`
	Intent   string         `json:"intent,omitempty"`
	Template string         `json:"template,omitempty"`
	Payload  map[string]any `json:"payload,omitempty"`
}

type Ruleset

type Ruleset struct {
	ID             string    `json:"id"`
	Name           string    `json:"name"`
	Description    string    `json:"description,omitempty"`
	Language       string    `json:"language,omitempty"`
	ReplacementIDs []string  `json:"replacement_ids,omitempty"`
	Tags           []string  `json:"tags,omitempty"`
	Source         string    `json:"source,omitempty"`
	Scope          *ScopeRef `json:"scope,omitempty"`
	Enabled        bool      `json:"enabled"`
	CreatedAt      time.Time `json:"created_at,omitempty"`
	UpdatedAt      time.Time `json:"updated_at,omitempty"`
}

type ScopeKind

type ScopeKind string
const (
	ScopeBuiltin   ScopeKind = "builtin"
	ScopeApp       ScopeKind = "app"
	ScopeInstall   ScopeKind = "install"
	ScopeOrg       ScopeKind = "org"
	ScopeWorkspace ScopeKind = "workspace"
	ScopeUser      ScopeKind = "user"
	ScopeSession   ScopeKind = "session"
)

func NormalizeScopeKind

func NormalizeScopeKind(kind ScopeKind) ScopeKind

type ScopeRef

type ScopeRef struct {
	Kind ScopeKind `json:"kind"`
	Key  string    `json:"key,omitempty"`
}

func DefaultDeviceScopeOrder

func DefaultDeviceScopeOrder() []ScopeRef

func DefaultServerScopeOrder

func DefaultServerScopeOrder() []ScopeRef

func NormalizeScopeRef

func NormalizeScopeRef(ref ScopeRef) ScopeRef

type Stage

type Stage string
const (
	StagePreRecognitionCleanup Stage = "pre_recognition_cleanup"
	StagePostSTT               Stage = "post_stt"
	StagePostLLM               Stage = "post_llm"
	StageOutput                Stage = "output"
)

func NormalizeStage

func NormalizeStage(stage Stage) Stage

type Word

type Word struct {
	ID         string    `json:"id"`
	Term       string    `json:"term"`
	SoundsLike []string  `json:"sounds_like,omitempty"`
	Language   string    `json:"language,omitempty"`
	Weight     float64   `json:"weight,omitempty"`
	Tags       []string  `json:"tags,omitempty"`
	Scope      *ScopeRef `json:"scope,omitempty"`
	Source     string    `json:"source,omitempty"`
	Enabled    bool      `json:"enabled"`
	UsageCount int       `json:"usage_count,omitempty"`
	CreatedAt  time.Time `json:"created_at,omitempty"`
	UpdatedAt  time.Time `json:"updated_at,omitempty"`
}

func MergeWords added in v0.61.9

func MergeWords(words []Word) []Word

MergeWords collapses duplicate terms in the same language. sounds_like and tags are unioned. Duplicate rows are a settings/migration defect, not a supported authoring state.

func WithDefaultsWord

func WithDefaultsWord(word Word) Word

Jump to

Keyboard shortcuts

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