Documentation
¶
Index ¶
- func ToneNames() []string
- type CadenceSegment
- type Player
- func (p *Player) IsPlaying() bool
- func (p *Player) OnStart(fn func())
- func (p *Player) Play(ctx context.Context, writer io.Writer, url string, mimeType string, repeat int) error
- func (p *Player) PlayAt8kHz(ctx context.Context, writer io.Writer, url string, mimeType string, repeat int) error
- func (p *Player) PlayAtRate(ctx context.Context, writer io.Writer, url, mimeType string, targetRate uint32, ...) error
- func (p *Player) PlayReader(ctx context.Context, writer io.Writer, reader io.Reader, mimeType string) error
- func (p *Player) PlayReaderAt8kHz(ctx context.Context, writer io.Writer, reader io.Reader, mimeType string) error
- func (p *Player) PlayReaderAtRate(ctx context.Context, writer io.Writer, reader io.Reader, mimeType string, ...) error
- func (p *Player) SetVolume(v int)
- func (p *Player) Stop()
- type ToneReader
- type ToneSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CadenceSegment ¶
CadenceSegment defines a segment of a tone cadence pattern. On=true means tone is playing, On=false means silence.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player manages audio playback to an io.Writer (PCM stream).
func (*Player) OnStart ¶
func (p *Player) OnStart(fn func())
OnStart registers a callback that fires once when audio streaming begins, after a successful fetch and format detection. Not called on fetch errors.
func (*Player) Play ¶
func (p *Player) Play(ctx context.Context, writer io.Writer, url string, mimeType string, repeat int) error
Play fetches audio from url and streams 16kHz mono 16-bit PCM to writer. WAV files are parsed and resampled/downmixed as needed. Supports PCM, mu-law, and A-law encoded WAV files. repeat controls looping: 0 or 1 = play once, -1 = infinite, N > 1 = N times. Blocks until playback completes or is stopped.
func (*Player) PlayAt8kHz ¶
func (p *Player) PlayAt8kHz(ctx context.Context, writer io.Writer, url string, mimeType string, repeat int) error
PlayAt8kHz fetches audio and streams 8kHz mono 16-bit PCM to writer. Used for direct leg playback where the leg expects 8kHz PCM. repeat controls looping: 0 or 1 = play once, -1 = infinite, N > 1 = N times.
func (*Player) PlayAtRate ¶
func (p *Player) PlayAtRate(ctx context.Context, writer io.Writer, url, mimeType string, targetRate uint32, repeat int) error
PlayAtRate fetches audio and streams mono 16-bit PCM at the given target rate. Used for direct leg playback at the leg's native sample rate.
func (*Player) PlayReader ¶
func (p *Player) PlayReader(ctx context.Context, writer io.Writer, reader io.Reader, mimeType string) error
PlayReader streams audio from an io.Reader at 16kHz (default mixer rate). Unlike Play, it does not fetch from a URL and plays only once.
func (*Player) PlayReaderAt8kHz ¶
func (p *Player) PlayReaderAt8kHz(ctx context.Context, writer io.Writer, reader io.Reader, mimeType string) error
PlayReaderAt8kHz streams audio from an io.Reader at 8kHz (leg native rate). Unlike PlayAt8kHz, it does not fetch from a URL and plays only once.
func (*Player) PlayReaderAtRate ¶
func (p *Player) PlayReaderAtRate(ctx context.Context, writer io.Writer, reader io.Reader, mimeType string, targetRate uint32) error
PlayReaderAtRate streams audio from an io.Reader at the given target rate. Used for direct leg playback at the leg's native sample rate.
type ToneReader ¶
type ToneReader struct {
// contains filtered or unexported fields
}
ToneReader generates infinite cadenced PCM from a ToneSpec. It implements io.Reader producing 16-bit signed little-endian mono PCM.
func NewToneReader ¶
func NewToneReader(spec ToneSpec, sampleRate int) *ToneReader
NewToneReader creates a ToneReader for the given spec at the given sample rate.
type ToneSpec ¶
type ToneSpec struct {
Frequencies []float64 // base frequencies to mix (e.g. 440, 480)
ModulationHz float64 // amplitude modulation frequency (0 = none)
Cadence []CadenceSegment // on/off pattern; nil or empty = continuous
}
ToneSpec defines a telephone tone: frequencies, optional AM modulation, and cadence.
func LookupTone ¶
LookupTone finds a tone by name. Accepts "country_type" (e.g. "us_ringback") or bare "type" (e.g. "ringback") which defaults to US. Also accepts common aliases (e.g. "uk_ringback" → "gb_ringback").