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 ¶
const (
MinVolume, MaxVolume = 10, 200
MinRate, MaxRate = 50, 200
MaxLeadIn = 1000
)
Ranges accepted from callers; values outside are clamped.
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.
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 ¶
var ErrUnsupported = errors.New("this recording cannot be played on this system")
ErrUnsupported means the recording cannot be prepared here.
Functions ¶
func Gain ¶
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.
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.