Help us shape the future of Go! Take the 2026 Go Developer Survey

audiomedia

package
v1.43.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package audiomedia analyzes immutable local audio and owns cancellable playback. Callers retain ownership of the verified snapshot and must not modify it while an operation runs. The package never reopens its pathname or closes its file.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAudio       = errors.New("audio is malformed or incomplete")
	ErrUnsupportedFormat  = errors.New("audio format is unsupported")
	ErrAnalysisFailed     = errors.New("audio analysis failed")
	ErrPlaybackFailed     = errors.New("audio playback failed")
	ErrDecoderUnavailable = errors.New("audio decoding requires FFmpeg; install FFmpeg or use uncompressed WAV or PCM")
	ErrPlayerUnavailable  = errors.New("audio playback requires FFplay; install FFmpeg with FFplay")
)

Functions

func Play

func Play(ctx context.Context, file *os.File, format string, offset time.Duration) error

Play starts local audio only when called explicitly. Native PCM/WAV offsets skip complete sample frames. Compressed offsets use output-side decoder seek. Every helper reads verified bytes through pipes; no path or URL reaches it.

func PlayWithProgress added in v1.40.3

func PlayWithProgress(ctx context.Context, file *os.File, format string, offset time.Duration, report func(time.Duration)) error

PlayWithProgress reports positions from FFplay's audio clock in the original recording. The player estimates device buffering; reports are not exact audible positions. No report arrives until the player supplies a usable clock. Reports run serially, must return promptly, and stop before this function returns. Callers must reject stale reports when replacing playback and handle no reports. A nil report preserves Play's behavior. The caller still owns the file.

func Waveform

func Waveform(peaks []float64, width, height int) string

Waveform draws uncolored amplitudes on a fixed 0..1 scale. Multiple rows use symmetric Braille columns; a single row uses an eight-level block sparkline. Dimensions are bounded independently from accepted audio size. Zero samples produce a baseline; absent audio produces no invented waveform.

Types

type Analysis

type Analysis struct {
	Format   string    `json:"format"`
	Bytes    int64     `json:"bytes"`
	Duration float64   `json:"duration"`
	Peaks    []float64 `json:"peaks"`
}

func Analyze

func Analyze(ctx context.Context, file *os.File, format string) (Analysis, error)

Analyze scans the supplied snapshot without changing its seek offset. A caller may use a context deadline to bound this optional work after preserving audio. Duration counts decoded frames. Each peak is the maximum absolute sample over all channels in its interval; opposite-phase stereo cannot cancel the waveform.

type UnavailableError

type UnavailableError struct{ Tool string }

UnavailableError identifies a missing optional helper without exposing paths.

func (*UnavailableError) Error

func (e *UnavailableError) Error() string

func (*UnavailableError) Unwrap

func (e *UnavailableError) Unwrap() error

Jump to

Keyboard shortcuts

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