sounds

package
v0.3.16 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 19 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

Package sounds plays notification sounds: names resolve through the freedesktop sound theme, files decode once (Ogg Vorbis and WAV) into the PCM the audio server's sample cache keeps, and a notification's sound plays from that cache through the session's PipeWire.

Index

Constants

View Source
const FallbackTheme = "freedesktop"

FallbackTheme is the theme every lookup ends in.

Variables

View Source
var ErrNoSound = errors.New("no sound theme file for this name")

ErrNoSound is a name no theme in the chain has a file for.

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

ErrUnsupported is a sound file that is neither Ogg Vorbis nor PCM WAV.

Functions

func Decode

func Decode(path string) (native.Sample, error)

Decode reads the sound file at path into interleaved signed 16-bit PCM for the sample cache.

Types

type Announcer

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

Announcer plays the sound of each new notification that may make one.

func NewAnnouncer

func NewAnnouncer(svc *notifications.Service, player Player, theme Theme, muted func() bool, policy Policy) *Announcer

NewAnnouncer plays notification sounds of svc through player, sound names resolving in theme; muted reports the default sink muted.

func (*Announcer) Announce

func (a *Announcer) Announce(n *notifications.Notification)

Announce plays n's sound when the policy, do-not-disturb, a share and the sink's mute all let it.

func (*Announcer) Decodes

func (a *Announcer) Decodes() int

Decodes counts the sound files decoded so far.

func (*Announcer) Run

func (a *Announcer) Run(events <-chan notifications.Event)

Run follows the service's feed until stop, playing each new notification's sound.

func (*Announcer) SetPolicy

func (a *Announcer) SetPolicy(p Policy)

SetPolicy replaces the sound configuration.

type Mode

type Mode uint8

Mode is which notifications make a sound.

const (
	Off Mode = iota
	Critical
	All
)

The modes.

type Player

type Player interface {
	PlaySample(ctx context.Context, p native.SamplePlay, load func() (native.Sample, error)) error
}

Player plays a sample through the audio server's cache, loading it on the first play (*pulse.Service).

type Policy

type Policy struct {
	Mode Mode
	// Default is the theme sound a notification without a sound hint
	// plays, and what a sound name the theme lacks falls back to.
	Default string
	// MuteApps are app-name or desktop-entry globs that never sound.
	MuteApps []string
	// Volume is the sounds' linear level, 1 playing them as recorded.
	Volume float64
}

Policy is the sound configuration.

type Theme

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

Theme resolves sound names in a sound theme and those it inherits, over the XDG data directories.

func NewTheme

func NewTheme(theme string, dataDirs []string) Theme

NewTheme looks names up in theme ("" is the fallback theme) under the sounds directory of each of dataDirs, most important first.

func (Theme) Lookup

func (t Theme) Lookup(name string) (string, error)

Lookup is the file for name in the theme, the themes it inherits and the fallback theme, in that order; only when none has the name does a shorter one (message-new-instant, then message-new, then message) count.

Jump to

Keyboard shortcuts

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