sound

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sound provides optional audio notifications for run-lifecycle events.

Playback is opt-in via the sound section in .productize/config.toml and is disabled by default. A Noop player is used whenever the feature flag is off or the platform is not supported, so callers never need to special-case "sound is turned off".

Index

Constants

View Source
const (
	PresetGlass     = "glass"
	PresetBasso     = "basso"
	PresetPing      = "ping"
	PresetHero      = "hero"
	PresetFunk      = "funk"
	PresetTink      = "tink"
	PresetSubmarine = "submarine"
)

preset names accepted in config.toml. Absolute paths bypass preset lookup.

Variables

View Source
var ErrEmptySound = errors.New("sound: empty sound name")

ErrEmptySound indicates the caller passed an empty sound identifier.

View Source
var ErrUnsupported = errors.New("sound: unsupported platform")

ErrUnsupported indicates the running platform cannot play sounds.

Functions

func KnownPresets

func KnownPresets() []string

KnownPresets lists every preset name the resolver understands. The list is exposed so the CLI / docs can surface valid values without re-declaring them.

func Notify

func Notify(
	ctx context.Context,
	cfg Config,
	kind events.EventKind,
	logger *slog.Logger,
)

Notify plays the configured sound for the given lifecycle event kind and blocks until the underlying player returns. Notify is the only API the run pipelines use: it runs on the caller's goroutine so the sound is guaranteed to finish before run cleanup tears down state.

The parent context is detached via context.WithoutCancel before playback starts. This is deliberate: on run.failed and run.cancelled the caller passes a ctx that is already done, and a canceled exec.CommandContext would immediately kill afplay/paplay so the failure sound would never be audible. A bounded playbackTimeout prevents a hung player from delaying run shutdown indefinitely.

Unrecognized kinds and empty preset configurations are silent no-ops. Playback errors are logged at debug and never bubble back to the caller — a missing system sound must not break a successful run.

func ResolvePath

func ResolvePath(sound string) (string, error)

ResolvePath maps a preset name or filesystem path to a concrete file that the platform player can consume. Absolute paths are returned verbatim. Unknown presets produce a descriptive error so users see typos early.

Types

type Config

type Config struct {
	Player      Player
	OnCompleted string
	OnFailed    string
}

Config binds a Player to per-event-kind preset names. Both presets and absolute filesystem paths are accepted; an empty string for a given kind disables playback for that kind.

type Noop

type Noop struct{}

Noop is the zero-cost player used when sound is disabled or unsupported.

func (Noop) Play

func (Noop) Play(context.Context, string) error

Play satisfies Player and always returns nil.

type Player

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

Player plays a named preset or a filesystem path. Implementations must be safe to call from any goroutine and must honor context cancellation.

func New

func New() Player

New returns the default Player for the current platform. Callers that want to skip playback entirely should use Noop{} directly.

Jump to

Keyboard shortcuts

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