Documentation
¶
Overview ¶
Package core holds AudioSmith's domain: the entities every module shares (takes, voices, projects, licences, notifications, log lines), the service interfaces the UI and the Local API call, and the event bus they both subscribe to.
core is a leaf: it imports no other internal package, so every other package may import it. Implementations live elsewhere:
internal/store persistence (history.json today, SQLite next) internal/services goroutine-safe implementations of the interfaces below (thread A) internal/jobs the job scheduler the services submit work to internal/engine the Swift engine supervisor the scheduler runs work on
Rules for everything in this package:
- Service methods are safe to call from any goroutine and may block on I/O: never call them from a MyGo build pass. The UI calls them from a goroutine (or an action handler that starts one) and learns about the outcome from the Bus, applying it with Window.Update.
- Every service method takes a context.Context first; cancelling it abandons the call, not the work a job already started (use the job's Cancel for that).
- Entities are plain values. Services return copies; mutate through the service, never through a value you were handed.
- Errors wrap the sentinels in errors.go, so callers test with errors.Is.
Index ¶
- Constants
- Variables
- func CleanName(s string) string
- func NewID(t time.Time) string
- func NoSpace(err error) bool
- func NoSpaceText(msg string) bool
- func On[T Event](b *Bus, fn func(T)) (unsubscribe func())
- func SizeText(n int64) string
- func TruncateName(s string, n int) string
- type Bus
- type ConsentRecording
- type ConsentState
- type DiskFullData
- type DiskFullError
- type DraftSaved
- type DraftService
- type Event
- type Export
- type ExportChanged
- type LicenceAcceptance
- type LicenceChanged
- type LicenceRequiredError
- type LicenceService
- type LogAppended
- type LogEntry
- type LogService
- type NeedsReferenceError
- type Notification
- type NotificationPosted
- type NotificationService
- type Project
- type ProjectChanged
- type ProjectKind
- type ProjectService
- type RefHeard
- type RefQuality
- type Render
- type RenderChanged
- type RenderState
- type Scales
- type Services
- type Severity
- type Stream
- type Take
- type TakeChunk
- type TakeCreated
- type TakeDeleted
- type TakeNotice
- type TakeQuery
- type TakeRender
- type TakeRequest
- type TakeService
- type TakeUpdated
- type Transcript
- type TranscriptChanged
- type TranscriptQuery
- type TranscriptSegment
- type TranscriptSource
- type TranscriptWord
- type Voice
- type VoiceChanged
- type VoiceConsent
- type VoiceExport
- type VoiceFiles
- type VoiceImport
- type VoiceKind
- type VoiceProjectUsage
- type VoiceQuery
- type VoiceService
- type VoiceUsage
Constants ¶
const ( TakeStudio = "studio" TakeVoice = "voice" TakeConvert = "convert" TakeAPI = "api" )
Take origins (Take.Origin).
const CodeDiskFull = "disk_full"
CodeDiskFull is the error code of a job or request refused or failed for want of free disk space; its data are DiskFullData.
const CodeNeedsReference = "needs_reference"
CodeNeedsReference is the jobs.Error code of a render refused for the same reason (Data: {"model": repo}).
const MaxName = 80
MaxName is the longest name, in runes, CleanName keeps.
Variables ¶
var ( ErrNotFound = errors.New("not found") // 404 ErrExists = errors.New("already exists") // 409 ErrInvalid = errors.New("invalid request") // 400 ErrBusy = errors.New("busy") // 409 / 503 ErrCancelled = errors.New("cancelled") // 499 ErrLicenceRequired = errors.New("licence not accepted") // 451: see LicenceService ErrNotDownloaded = errors.New("model not downloaded") // 424: see hub ErrEngine = errors.New("engine unavailable") // 503: worker down or restarting ErrUnsupported = errors.New("not supported") // 501: model/engine/store lacks the capability )
Sentinel errors. Implementations wrap them (fmt.Errorf("take %s: %w", id, ErrNotFound)) so the UI and the Local API can map them to messages and HTTP statuses without parsing text.
var ErrDiskFull = errors.New("not enough free disk space")
ErrDiskFull is wrapped by the errors of a lack of free disk space (DiskFullError, a write's ENOSPC as reported by NoSpace).
Functions ¶
func CleanName ¶
CleanName is a name from anywhere (an imported voice file, the API, an MCP client, the UI) as AudioSmith keeps it: control characters, line breaks and other whitespace become one space, invisible bidi controls go, the ends are trimmed and the result has at most MaxName runes (security review #100, M2: names reach the agents' skill and prompts).
func NewID ¶
NewID returns a ULID for t: 26 characters, the first 10 encoding the millisecond and the rest 80 random bits. IDs sort by creation time as strings, are unique across goroutines and processes, and are safe in file names. Every new entity (take, voice, project, job…) uses one.
IDs are opaque everywhere else: takes made before M0 keep their "20060102-150405.000" ids, and code must not parse ids of any shape.
Within one process, IDs of one millisecond are monotonic (ULID's monotonic mode): an ID made in the same millisecond as the previous one is the previous one plus one, so IDs made one after the other sort in that order (the jobs of a graph run in the order they were made).
func NoSpace ¶
NoSpace reports whether err says the disk is full: it wraps ErrDiskFull or ENOSPC, or its text says so (an engine error).
func NoSpaceText ¶
NoSpaceText reports whether an error message says the disk is full.
func On ¶
On subscribes fn to the events of type T (any topic):
core.On(bus, func(ev core.TakeCreated) { win.Update(func() { … }) })
func TruncateName ¶
TruncateName cuts s to at most n runes, ending in "…" when cut.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus fans events out from the services, the job scheduler and the engine supervisor to the UI and the Local API.
Delivery is synchronous: Publish calls every matching handler in turn, in subscription order, on the publisher's goroutine, and returns when they have all returned. That keeps events in order and tests deterministic, at the price of one rule: handlers must not block. A MyGo window hands the event to Window.Update; an HTTP/SSE client uses Stream, which drops (and flags) events it cannot buffer. Publishers must not hold their own locks while publishing.
The zero Bus is ready to use. A nil *Bus discards events, so packages can take an optional bus.
func (*Bus) Publish ¶
Publish delivers ev to the matching subscribers. Handlers may publish and (un)subscribe; events they publish are delivered before Publish returns, depth first.
func (*Bus) Subscribe ¶
Subscribe calls fn for every event whose topic matches one of topics: an exact name, or a prefix ending in "." ("job." matches "job.updated"). No topics means every event. The returned function unsubscribes; after it returns, fn is not called again (except by a Publish already running it on another goroutine).
type ConsentRecording ¶
type ConsentRecording struct {
Audio string // the recording (absolute path), copied into the voice's directory
Statement string // the text read
Locale string
}
ConsentRecording is the consent statement as read by the user.
type ConsentState ¶
type ConsentState string
ConsentState is how far a voice's ownership is attested.
const ( ConsentNone ConsentState = "" // ConsentVerified: the user recorded the consent statement here. ConsentVerified ConsentState = "verified" // ConsentIncluded: an imported voice file carried a consent record; it // is the exporter's claim until the user records one here. ConsentIncluded ConsentState = "included-unverified" )
type DiskFullData ¶
type DiskFullData struct {
Need int64 `json:"need,omitempty"`
Free int64 `json:"free,omitempty"`
Path string `json:"path,omitempty"`
}
DiskFullData are a disk_full error's data: bytes needed and free (0 when not known, as for a write that failed).
func DiskFullDataOf ¶
func DiskFullDataOf(err error) DiskFullData
DiskFullDataOf are the data of err's DiskFullError (zero for a write that failed).
type DiskFullError ¶
type DiskFullError struct {
What string // what was refused ("dub", "render"…), may be ""
Path string
Need int64
Free int64
}
DiskFullError is a pre-check's refusal: work that would write about Need bytes under Path, with Free bytes free there (Need counts the space it keeps free).
func (*DiskFullError) Error ¶
func (e *DiskFullError) Error() string
func (*DiskFullError) Is ¶
func (e *DiskFullError) Is(target error) bool
Is makes errors.Is(err, ErrDiskFull) hold.
type DraftSaved ¶
type DraftSaved struct{ Key string }
DraftSaved: DraftService wrote a draft (for an "autosaved" hint).
func (DraftSaved) Topic ¶
func (DraftSaved) Topic() string
type DraftService ¶
type DraftService interface {
// Load decodes the draft stored under key into v (JSON) and reports
// whether there was one.
Load(ctx context.Context, key string, v any) (bool, error)
Save(key string, v any)
Delete(ctx context.Context, key string) error
Flush(ctx context.Context) error
}
DraftService autosaves editor state (scripts, forms) so it survives a restart. Save is debounced and asynchronous; Flush writes pending drafts (call it on quit).
type Event ¶
type Event interface {
Topic() string
}
Event is anything published on the Bus. Topic names are dotted, the first part naming the owner: "take.created", "job.updated", "engine.status", "settings.changed", "model.download"… Event types are plain values: subscribers may read them from any goroutine.
type Export ¶
type Export struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
// Kind is what was exported: "take", "book", "chapter", "stem",
// "cues", "voice", "transcript"…
Kind string `json:"kind"`
SourceID string `json:"sourceId,omitempty"` // the take, render, voice… exported
ProjectID string `json:"projectId,omitempty"`
Title string `json:"title"`
Path string `json:"path"` // the file written (absolute)
Format string `json:"format,omitempty"` // "wav", "m4b", "txt"…
Bytes int64 `json:"bytes,omitempty"`
}
Export records that a file was written out of the library: what, where and when, for the Projects page's Exports ("what was exported where"). Deleting the record keeps the file.
type ExportChanged ¶
ExportChanged is published when an export was recorded or its record deleted. Topic "export.changed".
func (ExportChanged) Topic ¶
func (ExportChanged) Topic() string
type LicenceAcceptance ¶
type LicenceAcceptance struct {
Licence string `json:"licence"` // catalog.Licence.ID, e.g. "cc-by-nc-4.0"
Model string `json:"model"` // repo the user accepted it for; "" = every model under it
AcceptedAt time.Time `json:"acceptedAt"`
}
LicenceAcceptance records that the user accepted a model licence that requires it (catalog.Licence.RequiresAcceptance), e.g. CC-BY-NC weights. Revoking deletes it. Checked by LicenceService for the UI and the API.
type LicenceChanged ¶
type LicenceChanged struct {
Acceptance LicenceAcceptance
Accepted bool
}
LicenceChanged: the user accepted or revoked a model licence.
func (LicenceChanged) Topic ¶
func (LicenceChanged) Topic() string
type LicenceRequiredError ¶
type LicenceRequiredError struct {
Model string
Licence string // catalog.Licence.ID
Name string // human name, e.g. "CC BY-NC 4.0"
URL string
}
LicenceRequiredError says which licence must be accepted for a model.
func (*LicenceRequiredError) Error ¶
func (e *LicenceRequiredError) Error() string
func (*LicenceRequiredError) Unwrap ¶
func (e *LicenceRequiredError) Unwrap() error
type LicenceService ¶
type LicenceService interface {
// Check returns nil when model may be used, or a *LicenceRequiredError
// (which wraps ErrLicenceRequired) naming the licence to show.
Check(ctx context.Context, model string) error
Accept(ctx context.Context, a LicenceAcceptance) error
Revoke(ctx context.Context, licence, model string) error
List(ctx context.Context) ([]LicenceAcceptance, error)
}
LicenceService is the model licence gate. The UI asks before loading or generating; the API and the job executors check again, so nothing runs a gated model without an acceptance on record.
type LogAppended ¶
type LogAppended struct{ Entry LogEntry }
LogAppended: a line for the logs panel.
func (LogAppended) Topic ¶
func (LogAppended) Topic() string
type LogEntry ¶
type LogEntry struct {
Time time.Time `json:"time"`
Level Severity `json:"level"`
Source string `json:"source"` // "app", "engine:gpu", "engine:listen", "engine:media", "hub"…
Message string `json:"message"`
JobID string `json:"jobId,omitempty"`
// Seq numbers the lines a log appended, from 1: a line's identity in
// the logs view (its selection) while lines come and go.
Seq uint64 `json:"-"`
}
LogEntry is one line of the logs panel: from the app or from an engine worker (its "log" notifications and stderr).
type LogService ¶
type LogService interface {
Append(e LogEntry)
// Tail returns up to n newest entries from source ("" = all), oldest first.
Tail(n int, source string) []LogEntry
}
LogService is the in-memory ring of log lines behind the logs panel, also written to rotated files in mygo.PathLogs. Append never blocks.
type NeedsReferenceError ¶
type NeedsReferenceError struct {
Model string // the model's name as the UI shows it, or its repo
}
NeedsReferenceError: the model only clones voices (catalog Entry.NeedsReference) and the recipe has no reference clip. It wraps ErrInvalid (the Local API answers 400).
func (*NeedsReferenceError) Error ¶
func (e *NeedsReferenceError) Error() string
func (*NeedsReferenceError) Unwrap ¶
func (e *NeedsReferenceError) Unwrap() error
type Notification ¶
type Notification struct {
ID string `json:"id"`
Severity Severity `json:"severity"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
Link string `json:"link,omitempty"` // router path / audiosmith:// deep link, e.g. "/settings/models"
JobID string `json:"jobId,omitempty"`
Time time.Time `json:"time"`
Read bool `json:"read,omitempty"`
}
Notification is a message for the notification centre (and a toast, or a system notification when the app is in the background).
type NotificationPosted ¶
type NotificationPosted struct{ Notification Notification }
NotificationPosted: something for the notification centre / a toast.
func (NotificationPosted) Topic ¶
func (NotificationPosted) Topic() string
type NotificationService ¶
type NotificationService interface {
Post(n Notification)
List(ctx context.Context) ([]Notification, error)
MarkRead(ctx context.Context, id string) error
Clear(ctx context.Context) error
}
NotificationService is the notification centre. Post never blocks.
type Project ¶
type Project struct {
ID string `json:"id"`
Kind ProjectKind `json:"kind"`
Title string `json:"title"`
Body json.RawMessage `json:"body,omitempty"` // module-defined, includes its own "version"
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Project is a saved multi-step document (M3+). Its body is owned by the module of its Kind and stored as versioned JSON; segments, renders and exports hang off it in their own tables.
type ProjectChanged ¶
ProjectChanged: a project was created, saved, renamed or deleted.
func (ProjectChanged) Topic ¶
func (ProjectChanged) Topic() string
type ProjectKind ¶
type ProjectKind string
ProjectKind is the workspace a project opens in.
const ( ProjectStory ProjectKind = "story" ProjectAudiobook ProjectKind = "audiobook" ProjectDub ProjectKind = "dub" ProjectTranscript ProjectKind = "transcript" ProjectWorkflow ProjectKind = "workflow" )
type ProjectService ¶
type ProjectService interface {
List(ctx context.Context, kind ProjectKind, search string) ([]Project, error)
Get(ctx context.Context, id string) (Project, error)
Save(ctx context.Context, p Project) (Project, error)
Delete(ctx context.Context, id string) error
}
ProjectService is the project library (M3+).
type RefHeard ¶
type RefHeard struct {
Audio, Text string
}
RefHeard is a voice's reference as the recognizer heard it: its file and the text it had.
type RefQuality ¶
type RefQuality struct {
Grade string `json:"grade,omitempty"`
Hints []string `json:"hints,omitempty"`
Cleaned []string `json:"cleaned,omitempty"`
OriginalSeconds float64 `json:"originalSeconds,omitempty"`
TextChecked bool `json:"textChecked,omitempty"`
}
RefQuality is what the reference checker (dsp/refcheck) found in a voice's reference: its grade ("good", "ok", "poor"), its hints' codes, what the automatic cleaning did ("denoised", "tidied") and how long the original was. TextChecked: the recognizer heard the reference say its RefText (thread #93: references made from a voice itself are checked once; one that did not say its text is made again or gets what it says).
type Render ¶
type Render struct {
ID string `json:"id"`
ProjectID string `json:"projectId,omitempty"` // "" for a draft never saved as a project
Kind ProjectKind `json:"kind"` // ProjectStory or ProjectAudiobook
Title string `json:"title"`
State RenderState `json:"state"`
// Audition marks a render of one chapter or line, for listening: it
// writes no book and is not listed in the library.
Audition bool `json:"audition,omitempty"`
AudioSeconds float64 `json:"audioSeconds,omitempty"`
Body json.RawMessage `json:"body,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Render is one render of a longform project (M3): the manifest it was started with and what it produced, as JSON owned by the longform service (services.RenderBody), plus the columns the library lists and filters on.
type RenderChanged ¶
RenderChanged is published when a longform render starts, changes state or makes progress (chapters done, the current chapter's fraction). Topic "render.changed".
func (RenderChanged) Topic ¶
func (RenderChanged) Topic() string
type RenderState ¶
type RenderState string
RenderState is where a longform render (Stories, Audiobook) is.
const ( RenderRunning RenderState = "running" // chapters rendering or the book assembling RenderDone RenderState = "done" // every chapter and the book are written RenderFailed RenderState = "failed" // a chapter or the assembly failed: Retry re-renders what is missing RenderStopped RenderState = "stopped" // stopped by the user: finished chapters are kept )
type Scales ¶
type Scales struct {
Pitch float64 `json:"pitch,omitempty"`
Intonation float64 `json:"intonation,omitempty"`
Volume float64 `json:"volume,omitempty"`
TempoDynamics float64 `json:"tempoDynamics,omitempty"`
PreSilence float64 `json:"preSilence,omitempty"`
PostSilence float64 `json:"postSilence,omitempty"`
}
Scales tune a VOICEVOX-compatible engine's reading; 0 = the engine's own. Pitch, Intonation and Volume are its AudioQuery's scales (TempoDynamics AivisSpeech's own); PreSilence and PostSilence are seconds of silence the render adds before and after the take.
type Services ¶
type Services struct {
Bus *Bus
Takes TakeService
Voices VoiceService
Projects ProjectService
Licences LicenceService
Notifications NotificationService
Logs LogService
Drafts DraftService
}
Services bundles the domain services for the UI and the Local API. Nil fields are services not implemented yet.
type Stream ¶
type Stream struct {
C <-chan Event
// contains filtered or unexported fields
}
Stream is a buffered subscription for consumers on their own goroutine, like an SSE or WebSocket connection. When its buffer is full new events are dropped and Lagged reports it: the consumer should then re-read the state it mirrors (e.g. GET the job) rather than trust the stream.
type Take ¶
type Take struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
// File is the audio's name inside the store's audio directory; see
// store.Takes.AudioPath. Never an absolute path.
File string `json:"file"`
// The recipe. Zero values mean "the model's default" and were not sent.
Text string `json:"text"`
Model string `json:"model"` // Hugging Face repo id (catalog.Entry.Repo)
Voice string `json:"voice,omitempty"`
Language string `json:"language,omitempty"`
Speed float64 `json:"speed,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"topP,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
RefAudio string `json:"refAudio,omitempty"` // reference clip for cloning (absolute path)
RefText string `json:"refText,omitempty"`
Seed int64 `json:"seed,omitempty"` // M1: the seed used, so the take can be reproduced
Duration float64 `json:"duration,omitempty"` // target length in seconds (OmniVoice); 0 = natural
Steps int `json:"steps,omitempty"` // diffusion steps (OmniVoice); 0 = the model's
// M1 engine parameters (protocol 2, M1); zero = the model's default.
Guidance float64 `json:"guidance,omitempty"` // classifier-free guidance scale
// Exaggeration is Chatterbox's emotion exaggeration (stories set it
// from a line's emotion intensity); 0 = the model's.
Exaggeration float64 `json:"exaggeration,omitempty"`
VoicePrompt string `json:"voicePrompt,omitempty"` // tts.encodeVoice file of the clone reference (absolute path)
// CloneRef and CloneRefText are the voice's reference for a model that
// clones it while this recipe does not (a designed voice spoken by a
// model that designs): Stories' whole dialogue clones from them. Never
// sent with the recipe.
CloneRef string `json:"cloneRef,omitempty"`
CloneRefText string `json:"cloneRefText,omitempty"`
// Scales are the reading of a VOICEVOX-compatible engine (thread
// #171): its AudioQuery scales and silences; nil = the engine's.
Scales *Scales `json:"scales,omitempty"`
// Credit is the attribution the take's audio must carry when it is
// published ("VOICEVOX:ずんだもん"; thread #171): set by the render from
// the voice's terms, shown with the take and written into exports.
Credit string `json:"credit,omitempty"`
// Relations (M1+). Empty for MVP takes.
VoiceID string `json:"voiceId,omitempty"` // Voice profile it was spoken with
ProjectID string `json:"projectId,omitempty"` // project (story, audiobook, dub) it belongs to
JobID string `json:"jobId,omitempty"` // job that produced it
// Origin is where the take was asked for: TakeStudio (also ""),
// TakeVoice (a voice page's preview or sample), TakeConvert (Tools →
// change the voice) or TakeAPI (the Local API or MCP, Client naming
// the agent when it said). The Export dialog offers per origin.
Origin string `json:"origin,omitempty"`
Client string `json:"client,omitempty"`
// Library state (M1+).
Starred bool `json:"starred,omitempty"`
// Render is how the script became audio (M1 render pipeline): output
// options, chunks and findings. nil for takes made by one engine call
// (MVP, M0).
Render *TakeRender `json:"render,omitempty"`
// The result.
SampleRate int `json:"sampleRate"`
AudioSeconds float64 `json:"audioSeconds"`
GenSeconds float64 `json:"genSeconds"`
}
Take is one generated piece of speech: its audio file and the recipe that made it, so it can be replayed, reused or regenerated.
The JSON names are the history.json format of the MVP and stay stable: the SQLite store keeps the recipe in the same shape (takes.recipe JSON) and the history.json importer decodes old files with this type.
type TakeChunk ¶
type TakeChunk struct {
Text string `json:"text"` // as the engine got it (lowered, normalised)
Start float64 `json:"start"` // seconds into the take
End float64 `json:"end"` //
Seed int64 `json:"seed,omitempty"` // the seed the engine used
Cached bool `json:"cached,omitempty"` // reused from the chunk cache
GenSeconds float64 `json:"genSeconds,omitempty"`
}
TakeChunk is one engine call of a render.
type TakeCreated ¶
type TakeCreated struct{ Take Take }
TakeCreated: a take finished and was saved.
func (TakeCreated) Topic ¶
func (TakeCreated) Topic() string
type TakeDeleted ¶
type TakeDeleted struct{ ID string }
TakeDeleted: a take and its audio are gone.
func (TakeDeleted) Topic ¶
func (TakeDeleted) Topic() string
type TakeNotice ¶
type TakeNotice struct {
Code string `json:"code"`
Severity string `json:"severity,omitempty"` // "info", "warning", "error"
Chunk int `json:"chunk,omitempty"` // 1-based; 0 = none
Start float64 `json:"start,omitempty"` // seconds
End float64 `json:"end,omitempty"`
Value float64 `json:"value,omitempty"`
Params map[string]string `json:"params,omitempty"`
}
TakeNotice is a finding about a take, by code (translated by the UI) with its parameters and, where it has one, its place in the audio.
type TakeQuery ¶
type TakeQuery struct {
Search string // full-text over the script (SQLite FTS5); "" matches all
Model string
VoiceID string
ProjectID string
Starred bool // only starred takes
Limit int // 0 = no limit
Offset int
}
TakeQuery selects takes. The zero value is every take, newest first.
type TakeRender ¶
type TakeRender struct {
// Recipe.
Bits int `json:"bits,omitempty"` // 16 (0 = 16), 24 or 32 (float)
Master string `json:"master,omitempty"` // mastering preset ("broadcast" = Even out volume); "" = none
NoNormalize bool `json:"noNormalize,omitempty"` // numbers, dates… left as written
SeedPinned bool `json:"seedPinned,omitempty"` // Seed was chosen by the user
// Result.
Channels int `json:"channels,omitempty"`
Bytes int64 `json:"bytes,omitempty"` // size of the audio file
Chunks []TakeChunk `json:"chunks,omitempty"`
Warnings []TakeNotice `json:"warnings,omitempty"` // markup lowered, chunks that may have dropped words…
// Issues are the findings of Check audio (dsp/qc); QCDone says the
// check ran (no issues then means none were found).
Issues []TakeNotice `json:"issues,omitempty"`
QCDone bool `json:"qcDone,omitempty"`
// Watermarked: the file carries the invisible watermark (AudioSeal).
Watermarked bool `json:"watermarked,omitempty"`
}
TakeRender is a take's render: the output options of its recipe (which Reuse restores) and what the render found.
type TakeRequest ¶
type TakeRequest struct {
// Recipe holds the text, model, voice and parameters; its File,
// CreatedAt and result fields are ignored and filled in by the service.
// Zero parameters are not sent, so the model's defaults apply. Its ID
// may be set (a new ULID, core.NewID) so the caller can follow the job
// by its owner, "take:<id>", before Generate returns; "" lets the
// service choose one.
Recipe Take
// Stream asks for audio chunks as they are generated (M1 streaming
// preview): the job's events then carry tts.chunk payloads.
Stream bool
// Background queues behind interactive work (batch, longform). The
// Studio and API requests leave it false.
Background bool
}
TakeRequest asks for a new take.
type TakeService ¶
type TakeService interface {
// List returns takes matching q, newest first.
List(ctx context.Context, q TakeQuery) ([]Take, error)
// Get returns one take, or an error wrapping ErrNotFound.
Get(ctx context.Context, id string) (Take, error)
// Generate checks the request (text, model downloaded, licence
// accepted), submits a "tts.synthesize" job and returns its id at
// once. The take is saved, and TakeCreated published, when the job
// succeeds; progress and failure arrive as jobs.Updated events.
Generate(ctx context.Context, req TakeRequest) (jobID string, err error)
// Saved waits until the take id that Generate queued is saved, or
// its job ended without one (at once for other ids): the job ends
// just before its take is saved.
Saved(ctx context.Context, id string) error
// Delete removes the take and its audio.
Delete(ctx context.Context, id string) error
// SetStarred stars or unstars a take.
SetStarred(ctx context.Context, id string, starred bool) error
// Add saves a take made outside Generate whose audio is already in
// AudioDir (the protocol-1 engine link until Generate runs on jobs;
// later imports), filling ID and CreatedAt when empty, and publishes
// TakeCreated. It returns the take as stored.
Add(ctx context.Context, t Take) (Take, error)
// AudioDir is the directory take audio lives in. Pure: no I/O.
AudioDir() string
// AudioPath is the absolute path of the take's audio file. Pure: no I/O.
AudioPath(t Take) string
// Export copies the take's audio to dst (streamed, not read into memory).
Export(ctx context.Context, id, dst string) error
}
TakeService is the take library and TTS generation.
type TakeUpdated ¶
type TakeUpdated struct{ Take Take }
TakeUpdated: a take's library state (star, relations) changed.
func (TakeUpdated) Topic ¶
func (TakeUpdated) Topic() string
type Transcript ¶
type Transcript struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Title string `json:"title"` // the file's name, or "" (the UI names recordings)
Source TranscriptSource `json:"source"`
// SourcePath is the file transcribed, as picked (it may move later).
SourcePath string `json:"sourcePath,omitempty"`
// Audio is the 16 kHz mono WAV kept with the transcript, a file name
// in the transcript directory; "" when none is kept.
Audio string `json:"audio,omitempty"`
Mode string `json:"mode"` // "fast" | "accurate"
Model string `json:"model"` // repo of the speech-to-text model
Aligner string `json:"aligner,omitempty"` // repo of the aligner that timed the words
Language string `json:"language,omitempty"` // BCP-47, detected or chosen
Duration float64 `json:"duration"` // seconds of audio
// Segments in time order; their text, edited or not, is the transcript.
Segments []TranscriptSegment `json:"segments"`
// Raw is the text as the model gave it, before any edit.
Raw string `json:"raw,omitempty"`
// Clean is a cleaned-up version of the text (LLM clean-up of
// fillers and self-corrections, or the dictation's polish); "" when
// there is none. The segments keep the original.
Clean string `json:"clean,omitempty"`
CleanBy string `json:"cleanBy,omitempty"` // "polish", or the LLM provider/model
// Speakers names speaker labels ("S1" → "Ana"); labels come from
// diarization (M4), nil until then.
Speakers map[string]string `json:"speakers,omitempty"`
// App is the app dictation typed into ("Notes"), for dictations.
App string `json:"app,omitempty"`
// Inserted reports whether a dictation was pasted (else it was copied).
Inserted bool `json:"inserted,omitempty"`
// Seconds is how long the model took (without loading).
Seconds float64 `json:"seconds,omitempty"`
}
Transcript is speech turned into text (M2): the Transcribe page's history and dictation's. Its audio, when kept, is a WAV in the store's transcript directory (store.Transcripts.AudioDir), named by Audio.
func (Transcript) Preferred ¶
func (t Transcript) Preferred() string
Preferred is the text to copy, export as text and reuse: the clean-up when there is one, else Text.
func (Transcript) Text ¶
func (t Transcript) Text() string
Text is the transcript as the segments read, edits included.
func (Transcript) TextPrefix ¶
func (t Transcript) TextPrefix(max int) string
TextPrefix is the start of Text, at least max bytes of it when the transcript is that long (cut after a whole segment): enough for a list row's subtitle without joining an hour of speech.
type TranscriptChanged ¶
type TranscriptChanged struct {
Transcript Transcript
Deleted bool
}
TranscriptChanged is published after a transcript is saved or deleted.
func (TranscriptChanged) Topic ¶
func (TranscriptChanged) Topic() string
type TranscriptQuery ¶
type TranscriptQuery struct {
Search string // text, title, language
Source TranscriptSource // "" = every source
Limit int // 0 = no limit
Offset int
}
TranscriptQuery filters a transcript list, newest first.
type TranscriptSegment ¶
type TranscriptSegment struct {
Start float64 `json:"start"`
End float64 `json:"end"`
Text string `json:"text"`
Speaker string `json:"speaker,omitempty"` // diarization label (M4)
Words []TranscriptWord `json:"words,omitempty"` // timed words, when known
Edited bool `json:"edited,omitempty"` // the text was changed by hand
}
TranscriptSegment is a stretch of speech: a sentence, or the model's segment when words are not timed.
type TranscriptSource ¶
type TranscriptSource string
TranscriptSource says where a transcript's audio came from.
const ( SourceFile TranscriptSource = "file" // an audio or video file SourceRecording TranscriptSource = "recording" // recorded on the Transcribe page SourceDictation TranscriptSource = "dictation" // system-wide dictation )
type TranscriptWord ¶
type TranscriptWord struct {
Text string `json:"text"`
Start float64 `json:"start"`
End float64 `json:"end"`
Prob *float64 `json:"prob,omitempty"`
}
TranscriptWord is a timed word as it reads in the text (with its punctuation); one character for Chinese and Japanese.
type Voice ¶
type Voice struct {
ID string `json:"id"`
Name string `json:"name"`
Kind VoiceKind `json:"kind"`
Model string `json:"model"` // repo the voice is for; "" = any that supports Kind
Speaker string `json:"speaker,omitempty"` // builtin speaker id
RefAudio string `json:"refAudio,omitempty"` // clone reference: file name in the voice directory
RefText string `json:"refText,omitempty"` // what the reference says ("" = let the engine listen)
RefSeconds float64 `json:"refSeconds,omitempty"`
// RefOriginal is the reference before it was cleaned automatically
// (denoised, its silences trimmed, evened out; thread #83): a file
// name, kept so the cleaning can be undone. RefCheck is what the
// reference checker found (of the reference as given).
RefOriginal string `json:"refOriginal,omitempty"`
RefCheck *RefQuality `json:"refCheck,omitempty"`
// Style is a delivery hint ("whisper", "calm and slow") sent as the
// instruction of engines that take one; tag engines get it reduced to
// their vocabulary.
Style string `json:"style,omitempty"`
// Design is the description as written (designed voices) and
// DesignAttrs the effective attributes (voicedesign.Attributes JSON):
// with Seed they are the voice's voicedesign.Recipe.
Design string `json:"design,omitempty"`
DesignAttrs json.RawMessage `json:"designAttrs,omitempty"`
Language string `json:"language,omitempty"`
Seed int64 `json:"seed,omitempty"`
Locked bool `json:"locked,omitempty"` // identity locked to LockTake + Seed
LockTake string `json:"lockTake,omitempty"` // take id the lock reproduces
Consent VoiceConsent `json:"consent,omitzero"`
Portrait string `json:"portrait,omitempty"` // file name, 256×256 PNG
// Sample is a rendered sample of the voice (file name): a designed
// voice's identity render, or the locked take's audio; SampleText is
// what it says. A locked voice is re-rendered by cloning its sample.
Sample string `json:"sample,omitempty"`
SampleText string `json:"sampleText,omitempty"`
// Prompts are cached voice prompts by model repo (tts.encodeVoice):
// file names in the voice directory.
Prompts map[string]string `json:"prompts,omitempty"`
// CreatedWith is the repo of the model that made the voice (a design
// render, the lock take), for licence notes on export.
CreatedWith string `json:"createdWith,omitempty"`
// Origin says where the voice came from: "gallery:<archetype id>",
// "asvoice:<persona id>", "ovsvoice:<id>"; "" = made here.
Origin string `json:"origin,omitempty"`
Tags []string `json:"tags,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Voice is a saved voice profile (M1): what to pass to a model to get the same voice again. Blobs (reference audio, rendered sample, consent recording, cached prompts, portrait) are files in the store's voice directory, VoiceDir/<id>/, referenced by name.
type VoiceChanged ¶
VoiceChanged: a voice profile was created, edited or deleted.
func (VoiceChanged) Topic ¶
func (VoiceChanged) Topic() string
type VoiceConsent ¶
type VoiceConsent struct {
State ConsentState `json:"state,omitempty"`
Recording string `json:"recording,omitempty"`
Statement string `json:"statement,omitempty"`
Locale string `json:"locale,omitempty"` // language the statement was read in
At time.Time `json:"at,omitzero"`
}
VoiceConsent is a voice's ownership attestation: the statement read, its recording (a file name in the voice directory) and when.
func (*VoiceConsent) UnmarshalJSON ¶
func (c *VoiceConsent) UnmarshalJSON(b []byte) error
UnmarshalJSON also reads M0's "consent": true|false.
type VoiceExport ¶
type VoiceExport struct {
// IncludeReference adds the clone reference; off shares only the preview.
IncludeReference bool
Licence string // SPDX id; "" = personal use
// Preview is a WAV to ship as the preview; "" picks the voice's sample,
// or its reference (WAV): never its takes (private).
Preview string
App string // creator software, "AudioSmith"
AppVersion string
}
VoiceExport configures Export.
type VoiceFiles ¶
type VoiceFiles struct {
Reference string // audio file (absolute path): the new clone reference
// Original is the new reference before it was cleaned (Reference is
// the cleaned one); RemoveReference removes the reference (a designed
// voice whose design changed).
Original string
RemoveReference bool
Sample string // audio file: a rendered sample (designed voices)
// Portrait is the new portrait, a PNG (already cropped to 256×256);
// RemovePortrait deletes the current one.
Portrait []byte
RemovePortrait bool
// Prompt is a cached voice prompt for model PromptModel (tts.encodeVoice).
Prompt string
PromptModel string
}
VoiceFiles are files to copy into a voice's directory. Empty fields leave the voice's files as they are.
type VoiceImport ¶
type VoiceImport struct {
Voice Voice
Format string // "asvoice" or "ovsvoice"
Warnings []string // English, technical
}
VoiceImport is an imported voice and what the importer could not carry over.
type VoiceProjectUsage ¶
type VoiceProjectUsage struct {
ID string
Title string
Kind ProjectKind
Segments int
}
VoiceProjectUsage is one project whose segments use a voice.
type VoiceQuery ¶
type VoiceQuery struct {
Search string // name, style, transcript, description, tags
Kind VoiceKind
Model string
Origin string // exact Voice.Origin
}
VoiceQuery selects voices. The zero value is every voice, by name.
type VoiceService ¶
type VoiceService interface {
List(ctx context.Context, q VoiceQuery) ([]Voice, error)
Get(ctx context.Context, id string) (Voice, error)
// Save creates (empty ID) or updates a profile and returns it as stored.
// Blob fields (RefAudio, Sample, Portrait, Consent.Recording, Prompts)
// keep their stored values on update: files change through SaveFiles,
// Lock, SetConsent.
Save(ctx context.Context, v Voice) (Voice, error)
// SaveFiles is Save that first copies files into the voice's directory.
// A new reference clears the lock and a verified consent (the new clip
// may be another speaker), except a designed voice's (rendered from
// the voice itself).
SaveFiles(ctx context.Context, v Voice, f VoiceFiles) (Voice, error)
// Delete deletes a profile and its files. Trash deletes it too, but
// its files wait in the library's trash until Purge (or the next
// start), so that Restore can undo it.
Delete(ctx context.Context, id string) error
Trash(ctx context.Context, id string) error
Restore(ctx context.Context, id string) (Voice, error)
Purge(id string)
// PurgeTrash empties the trash (at start).
PurgeTrash(ctx context.Context)
// Import reads a .asvoice (or VoiceStudio .ovsvoice) package into a new
// profile. Imported consent is ConsentIncluded at most.
Import(ctx context.Context, path string) (VoiceImport, error)
// Export writes a .asvoice package.
Export(ctx context.Context, id, dst string, o VoiceExport) error
// HasPreview reports whether Export finds a preview by itself (the
// voice's sample or reference is a WAV): asked before a save dialog.
HasPreview(v Voice) bool
// Usage says where the voice was used: takes, project segments.
Usage(ctx context.Context, id string) (VoiceUsage, error)
// Lock ties the voice's identity to one of its takes: its audio becomes
// the voice's sample, its seed the voice's seed.
Lock(ctx context.Context, id, takeID string) (Voice, error)
Unlock(ctx context.Context, id string) (Voice, error)
// CleanReference makes a cleaned copy of the voice's reference (the
// file at path, seconds long) its reference, keeping the current one
// as RefOriginal; RevertReference undoes it. Neither touches the lock
// or the consent: the speaker is the same.
CleanReference(ctx context.Context, id, path string, seconds float64, q *RefQuality) (Voice, error)
RevertReference(ctx context.Context, id string) (Voice, error)
// ReferenceTextChecked records that the recognizer heard the reference
// was say text: text becomes RefText and RefCheck says it is checked
// (ErrInvalid when the reference is no longer was).
ReferenceTextChecked(ctx context.Context, id string, was RefHeard, text string) (Voice, error)
// SetConsent stores a recording of the user reading the consent
// statement: the voice becomes Verified. RevokeConsent removes it.
SetConsent(ctx context.Context, id string, c ConsentRecording) (Voice, error)
RevokeConsent(ctx context.Context, id string) (Voice, error)
// FilePath is the absolute path of one of the voice's files ("" for
// an empty name). Pure: no I/O.
FilePath(v Voice, name string) string
}
VoiceService is the voice library (M1).
type VoiceUsage ¶
type VoiceUsage struct {
Takes int
LatestTake string // id of the newest take
Segments int
Projects []VoiceProjectUsage
}
VoiceUsage is where a voice was used.