Documentation
¶
Overview ¶
Package say provides a cross-platform text-to-speech abstraction.
It mirrors the pkg/browser package: a small interface (Speaker) backed by per-OS detection of a TTS engine (macOS `say`, Linux `spd-say`/`espeak`, Windows PowerShell System.Speech), with a CommandRunner seam for testing.
When no engine is available — or the process is running in CI or a test — New returns a Speaker that invokes a caller-supplied fallback instead of emitting audio, so callers degrade gracefully on headless machines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListVoices ¶
func ListVoices(info *SayInfo, runner CommandRunner) ([]string, error)
ListVoices enumerates the voices installed for the detected backend. Returns ErrVoiceListUnsupported for backends that cannot enumerate voices (e.g. spd-say, whose voice model is module-based rather than named).
Types ¶
type Backend ¶
type Backend int
Backend identifies a platform text-to-speech engine.
const ( // BackendMacSay is the macOS `say` command. BackendMacSay Backend = iota // BackendSpdSay is the Linux Speech Dispatcher `spd-say` command. BackendSpdSay // BackendEspeak is the Linux `espeak`/`espeak-ng` command. BackendEspeak // BackendPowerShell is the Windows PowerShell System.Speech backend. BackendPowerShell )
type CommandRunner ¶
type CommandRunner interface {
// Run executes the command and waits for it to complete.
Run(name string, args ...string) error
// Output executes the command, waits, and returns its standard output.
Output(name string, args ...string) ([]byte, error)
}
CommandRunner executes external commands. Abstracted for testing.
type FallbackFunc ¶
FallbackFunc renders text when speech is unavailable.
type Option ¶
type Option func(*config)
Option configures a Speaker.
func WithCommandRunner ¶
func WithCommandRunner(runner CommandRunner) Option
WithCommandRunner sets a custom command runner (for testing).
func WithFallback ¶
func WithFallback(fn FallbackFunc) Option
WithFallback sets the function used to render text when speech is unavailable.
func WithVoices ¶
WithVoices sets the ordered list of candidate voices. The first voice actually installed on the host is used (CSS font-family style); if none match, the backend's default voice is used.
type SayInfo ¶
type SayInfo struct {
// Path is the resolved path to the TTS executable.
Path string
// Backend identifies which TTS engine Path refers to.
Backend Backend
}
SayInfo holds information about a detected text-to-speech backend.