Documentation
¶
Overview ¶
Package workflow is WorkflowStudio's model (M6): a workflow is a graph of steps (nodes) with typed inputs and outputs joined by links (edges), run once per input item (a script, or an audio clip). The package is pure: the graph, its validation, the input items, the recipe keys that tell which results a run can keep, and the built-in templates. The services run workflows (internal/services/workflow*.go); the UI draws and edits them (workflow*.go).
Imports: lang (language codes), text (script splitting), i18n (texts of diagnostics).
Index ¶
- Constants
- Variables
- func CopyName(base string, taken []string) string
- func Evaluate(m Match, want, text string) bool
- func Excerpt(s string, n int) string
- func ExportFormat(format string, t Type) string
- func FileName(template string, v NameVars) string
- func FormatsFor(t Type) []string
- func ItemFile(key string) string
- func PortLabel(port string) string
- func RunSignature(keys map[string]map[string]string, items []Item) string
- func SafeName(s string) string
- func SplitScript(s string) []string
- func StepKeys(w *Workflow, rep *Report, items []Item, salt Salt) map[string]map[string]string
- func TemplateAbout(id string) string
- func TemplateName(id string) string
- func ValidTemplate(s string) bool
- type Check
- type Clip
- type Diagnostic
- type Edge
- type Item
- type Kind
- type Match
- type NameVars
- type Node
- type Params
- type Port
- type Report
- type Run
- type RunItem
- type RunState
- type Salt
- type Script
- type Severity
- type Spec
- type Step
- type StepStatus
- type Template
- type TemplateOptions
- type Type
- type Value
- type View
- type Workflow
- func (w *Workflow) AddNode(k Kind, x, y float64) string
- func (w *Workflow) Clone() *Workflow
- func (w *Workflow) Connect(from, fromPort, to, toPort string) (string, error)
- func (w *Workflow) Duplicate(id, name string, now time.Time) *Workflow
- func (w *Workflow) Edge(id string) *Edge
- func (w *Workflow) FreeSpot() (float64, float64)
- func (w *Workflow) Incoming(id string) []Edge
- func (w *Workflow) InputNode() *Node
- func (w *Workflow) Items() []Item
- func (w *Workflow) Node(id string) *Node
- func (w *Workflow) Normalize()
- func (w *Workflow) Outgoing(id string) []Edge
- func (w *Workflow) RemoveEdge(id string)
- func (w *Workflow) RemoveNode(id string)
Constants ¶
const ( MaxNodes = 100 MaxScripts = 50 // scripts (items) a Start step takes MaxScriptChars = 20000 // runes per script MaxClips = 50 // audio clips a Source step takes MaxClipBytes = 64 << 20 // per clip MaxName = 120 // runes of a workflow's or a step's name MaxMatchText = 200 // runes a condition looks for MaxTemplate = 200 // runes of an export's file name template )
Limits.
const ( PortIn = "in" PortOut = "out" PortYes = "yes" PortNo = "no" )
Port names.
const ( MinZoom = 0.25 MaxZoom = 2.0 )
Zoom limits.
const ( LevelLoudness = "loudness" // integrated LUFS, true peak under −1 dBTP LevelPeak = "peak" // sample peak, dBFS )
Normalize modes.
const ( FormatWAV = "wav" FormatM4A = "m4a" FormatTXT = "txt" FormatSRT = "srt" FormatVTT = "vtt" FormatJSON = "json" )
Export formats.
const ( DefaultLoudness = -16.0 DefaultPeak = -2.0 MinLoudness = -30.0 MaxLoudness = -10.0 MinPeak = -24.0 MaxPeak = -1.0 MinSpeed = 0.5 MaxSpeed = 2.0 )
Defaults of the normalize step.
const ( SkipBranch = "branch" // the other branch of a condition SkipUpstream = "upstream" // a step before it failed )
Skip codes (Step.Code of skipped steps).
const ( GridX = 280 GridY = 170 )
Column spacing of templates and new steps.
const ( CodeEmpty = "graph.empty" // no steps CodeNoInput = "graph.no_input" // no Start or Source step CodeNoSteps = "graph.no_steps" // only the input step CodeExtraInput = "node.extra_input" // a second Start or Source step CodeUnconnected = "node.unconnected" // its input has no link CodeUnreachable = "node.unreachable" // no path from the input step CodeCycle = "edge.cycle" // the link closes a loop CodeType = "edge.type" // the link carries a type the input does not take (Arg: the type) CodeMergeTypes = "edge.merge_types" // links into one input carry different types CodeMerge = "edge.merge" // links into one input that are not alternative branches of a condition CodeStartEmpty = "start.empty" // no script CodeStartTooMany = "start.too_many" // more than MaxScripts items (Arg: the count) CodeStartTooLong = "start.too_long" // an item over MaxScriptChars (Arg: its number, 1-based) CodeSourceEmpty = "source.empty" // no clip CodeSourceTooMany = "source.too_many" // more than MaxClips CodeSourceLarge = "source.too_large" // a clip over MaxClipBytes (Arg: its name) CodeSourceZero = "source.empty_file" // a clip of 0 bytes (Arg: its name) CodeNoModel = "speak.no_model" // Speak/Convert without a model CodeNoTarget = "translate.no_target" CodeSameLanguage = "translate.same" CodeNoMatchText = "condition.no_text" CodeFormat = "export.format" // the format does not suit the value (Arg: the format) CodeTemplate = "export.template" // the file name template is not a name CodeNoFolder = "export.no_folder" // warning: the results stay in the app )
Diagnostic codes.
const DefaultTemplate = "{workflow}-{n}-{item}"
DefaultTemplate is an export's file name template.
const Version = 1
Version is the document version Normalize writes.
Variables ¶
var Kinds = []Kind{KindStart, KindSource, KindSpeak, KindTranscribe, KindTranslate, KindConvert, KindNormalize, KindCondition, KindExport}
Kinds lists the step kinds in the palette's order.
var Matches = []Match{MatchContains, MatchEquals, MatchPrefix, MatchSuffix}
Matches lists the comparisons in the inspector's order.
var TemplateTokens = []string{"{workflow}", "{n}", "{item}", "{step}", "{date}", "{lang}"}
TemplateTokens are the tokens a file name template may use.
var Templates = []Template{ {ID: "narration", Name: "Batch narration", About: "Scripts → speech, one file each.", /* contains filtered or unexported fields */}, {ID: "narration-normalize", Name: "Narration + normalize", About: "Scripts → speech at an even loudness.", /* contains filtered or unexported fields */}, {ID: "transcript", Name: "Audio to transcript", About: "Recordings → text files.", /* contains filtered or unexported fields */}, {ID: "change-voice", Name: "Change the voice", About: "Recordings → the same words in another voice.", /* contains filtered or unexported fields */}, {ID: "translate-narrate", Name: "Translate and narrate", About: "Recordings → transcribed, translated and spoken.", /* contains filtered or unexported fields */}, {ID: "subtitles", Name: "Transcript → subtitles", About: "Recordings → SubRip subtitles.", /* contains filtered or unexported fields */}, }
Templates are AudioSmith's templates, in the library's order.
Functions ¶
func ExportFormat ¶
ExportFormat is the format an export writes for type t: its own, or the type's first.
func FileName ¶
FileName fills a template and makes it a safe file name (without its extension): characters files cannot have become "_", at most 120 runes.
func FormatsFor ¶
FormatsFor are the export formats of a value type.
func RunSignature ¶
RunSignature sums up the keys of every step for every item.
func SplitScript ¶
SplitScript cuts a script at lines of "---" into its parts, trimmed, without empty ones.
func StepKeys ¶
StepKeys are the recipe keys of every step reachable from the input, for every item: a hash of the step's kind and settings, salt, and the keys of the steps feeding it (the input step's: the item's content). A result whose key is unchanged was made from the same recipe.
func TemplateAbout ¶
func TemplateName ¶
TemplateName and TemplateAbout translate a template's texts.
func ValidTemplate ¶
ValidTemplate reports whether a file name template makes names: not empty, no folders.
Types ¶
type Check ¶
type Check func(n *Node, in Type) []Diagnostic
Check adds the diagnostics only the app can make about a step (a model not downloaded, a saved voice deleted, no translator set up), given the type its input receives ("" when unknown).
type Clip ¶
type Clip struct {
Name string `json:"name"`
Path string `json:"path"` // absolute
Size int64 `json:"size"`
// Mod is the file's modification time when it was added: a changed
// file is a new item.
Mod time.Time `json:"mod"`
}
Clip is one audio file of a Source step.
type Diagnostic ¶
type Diagnostic struct {
Severity Severity `json:"severity"`
Code string `json:"code"`
Node string `json:"node,omitempty"`
Edge string `json:"edge,omitempty"`
Arg string `json:"arg,omitempty"`
}
Diagnostic is a finding about the workflow, a step or a link.
func (Diagnostic) Text ¶
func (d Diagnostic) Text() string
Text is the diagnostic's message in the interface's language. Codes the app adds (Check) are not known here: their Arg is the message.
type Edge ¶
type Edge struct {
ID string `json:"id"`
From string `json:"from"`
FromPort string `json:"fromPort"`
To string `json:"to"`
ToPort string `json:"toPort"`
}
Edge links an output of one step to the input of another.
type Item ¶
type Item struct {
// Key identifies the item by its content: an edited script is a new
// item, a script moved in the list is the same one.
Key string `json:"key"`
Name string `json:"name"`
Text string `json:"text,omitempty"` // a script
// Path, Size: a clip.
Path string `json:"path,omitempty"`
Size int64 `json:"size,omitempty"`
// Source is the script or clip it comes from (0-based), Part its
// part when the script holds several ("---").
Source int `json:"source"`
Part int `json:"part,omitempty"`
}
Item is one input of a run: a script, or an audio clip. The workflow runs once per item.
type Kind ¶
type Kind string
Kind is a step's kind.
const ( KindStart Kind = "start" // scripts → text KindSource Kind = "source" // audio clips → audio KindSpeak Kind = "speak" // text → audio (the render pipeline) KindTranscribe Kind = "transcribe" // audio → transcript KindTranslate Kind = "translate" // text → text, transcript → transcript KindConvert Kind = "convert" // audio → audio in another voice KindNormalize Kind = "normalize" // audio → audio at a loudness or peak level KindCondition Kind = "condition" // text → yes / no (the same text) KindExport Kind = "export" // anything → files in a folder )
type NameVars ¶
type NameVars struct {
Workflow string
N int // the item's number, 1-based
Item string
Step string
Date time.Time
Lang string
}
NameVars are the values of a file name template's tokens.
type Node ¶
type Node struct {
ID string `json:"id"`
Kind Kind `json:"kind"`
// Name is the user's name for the step ("" = the kind's).
Name string `json:"name,omitempty"`
X float64 `json:"x"`
Y float64 `json:"y"`
P Params `json:"params"`
}
Node is a step.
type Params ¶
type Params struct {
// Start.
Scripts []Script `json:"scripts,omitempty"`
// Source.
Clips []Clip `json:"clips,omitempty"`
// Speak, Convert: the TTS model (repo), the voice (a saved voice's
// id, "speaker:<id>" for the model's own, "preset:<id>"…; "" = the
// model's default), the language (BCP-47; "" = auto) and the speed.
Model string `json:"model,omitempty"`
Voice string `json:"voice,omitempty"`
Language string `json:"language,omitempty"`
Speed float64 `json:"speed,omitempty"`
// Convert: keep the source's length (the model's duration control,
// else time-stretching).
MatchDuration bool `json:"matchDuration,omitempty"`
// Transcribe: the language spoken (""= detect). Translate: From
// ("" = detect) and To.
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
// Translate: "" = the language model of Settings; "deepl", "google",
// "microsoft".
Translator string `json:"translator,omitempty"`
// Normalize.
Level string `json:"level,omitempty"` // LevelLoudness | LevelPeak
Target float64 `json:"target,omitempty"`
// Condition.
Match Match `json:"match,omitempty"`
Text string `json:"text,omitempty"`
// Export: the folder ("" = none: the results stay in the app), the
// file name template and the format ("" = the first for the type).
Folder string `json:"folder,omitempty"`
Template string `json:"template,omitempty"`
Format string `json:"format,omitempty"`
}
Params are a step's settings; each kind reads its own.
type Port ¶
type Port struct {
Name string
// Type is an output's type (TypeSame: the input's).
Type Type
// Accepts are the types an input takes.
Accepts []Type
}
Port is an input or output of a step.
type Report ¶
type Report struct {
Diags []Diagnostic
// Input is the input step's id ("" without one).
Input string
// Order lists the steps reachable from the input in an order that
// runs every step after the steps feeding it (without cycles).
Order []string
// In and Out are the types of each step's input and outputs, where
// they are known.
In, Out map[string]Type
// Items counts the input's items.
Items int
}
Report is what Validate found.
func Validate ¶
Validate checks the graph: one input step, every other step fed and reachable from it, no loops, links of types the inputs take, inputs fed by several links only from alternative branches of conditions, and each step's settings; check (optional) adds the app's own findings.
func (*Report) For ¶
func (r *Report) For(node string) []Diagnostic
For lists the diagnostics of a step (and of the links into it).
func (*Report) ForEdge ¶
func (r *Report) ForEdge(edge string) []Diagnostic
ForEdge lists the diagnostics of a link.
type Run ¶
type Run struct {
ID string `json:"id"`
// Signature sums up what the run was asked to make (RunSignature):
// a workflow whose signature differs has changed since.
Signature string `json:"signature"`
State RunState `json:"state"`
StartedAt time.Time `json:"startedAt,omitzero"`
EndedAt time.Time `json:"endedAt,omitzero"`
Items []RunItem `json:"items"`
// Steps are the step ids the run made jobs for.
Steps []string `json:"steps,omitempty"`
// Code and Err say why the run stopped before its end (a model not
// downloaded, the engine gone…).
Code string `json:"code,omitempty"`
Err string `json:"err,omitempty"`
}
Run is a workflow's last run, with every item's checkpoints.
func Plan ¶
func Plan(w *Workflow, rep *Report, items []Item, keys map[string]map[string]string, prev *Run, force bool, exists func(*Value) bool) (*Run, []string)
Plan makes the next run from the last one: an item per input item, in order, keeping each step whose result is still good (finished, same key, its file still there, and nothing before it running again) and resetting the others. force starts over. It returns the run and, in run order, the steps that have work.
type RunItem ¶
type RunItem struct {
Key string `json:"key"`
Name string `json:"name"`
// Path is a clip's file (Source).
Path string `json:"path,omitempty"`
Steps map[string]*Step `json:"steps"`
}
RunItem is an item's state in a run.
func (*RunItem) State ¶
func (it *RunItem) State() StepStatus
ItemState sums up an item: running, failed, done, or pending ("").
type Salt ¶
Salt adds what else a step's result depends on, besides its settings and inputs (the speech-to-text model of Settings, the translator…).
type Script ¶
type Script struct {
Name string `json:"name,omitempty"` // the imported file's name, or ""
Text string `json:"text"`
}
Script is one script of a Start step. Its text may hold several scripts separated by lines of "---".
type Severity ¶
type Severity int
Severity is how bad a diagnostic is: errors stop a run, warnings don't.
type Spec ¶
type Spec struct {
Kind Kind
In []Port // none (Start, Source) or one
Out []Port // none (Export), one, or yes and no (Condition)
}
Spec describes a kind of step.
type Step ¶
type Step struct {
Status StepStatus `json:"status"`
// Key is the recipe of the result (StepKeys): a result whose key
// still matches is reused by the next run.
Key string `json:"key"`
Out *Value `json:"out,omitempty"`
// Branch is the branch a condition took ("yes"/"no").
Branch string `json:"branch,omitempty"`
// Code and Err say why it failed (or was skipped: Code).
Code string `json:"code,omitempty"`
Err string `json:"err,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Seconds float64 `json:"seconds,omitempty"` // how long it took
At time.Time `json:"at,omitzero"`
}
Step is one step's state for one item: the checkpoint a run keeps.
type StepStatus ¶
type StepStatus string
StepStatus is where one step is for one item.
const ( StepPending StepStatus = "" StepRunning StepStatus = "running" StepDone StepStatus = "done" StepFailed StepStatus = "failed" // StepSkipped: the item did not reach the step (the other branch of // a condition, or a step before it failed: Code says which). StepSkipped StepStatus = "skipped" )
type Template ¶
type Template struct {
ID string
// Name and About are English; the UI translates them (i18n.T).
Name, About string
// contains filtered or unexported fields
}
Template is a ready-made workflow.
func TemplateByID ¶
TemplateByID returns a template, or false.
type TemplateOptions ¶
type TemplateOptions struct {
Model string // the TTS model of Speak and Convert steps
Voice string // their voice ("" = the model's default)
Language string // their language ("" = auto)
}
TemplateOptions fill in what a template leaves to the app.
type Value ¶
type Value struct {
Type Type `json:"type"`
// File holds the value: audio (WAV), text (UTF-8) or a transcript
// (JSON, core.Transcript); relative to the run's folder, or absolute
// for files exported elsewhere.
File string `json:"file,omitempty"`
// Text is the start of a text or transcript, to show.
Text string `json:"text,omitempty"`
Chars int `json:"chars,omitempty"`
Seconds float64 `json:"seconds,omitempty"` // audio, transcripts
Lang string `json:"lang,omitempty"`
}
Value is a step's result for an item.
type View ¶
View is a canvas's pan and zoom: the content point at the canvas's top-left corner, and the scale.
type Workflow ¶
type Workflow struct {
Version int `json:"version"`
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Nodes []Node `json:"nodes"`
Edges []Edge `json:"edges"`
// View is where the canvas looked last.
View View `json:"view"`
// Seq numbers new nodes and edges ("n7", "e12").
Seq int `json:"seq"`
}
Workflow is a saved workflow: its graph and its inputs.
func (*Workflow) AddNode ¶
AddNode adds a step of kind k at x, y with its default settings and returns its id ("" past MaxNodes).
func (*Workflow) Connect ¶
Connect links from's output port to to's input port and returns the link's id. It refuses ("" and why) links to the step itself, between ports that do not exist, and duplicates. Types are checked by Validate, so that a link can be made before the step feeding it is set up.
func (*Workflow) FreeSpot ¶
FreeSpot is where a new step goes: the first cell of a three-column grid that no step covers.
func (*Workflow) Items ¶
Items are the items of the workflow's input step, in order (nil without one). Duplicates of a content get distinct keys by occurrence.
func (*Workflow) Normalize ¶
func (w *Workflow) Normalize()
Normalize makes a document read from storage safe to use: unknown kinds, links to missing steps or ports and duplicates go; strings, numbers and lists are clamped to their limits; missing defaults are filled. It never fails.
func (*Workflow) RemoveNode ¶
RemoveNode removes a step and its links.