speech

package
v0.0.0-...-94fff03 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

+game:group:name=speech

Package speech lets entities speak with the voices of the github.com/weakpixel/voice library: the text of a gfx.Label types out in step with musical gibberish on the mixer's dialogue bus.

Assets: Language (*.lang.json), Voice (*.voice.json, or a starter voice by name such as "chirpy"), Sample (a 16-bit PCM WAV that a voice's instrument plays) and Dialogue (*.dialogue.json). RegisterLoaders registers them on an asset server; SetLibraryLoaders maps the library kinds to them.

Speaking: Install adds speech to a game.Engine and returns its Speech. An entity with a Speaker component speaks with Speech.Say; with a gfx.Label, its text shows what was said so far. What happens to a line arrives as Event values through system.EventsOf. See doc/guide/engine/speech.md.

It is the only package of the engine that imports the voice library, and it makes no Ebiten calls. Package game never imports speech: speech is opt-in.

Index

Constants

View Source
const (
	// AssetKindVoice is a [Voice]: a *.voice.json file or a starter voice
	// by name ("chirpy").
	AssetKindVoice = "voice"
	// AssetKindDialogue is a [Dialogue] (a *.dialogue.json file).
	AssetKindDialogue = "dialogue"
)

Asset kinds of this package: the names a component field carries in its +game:asset:kind=... marker.

View Source
const (
	LanguageSuffix = ".lang.json"
	VoiceSuffix    = ".voice.json"
	DialogueSuffix = ".dialogue.json"
)

File suffixes of the speech assets.

View Source
const DefaultVoices = 24

DefaultVoices is the polyphony of the synthesizer when Config.Voices is 0: enough for a few speakers at once, cheap enough for a browser (the synth renders on the audio pull, which in js/wasm shares the main thread).

Variables

View Source
var (
	CID_DialogueBox  = ecs.RegisterComp[DialogueBox]()
	CID_Speaker      = ecs.RegisterComp[Speaker]()
	CID_GfxLabel     = ecs.RegisterComp[gfx.Label]()
	CID_GfxTransform = ecs.RegisterComp[gfx.Transform]()
)

Functions

func IsStarter

func IsStarter(name string) bool

IsStarter reports whether name is a starter voice ("chirpy"): a voice key or a dialogue speaker's voice reference that loads voice.Preset instead of a file.

func LanguageKey

func LanguageKey(name string) string

LanguageKey returns the key of the language a voice file names in its language field: "" for the default language, a path relative to the voice for a name ending in .lang.json, otherwise <name>.lang.json next to the voice. The result is relative to the voice file, as asset.Dep takes it.

func LoadDialogue

func LoadDialogue(sc *asset.Scope, key string) gfx.DialogueHandle

LoadDialogue returns the handle for a dialogue key ("talk/village.dialogue.json") and adds a hold for sc. It never blocks and panics like asset.Load.

func LoadDialogueSync

func LoadDialogueSync(sc *asset.Scope, key string) (gfx.DialogueHandle, error)

LoadDialogueSync is LoadDialogue followed by loading until the dialogue is ready or failed, like asset.LoadSync. It blocks.

func LoadVoice

func LoadVoice(sc *asset.Scope, key string) gfx.VoiceHandle

LoadVoice returns the handle for a voice key ("chars/bard.voice.json", or a starter name such as "chirpy") and adds a hold for sc. It never blocks and panics like asset.Load.

func LoadVoiceSync

func LoadVoiceSync(sc *asset.Scope, key string) (gfx.VoiceHandle, error)

LoadVoiceSync is LoadVoice followed by loading until the voice is ready or failed, like asset.LoadSync. It blocks: use it for boot screens, tests and tools.

func RegisterLoaders

func RegisterLoaders(srv *asset.Server)

RegisterLoaders registers Language, Sample, Voice and Dialogue and their loaders on srv. The assets do not depend on the stream's sample rate: samples keep their file's rate and the synthesizer resamples them per note.

It makes no audio calls and may run on any goroutine that owns srv. It panics like asset.Register if a type is already registered.

func SetLibraryLoaders

func SetLibraryLoaders(lib *library.Library)

SetLibraryLoaders maps the library kinds of the speech files (library.KindVoice, library.KindDialogue, library.KindLanguage) to their load functions, so a library group loads the voices, dialogues and languages in its folder. RegisterLoaders must have run on the server the library is attached to.

game cannot set these itself (speech is installed on an engine, so game never imports it); a game that uses a library calls this once, or lets speech.Install do it.

Types

type Box

type Box struct {
	// Where the text is.
	// +game:component
	Transform *gfx.Transform
	// The line types into it.
	// +game:component
	Label *gfx.Label
	// The dialogue.
	// +game:component
	DialogueBox *DialogueBox
}

Box is a dialogue box: a Label placed by a Transform that plays a dialogue file. The Label is drawn in screen space, so Transform.Pos is in logical pixels. Put a gfx:Panel behind it for a frame, and point DialogueBox.Name at a gfx:Text for the speaker's name.

+game:object

type BoxView

type BoxView struct {
	// contains filtered or unexported fields
}

BoxView is a thin handle over Box entities, bound to one World. It holds no entity state of its own.

func NewBoxView

func NewBoxView(world *ecs.World) BoxView

NewBoxView returns a BoxView bound to world. Create it once and keep it; copies share the same underlying state.

func (BoxView) Each

func (v BoxView) Each() iter.Seq2[ecs.Entity, Box]

Each yields every entity that has all required components of Box, regardless of how it was created. Optional fields are always resolved, so Each yields the same Box that Get would return for the same entity.

Panics with "ecs: not bound to a world" if BoxView is the zero value.

func (BoxView) Get

func (v BoxView) Get(e ecs.Entity) Box

Get returns a Box whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if BoxView is the zero value.

func (BoxView) Has

func (v BoxView) Has(e ecs.Entity) bool

Has reports whether e has every required component of Box, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if BoxView is the zero value.

func (BoxView) NewEntity

func (v BoxView) NewEntity(obj Box) ecs.Entity

NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.

Panics with "ecs: not bound to a world" if BoxView is the zero value.

func (BoxView) Remove

func (v BoxView) Remove(e ecs.Entity)

Remove removes all of Box's components (required and optional) that e has, in one archetype move. Other components stay.

Panics with "ecs: not bound to a world" if BoxView is the zero value.

func (BoxView) Set

func (v BoxView) Set(e ecs.Entity, obj Box)

Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of Box are left untouched.

Panics with "ecs: not bound to a world" if BoxView is the zero value.

type Config

type Config struct {
	// Bus is the mixer bus the voices play on. The zero value (BusSFX)
	// means sound.BusVoice: speech never plays on the effects bus.
	Bus sound.Bus
	// Volume is the stream's own volume factor; 0 means 1.
	Volume float32
	// Voices is the polyphony of the synthesizer; 0 means DefaultVoices.
	Voices int
	// Buffer is the player buffer; 0 means sound.DefaultStreamBuffer.
	Buffer time.Duration
	// Reverb is the synthesizer's reverb; nil means synth.DefaultReverb.
	Reverb *synth.Reverb
	// Sink, when set, receives the notes instead of the built-in
	// synthesizer, and no stream is started (a recording sink in tests,
	// another synthesizer). If it has the synth.Stream method SetVoice, it
	// gets every speaker's instruments before its notes.
	Sink voice.Sink
	// OnError receives what goes wrong while speaking (a voice whose
	// instruments the synthesizer rejects, a stream that cannot start);
	// nil logs it. Asset errors go to the asset server's OnError.
	OnError func(error)
}

Config configures what Install adds. The zero value works: the built-in synthesizer with 24 voices on sound.BusVoice, a 50 ms buffer and the library's default reverb; errors are logged.

type Dialogue

type Dialogue struct {
	// Script is the dialogue. It is shared: never modify it.
	Script *dialogue.Script
	// Voices holds the voice of every speaker, keyed by the speaker's voice
	// reference ([dialogue.Speaker].Voice), like [dialogue.LoadVoices].
	// Speakers that share a reference share the value.
	Voices map[string]*Voice
}

Dialogue is a loaded *.dialogue.json file with the voice of every speaker.

The placeholder has a nil Script: a failed dialogue plays nothing.

func (*Dialogue) PlayerVoices

func (d *Dialogue) PlayerVoices() map[string]*voice.Voice

PlayerVoices returns the voices keyed by reference, in the form dialogue.NewPlayer takes. It allocates a new map.

type DialogueBox

type DialogueBox struct {
	// Dialogue is the *.dialogue.json file to play. The zero, a missing or
	// a failed dialogue plays nothing (Play sends DialogueFinished at once).
	//
	// +game:asset:kind=dialogue
	Dialogue gfx.DialogueHandle `json:"-"`
	// Name, when set, is an entity with a gfx.Label that shows the name of
	// the current line's speaker. In a GOD level it is the id of an object
	// of the same document.
	Name ecs.Entity
	// AutoStart plays the dialogue from its first line once the asset is
	// ready, without a call of Play: a box placed in a level speaks when
	// the level runs.
	AutoStart bool
	// AutoAdvance goes on after every line by itself after the line's hold
	// time, whatever the dialogue file says (hands-free play).
	AutoAdvance bool
}

DialogueBox plays a *.dialogue.json file on its entity: the current line types out into the entity's gfx.Label in its speaker's voice, and the speaker's display name goes into the Label of Name. Speech.Play starts it, Speech.Next is the game's "advance" input. The state of the running dialogue lives in the Speech, not here.

+game:component

type DialogueStore

type DialogueStore struct {
	// contains filtered or unexported fields
}

DialogueStore resolves gfx.DialogueHandle values. Get one with DialogueStoreOf. It is a small value; copy it freely.

func DialogueStoreOf

func DialogueStoreOf(srv *asset.Server) DialogueStore

DialogueStoreOf returns the dialogue store of srv. It panics like asset.StoreOf if RegisterLoaders has not run on srv.

func (DialogueStore) Err

Err returns why the dialogue failed to load, or nil.

func (DialogueStore) Generic

func (s DialogueStore) Generic() *asset.Store[Dialogue]

Generic returns the underlying generic store.

func (DialogueStore) Get

Get returns the dialogue, or the placeholder (no script); see asset.Store.Get for the pointer validity rule. It does not allocate.

func (DialogueStore) Key

Key returns the key h was loaded from, or the zero Key for a zero or stale handle.

func (DialogueStore) Lookup

Lookup is Get plus the load state; see asset.Store.Lookup.

func (DialogueStore) Ready

func (s DialogueStore) Ready(h gfx.DialogueHandle) bool

Ready reports whether h refers to a loaded dialogue.

type Event

type Event struct {
	// Entity is the speaking entity or the dialogue box. It may no longer
	// be alive (a line that ended because the entity was deleted).
	Entity ecs.Entity
	// Kind is what happened.
	Kind EventKind
	// Line numbers the entity's lines from 1, one per Say, so a Stopped
	// event of the line a new Say replaced can be told from the new one's
	// Started.
	// For the dialogue kinds it is the index of the line in the dialogue
	// file, from 0.
	Line uint64
}

Event is something that happened to a line. Read them with a system.EventReader on system.EventsOf[speech.Event]; the speech system sends them in StagePost, so a reader in StageSimulate sees them the tick after.

type EventKind

type EventKind uint8

EventKind is what happened to a line of Speech.Say or in a dialogue box.

const (
	// Started: Say began a line (once its voice was loaded).
	Started EventKind = iota
	// Completed: the line played to its end, all text shown.
	Completed
	// Skipped: Skip ended the line early, all text shown.
	Skipped
	// Stopped: Stop, a new Say, Close, the entity's deletion or the loss
	// of its Speaker ended the line where it was.
	Stopped
	// LineStarted: a dialogue box's line passed its delay and began to
	// speak. Line is the line's index in the dialogue file.
	LineStarted
	// LineDone: a dialogue box's line completed or was skipped by Next;
	// all its text is shown. Line is its index.
	LineDone
	// DialogueFinished: a dialogue box's last line gave way, or Play found
	// no dialogue to play (zero, missing or failed). Line is the index of
	// the last line played. StopDialogue and the box's deletion send none.
	DialogueFinished
)

Event kinds.

func (EventKind) String

func (k EventKind) String() string

String returns the kind in words: "started", "completed", "skipped", "stopped", "line started", "line done" or "dialogue finished".

type Language

type Language struct {
	// L is the language. It is immutable and shared.
	L *voice.Language
}

Language is a loaded *.lang.json file: how text becomes phonemes.

The placeholder is the library's default language.

type LanguageHandle

type LanguageHandle struct{ asset.Ref }

LanguageHandle refers to a Language. Components do not hold languages (a voice names its own), so the handle lives here, not in gfx.

func LoadLanguage

func LoadLanguage(sc *asset.Scope, key string) LanguageHandle

LoadLanguage returns the handle for a language key ("lang/elvish.lang.json") and adds a hold for sc. A voice loads its own language; load one directly to parse text with it. It never blocks and panics like asset.Load.

type LanguageStore

type LanguageStore struct {
	// contains filtered or unexported fields
}

LanguageStore resolves LanguageHandle values. Get one with LanguageStoreOf. It is a small value; copy it freely.

func LanguageStoreOf

func LanguageStoreOf(srv *asset.Server) LanguageStore

LanguageStoreOf returns the language store of srv. It panics like asset.StoreOf if RegisterLoaders has not run on srv.

func (LanguageStore) Err

Err returns why the language failed to load, or nil.

func (LanguageStore) Generic

func (s LanguageStore) Generic() *asset.Store[Language]

Generic returns the underlying generic store.

func (LanguageStore) Get

Get returns the language, or the placeholder (the default language). It does not allocate.

type Note

type Note struct {
	On, Off time.Duration
	// Pitch is in semitones, MIDI numbering (60 is middle C).
	Pitch    float32
	Velocity float32 // 0 to 1
	Kind     NoteKind
}

Note is one note of a line, for showing it (a piano roll). Times are in line time, from the start of the line, before the line's Speed.

type NoteKind

type NoteKind uint8

NoteKind is what plays a Note: one of a voice's instruments.

const (
	NoteVowel      NoteKind = iota // a vowel
	NoteSonorant                   // m, n, l, r, ...
	NoteFricative                  // s, f, h, ...
	NotePlosive                    // p, t, k, ...
	NoteMotif                      // the quiet melody under a line
	NotePercussion                 // a percussion sound of a rhythm voice
)

The kinds of a note.

func (NoteKind) String

func (k NoteKind) String() string

String returns "vowel", "sonorant", "fricative", "plosive", "motif" or "percussion".

type Sample

type Sample struct {
	// S is the recording. It is shared by every voice that uses the file:
	// never modify it.
	S *synth.Sample
}

Sample is a mono recording a voice's instrument plays, loaded from a 16-bit PCM WAV file (mixed to mono at the file's own rate; the synthesizer resamples per note). Root and loop points come from the voice file.

It has no handle of its own: it loads only as a dependency of a Voice. The placeholder has a nil S.

type SayOptions

type SayOptions struct {
	// Speed scales the line on top of Speaker.Speed: 2 is twice as fast.
	// 0 means 1.
	Speed float32
	// Instant shows all text at once and plays the motif only.
	Instant bool
	// Voice, when not zero, speaks with this voice instead of the entity's
	// Speaker.Voice. It lets an entity without a Speaker speak.
	Voice gfx.VoiceHandle
}

SayOptions tune one line of Speech.Say.

type Speaker

type Speaker struct {
	// Voice is a *.voice.json file or a starter voice by name ("chirpy").
	// The zero handle, a missing or a failed voice speaks silently, at the
	// default speed. A voice that is still loading delays the line until it
	// is ready.
	//
	// +game:asset:kind=voice
	Voice gfx.VoiceHandle `json:"-"`
	// Speed scales how fast the voice speaks: 2 is twice as fast. Zero
	// means 1; the editor starts a new speaker at 1.
	//
	// +game:default=1
	Speed float32
	// Pan moves the voice in the stereo field, -1 (left) to 1 (right). It is
	// added to the pan of every note.
	Pan float32
}

Speaker gives an entity a voice. Speech.Say speaks a line with it; if the entity has a gfx.Label, the system sets Label.Text to the part of the line said so far while it speaks. The state of the running line lives in the Speech, not here, so the component is plain authored data.

+game:component

type Speech

type Speech struct {
	// contains filtered or unexported fields
}

Speech is the controller of speaking entities: Install creates it and sets it as a World resource. Use it from the game goroutine only (systems and Start hooks), like the World.

Every note it starts ends: Skip, Stop, a new Say, Pause, a frozen root scene, the deletion of the entity, the loss of its Speaker and Close release the line's notes; Next, a new Play, StopDialogue, PauseDialogue, the freeze, the deletion of the box, the loss of its DialogueBox and Close release a dialogue's.

func Install

func Install(e *game.Engine, cfg Config) *Speech

Install adds speech to e and returns its controller, which is also set as a World resource (ecs.GetResource[speech.Speech]). It registers the asset loaders (RegisterLoaders; do not call it as well) and the library's loaders of the kinds when e has a library, starts the synthesizer at e's sample rate on the mixer, and adds the speech system to StagePost of the root scene and a check to the audio stage. Call it once, after game.New and before the first Update.

Under game.Config.NoAudio (servers, tests, the level editor) nothing reads the synthesizer: text, reveal and events behave the same, silently, and the notes are dropped every tick. A pause scene above the root or a Tool's pause holds every line and releases its notes; the lines continue when the root runs again.

Voices in the library's global/ package are not loaded at boot (the boot starts in game.New, before Install); they load when first used.

func (*Speech) Close

func (s *Speech) Close()

Close stops every line, releases every owner and stops the stream. Later calls of Say do nothing, and the system does nothing. Closing twice is harmless.

func (*Speech) Line

func (s *Speech) Line(e ecs.Entity) (dialogue.Line, dialogue.Speaker, bool)

Line returns box e's current line and its speaker, and whether the box is playing one (false before Play, while the dialogue loads and once it finished or stopped). Line.Text is the whole line; the box's Label shows the part said so far.

func (*Speech) LineNotes

func (s *Speech) LineNotes(e ecs.Entity, dst []Note) []Note

LineNotes appends the notes of e's line (the running one, or the last one that ended) to dst and returns it, sorted by On. Without a line, or while it waits for its voice, it returns dst unchanged. It allocates only when dst grows.

func (*Speech) LinePosition

func (s *Speech) LinePosition(e ecs.Entity) (at, length time.Duration)

LinePosition returns how far e's line has played and how long it is, both in line time like Note: at stays put while the line is paused or held and reaches length when the line completes (Skip and Stop leave it where they ended the line). Both are 0 without a line and while it waits for its voice.

func (*Speech) Next

func (s *Speech) Next(e ecs.Entity)

Next is the game's "advance" input for box e: while a line types out it shows the rest at once (the line is done, its notes are released); while a finished line holds it goes on to the next line, or finishes the dialogue after the last. During a line's delay, while the dialogue loads, after the end and without a box it does nothing.

func (*Speech) Pause

func (s *Speech) Pause(e ecs.Entity)

Pause holds e's line: its time stops and its sounding notes are released. Resume continues with the next notes. A waiting line starts paused.

func (*Speech) PauseDialogue

func (s *Speech) PauseDialogue(e ecs.Entity)

PauseDialogue holds box e's dialogue: its time stops (the line, its delay or its hold) and its sounding notes are released. ResumeDialogue continues with the next notes. A dialogue that is still loading starts paused. Next still works while paused: it shows the rest of the line or goes on to the next one, which then waits for ResumeDialogue.

func (*Speech) Play

func (s *Speech) Play(e ecs.Entity, start int)

Play plays the DialogueBox of entity e from line start (0 is the first), replacing what the box played (its notes are released, no event). It starts at once, or in the speech system's next tick once the dialogue has loaded. The box's gfx.Label shows the current line as it types out, and the Label of DialogueBox.Name the speaker's name; both are set to "" when the dialogue finishes or stops. A zero, missing or failed dialogue, or a start outside the dialogue's lines (reported to Config.OnError), plays nothing and sends DialogueFinished. Play after Close does nothing. Play allocates; the ticks of a running dialogue do not.

Panics with "speech: Play on a dead entity" and with "speech: Play on an entity without a DialogueBox".

func (*Speech) Playing

func (s *Speech) Playing(e ecs.Entity) bool

Playing reports whether box e has a dialogue that has not finished: speaking, holding, in a delay, paused or waiting for its file.

func (*Speech) Resume

func (s *Speech) Resume(e ecs.Entity)

Resume continues e's paused line.

func (*Speech) ResumeDialogue

func (s *Speech) ResumeDialogue(e ecs.Entity)

ResumeDialogue continues box e's paused dialogue.

func (*Speech) Revealed

func (s *Speech) Revealed(e ecs.Entity) int

Revealed returns how many bytes of e's current line are shown: text[:n] is always whole characters. It is 0 without a line and while the line waits for its voice.

func (*Speech) Run

func (s *Speech) Run(ctx *system.Context)

Run is the speech system (StagePost of the root): it starts the dialogue boxes with AutoStart and those whose dialogue finished loading, advances them and writes their Labels, starts lines whose voice finished loading, advances every line by the tick, writes the reveal into Labels, sends the events and ends the lines of deleted entities and of entities that lost their Speaker. A tick of running lines allocates nothing.

func (*Speech) Say

func (s *Speech) Say(e ecs.Entity, text string, opts SayOptions)

Say speaks text on entity e with its Speaker's voice (or opts.Voice), replacing the line e is saying (that line gets a Stopped event). The line starts at once, or in the speech system's next tick once its voice has loaded; then it sends Started. If e has a gfx.Label, the system sets its Text to the part said so far every tick until the line ends. Text is plain: inline voice markup works in dialogues only. Say after Close does nothing. Say allocates (it composes the line); the ticks of a running line do not.

Panics with "speech: Say on a dead entity" and with "speech: Say on an entity without a Speaker and without SayOptions.Voice".

func (*Speech) Skip

func (s *Speech) Skip(e ecs.Entity)

Skip ends e's line at once: all text is shown, its notes are released and it sends Skipped. A line still waiting for its voice starts silently and is skipped. Without a line it does nothing.

func (*Speech) Speaking

func (s *Speech) Speaking(e ecs.Entity) bool

Speaking reports whether e has a line that has not ended: playing, paused or waiting for its voice.

func (*Speech) Step

func (s *Speech) Step(dt time.Duration)

Step advances speech by dt, like one tick of the speech system (Speech.Run). A tool that runs the engine paused (game.TickPause skips StagePost, so the system does not run) calls it once per tick so its lines and dialogue boxes play; a game never needs it, and calling both in one tick advances twice. Step after Close does nothing.

func (*Speech) Stop

func (s *Speech) Stop(e ecs.Entity)

Stop ends e's line where it is (the shown text stays), releases its notes and sends Stopped. Without a line it does nothing.

func (*Speech) StopDialogue

func (s *Speech) StopDialogue(e ecs.Entity)

StopDialogue ends box e's dialogue where it is: its notes are released, its Labels are cleared at the next tick and no event is sent. Play starts it again. Without a box it does nothing.

func (*Speech) Stream

func (s *Speech) Stream() *sound.Stream

Stream returns the stream the built-in synthesizer plays on (its volume and pan apply on top of the bus), or nil when Config.Sink is set.

type Talker

type Talker struct {
	// Where the text is.
	// +game:component
	Transform *gfx.Transform
	// The text the line types into, and how it is drawn.
	// +game:component
	Label *gfx.Label
	// The voice.
	// +game:component
	Speaker *Speaker
}

Talker is a speaking text: a Label placed by a Transform, with a voice. The Label is drawn in screen space, so Transform.Pos is in logical pixels.

+game:object

type TalkerView

type TalkerView struct {
	// contains filtered or unexported fields
}

TalkerView is a thin handle over Talker entities, bound to one World. It holds no entity state of its own.

func NewTalkerView

func NewTalkerView(world *ecs.World) TalkerView

NewTalkerView returns a TalkerView bound to world. Create it once and keep it; copies share the same underlying state.

func (TalkerView) Each

func (v TalkerView) Each() iter.Seq2[ecs.Entity, Talker]

Each yields every entity that has all required components of Talker, regardless of how it was created. Optional fields are always resolved, so Each yields the same Talker that Get would return for the same entity.

Panics with "ecs: not bound to a world" if TalkerView is the zero value.

func (TalkerView) Get

func (v TalkerView) Get(e ecs.Entity) Talker

Get returns a Talker whose component fields point to e's live components. Optional fields are resolved (nil when absent). Panics if e lacks a required component, and with "ecs: not bound to a world" if TalkerView is the zero value.

func (TalkerView) Has

func (v TalkerView) Has(e ecs.Entity) bool

Has reports whether e has every required component of Talker, i.e. whether Get would not panic. Panics if e is stale, and with "ecs: not bound to a world" if TalkerView is the zero value.

func (TalkerView) NewEntity

func (v TalkerView) NewEntity(obj Talker) ecs.Entity

NewEntity creates an entity from obj. A nil required pointer component is stored as the zero value. An optional component is added only when non-nil.

Panics with "ecs: not bound to a world" if TalkerView is the zero value.

func (TalkerView) Remove

func (v TalkerView) Remove(e ecs.Entity)

Remove removes all of Talker's components (required and optional) that e has, in one archetype move. Other components stay.

Panics with "ecs: not bound to a world" if TalkerView is the zero value.

func (TalkerView) Set

func (v TalkerView) Set(e ecs.Entity, obj Talker)

Set writes obj to e: required components are added or replaced (a nil required pointer overwrites the component with its zero value); optional components are added or replaced when non-nil and removed when nil. Components of e that are not part of Talker are left untouched.

Panics with "ecs: not bound to a world" if TalkerView is the zero value.

type Voice

type Voice struct {
	// V is the voice. It is shared by every speaker that uses the asset:
	// never modify it; copy it to change a field.
	V *voice.Voice
	// Language is the voice's language: the file its language field names,
	// or the default language.
	Language *voice.Language
	// Silent is set on the placeholder.
	Silent bool
	// contains filtered or unexported fields
}

Voice is how one character speaks: a loaded *.voice.json file with its language and samples resolved, or a starter voice (voice.Preset) when the key is a starter name such as "chirpy".

The placeholder (a missing or failed voice) is the "soft" starter with Silent set: it reveals text at the default speed and plays no notes.

func (*Voice) Sample

func (v *Voice) Sample(name string) (*synth.Sample, error)

Sample returns the recording an instrument names in the voice file ("hum.wav"), so (*Voice).Sample can be passed as a synth.SampleLoader. It returns an error for a name the file does not use.

type VoiceStore

type VoiceStore struct {
	// contains filtered or unexported fields
}

VoiceStore resolves gfx.VoiceHandle values. Get one with VoiceStoreOf. It is a small value; copy it freely.

func VoiceStoreOf

func VoiceStoreOf(srv *asset.Server) VoiceStore

VoiceStoreOf returns the voice store of srv. It panics like asset.StoreOf if RegisterLoaders has not run on srv.

func (VoiceStore) Err

func (s VoiceStore) Err(h gfx.VoiceHandle) error

Err returns why the voice failed to load, or nil.

func (VoiceStore) Generic

func (s VoiceStore) Generic() *asset.Store[Voice]

Generic returns the underlying generic store.

func (VoiceStore) Get

func (s VoiceStore) Get(h gfx.VoiceHandle) *Voice

Get returns the voice, or the placeholder (a silent voice); see asset.Store.Get for the pointer validity rule. It does not allocate.

func (VoiceStore) Key

func (s VoiceStore) Key(h gfx.VoiceHandle) asset.Key

Key returns the key h was loaded from, or the zero Key for a zero or stale handle.

func (VoiceStore) Lookup

func (s VoiceStore) Lookup(h gfx.VoiceHandle) (*Voice, asset.State)

Lookup is Get plus the load state; see asset.Store.Lookup.

func (VoiceStore) Ready

func (s VoiceStore) Ready(h gfx.VoiceHandle) bool

Ready reports whether h refers to a loaded voice.

func (VoiceStore) Version

func (s VoiceStore) Version(h gfx.VoiceHandle) uint32

Version returns the voice's version, which a hot reload increments; see asset.Store.Version.

Jump to

Keyboard shortcuts

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