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 ¶
- Variables
- func CaptureFilePCM(ctx context.Context, file *os.File, onChunk func([]byte) error) error
- func CapturePCM(ctx context.Context, device string, onChunk func([]byte) error) error
- func OpenCaptureFile(path string) (*os.File, error)
- func Play(ctx context.Context, file *os.File, format string, offset time.Duration) error
- func PlayPCM(ctx context.Context, source io.ReadCloser, rate, channels int) error
- func PlayPCMFrom(ctx context.Context, source *io.SectionReader, rate, channels int, ...) error
- func PlayWithProgress(ctx context.Context, file *os.File, format string, offset time.Duration, ...) error
- func ValidateCapture(device string) error
- func ValidatePlayback() error
- func Waveform(peaks []float64, width, height int) string
- type Analysis
- type PCM16Envelope
- type UnavailableError
Constants ¶
This section is empty.
Variables ¶
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") )
var ( ErrCaptureFailed = errors.New("microphone capture failed; check microphone access, the selected device, and FFmpeg audio device support") ErrCaptureDevice = errors.New("choose a microphone device name or index without line breaks") ErrCaptureUnsupported = errors.New("microphone capture is unavailable on this operating system") )
Functions ¶
func CaptureFilePCM ¶ added in v1.53.1
CaptureFilePCM sends decoded mono PCM16 at playback speed. The selected file reaches FFmpeg through stdin, without exposing a pathname or enabling other locations.
func CapturePCM ¶ added in v1.53.1
CapturePCM captures 24 kHz mono signed little-endian PCM16 through FFmpeg. The callback receives owned 200 ms chunks, serially, with no pending queue. It must return promptly or honor a caller-owned cancellation context. A final shorter chunk contains every complete sample received, including on cancellation. A graceful stop can use a separate bounded callback drain context. CapturePCM waits for its helper and callbacks before returning.
func OpenCaptureFile ¶ added in v1.53.1
OpenCaptureFile pins the selected recording before the session connects. The caller closes the returned file when translation ends.
func Play ¶
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 PlayPCM ¶ added in v1.53.1
PlayPCM plays a live signed little-endian PCM16 stream with explicit metadata. It owns source.Close on every exit. Close must unblock a pending Read; an io.PipeReader satisfies this contract. No input queue or recording is retained.
func PlayPCMFrom ¶ added in v1.53.1
func PlayPCMFrom(ctx context.Context, source *io.SectionReader, rate, channels int, offset time.Duration) error
PlayPCMFrom replays retained PCM16 starting at a complete sample frame. The caller owns the immutable recording and its underlying descriptor.
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 ValidateCapture ¶ added in v1.53.1
ValidateCapture checks the device selection and helper availability without opening a device. FFmpeg builds can omit the required platform input backend.
func ValidatePlayback ¶ added in v1.53.1
func ValidatePlayback() error
ValidatePlayback checks helper discovery without opening an output device.
func Waveform ¶
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 ¶
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 PCM16Envelope ¶ added in v1.53.1
type PCM16Envelope struct {
// contains filtered or unexported fields
}
PCM16Envelope measures interleaved PCM16 from a single stream. It retains the same bounded peak bins as saved-file analysis.
func (*PCM16Envelope) Add ¶ added in v1.53.1
func (e *PCM16Envelope) Add(data []byte, channels int)
func (*PCM16Envelope) Peaks ¶ added in v1.53.1
func (e *PCM16Envelope) Peaks() []float64
type UnavailableError ¶
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