tts

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyText is returned when there is nothing to synthesize.
	ErrEmptyText = errors.New("tts: empty text")
	// ErrNotConfigured is returned when the engine binary or model is missing.
	ErrNotConfigured = errors.New("tts: engine not configured (piper binary or model missing)")
)

Functions

func DetectLanguage added in v1.15.0

func DetectLanguage(text string, candidates []string) string

DetectLanguage returns the ISO 639-1 code of text's dominant language, restricted to candidates (the languages you have a voice/model for). Restricting the choice makes detection far more accurate on short or mixed text than open-set detection. With a single candidate it returns that language without detecting; with none, or when it can't decide, it returns "".

func ResolveEngine added in v1.15.0

func ResolveEngine(configured string) string

ResolveEngine maps a configured engine value to a concrete engine. "say" and "piper" are honored as-is; anything else ("" or "auto") auto-selects by OS: macOS gets the built-in "say" (zero dependencies, always available), every other platform gets the cross-platform "piper".

Types

type ExternalPiperSynthesizer

type ExternalPiperSynthesizer struct {
	PiperPath string
}

ExternalPiperSynthesizer runs the local Piper binary: text on stdin → a temp WAV file.

func (*ExternalPiperSynthesizer) Synthesize

type OSPlayer

type OSPlayer struct{}

OSPlayer uses the platform's audio CLI.

func (OSPlayer) Play

func (OSPlayer) Play(ctx context.Context, audioPath string) error

type Player

type Player interface {
	Play(ctx context.Context, audioPath string) error
}

Player plays an audio file through the OS. Killable via the context.

type SaySynthesizer added in v1.15.0

type SaySynthesizer struct{}

SaySynthesizer uses the macOS built-in `say` command — zero external dependencies, always available on macOS. It speaks **directly** (streaming): `say` starts talking almost immediately and is killed instantly on cancel, with no temp file or separate player. opts.ModelPath is ignored; opts.Voice selects a macOS system voice (the caller picks it by detected language). Because it plays itself, Synthesize returns an empty AudioPath — the SpeechService takes that as "already played".

func (*SaySynthesizer) Synthesize added in v1.15.0

func (s *SaySynthesizer) Synthesize(ctx context.Context, text string, opts SynthesizeOptions) (*SynthesisResult, error)

type SynthesisResult

type SynthesisResult struct {
	AudioPath string
	Engine    string
	Model     string
}

SynthesisResult describes the generated audio.

type SynthesizeOptions

type SynthesizeOptions struct {
	ModelPath string // path to the .onnx voice model (engine "piper")
	Voice     string // voice name (engine "say"); empty = system default
}

SynthesizeOptions configures a single synthesis call. The fields are per-call so the caller can pick a voice/model by the detected language of the text.

type Synthesizer

type Synthesizer interface {
	Synthesize(ctx context.Context, text string, opts SynthesizeOptions) (*SynthesisResult, error)
}

Synthesizer turns text into an audio file. Decoupled so the engine can be swapped.

Jump to

Keyboard shortcuts

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