playback

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0 Imports: 13 Imported by: 0 modules, 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 playback prepares a dictionary recording for the link helper to play.

The helper keeps one audio engine running between clicks, so a word plays at once and a Bluetooth headset is not woken for every click; it applies the speed with Apple's time-stretch unit. What it plays comes from here: the recording decoded to one fixed format, matched in loudness, set to the reader's volume and, when the helper's engine is cold, preceded by a moment of silence.

Nothing here is a new audio implementation. afconvert decodes and resamples the recording and measures its loudness (ITU-R BS.1770, the measure behind EBU R128 and Apple's Sound Check). This package only chooses one gain and applies it to the decoded samples.

Index

Constants

View Source
const (
	MinVolume, MaxVolume = 10, 200
	MinRate, MaxRate     = 50, 200
	MaxLeadIn            = 1000
)

Ranges accepted from callers; values outside are clamped.

View Source
const SampleRate = 44100

SampleRate and the single channel are the format every prepared recording has, so the helper connects its engine once and never reconfigures it.

View Source
const (
	// TargetLoudness is the integrated loudness recordings are matched to,
	// in LUFS: the level Apple's Sound Check uses for music and speech.
	TargetLoudness = -16.0
)

Variables

View Source
var ErrUnsupported = errors.New("this recording cannot be played on this system")

ErrUnsupported means the recording cannot be prepared here.

Functions

func Gain

func Gain(settings Settings, loudness, peak float64) float64

Gain is the linear gain for a recording with the given integrated loudness (NaN when unknown) and peak level in dBFS: loudness matching when asked for, then the volume setting, then as much reduction as keeps the peak under the ceiling.

func Prepare

func Prepare(dir string, data []byte, contentType string, settings Settings) ([]byte, error)

Prepare returns the recording as a WAV file ready to play.

func Supported

func Supported(contentType string) bool

Supported reports whether a content type can be prepared here.

Types

type Settings

type Settings struct {
	// Volume is a percentage of the (matched) level; 100 leaves it alone.
	Volume int
	// Rate is a percentage of normal speed; 100 leaves it alone.
	Rate int
	// Normalize matches the recording's loudness to TargetLoudness, so
	// dictionaries recorded at different levels sound alike.
	Normalize bool
	// LeadIn is silence, in milliseconds of real time, before the word. A
	// Bluetooth headset that has gone idle drops the first few hundred
	// milliseconds of a new stream while it wakes; for a single word that can
	// be all of it. The helper asks for it only when its engine was stopped.
	LeadIn int
}

Settings adjust one playback.

func Defaults

func Defaults() Settings

Defaults are what a caller that expresses no preference gets.

func (Settings) Clamped

func (s Settings) Clamped() Settings

Clamped returns s with every value inside its accepted range.

Jump to

Keyboard shortcuts

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