audiocap

package
v1.0.260758 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package audiocap captures the host's current audio output (whatever's already playing — desktop sounds, Amp, Vid, a bridged app) as raw PCM, for internal/attach to stream to an attached remote client. It shells out to parec against the default sink's monitor source — never a microphone — mirroring internal/ffdecode's ffmpeg-subprocess pattern: no linked capture library, a soft runtime dependency only needed if audio streaming is actually turned on. parec covers both PulseAudio proper and PipeWire systems running pipewire-pulse, which is the default on nearly every modern desktop distro; pw-record has no equivalently portable "default sink monitor" target name, so it isn't wired up here.

Index

Constants

View Source
const (
	SampleRate = 48000
	Channels   = 2
)

SampleRate/Channels match internal/audio's fixed output format, so a captured chunk can go straight to an attached client's Playback with no resampling.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available reports whether parec is on PATH — checked before Capture for a clear error instead of a raw exec failure.

Types

type Event

type Event struct {
	Err error
}

Event is how a Stream's feeder goroutine reports back — never by touching caller state directly, exactly like internal/ffdecode.AudioEvent.

type Stream

type Stream struct {
	PCM chan []int16
	// contains filtered or unexported fields
}

Stream captures raw PCM from the default sink's monitor via a parec subprocess. PCM delivers interleaved int16 samples at SampleRate/Channels.

func Capture

func Capture(events chan<- Event) (*Stream, error)

Capture starts parec and begins feeding PCM into the returned stream's PCM channel. events receives exactly one Event if capture ends unexpectedly (Err set); a clean Stop sends nothing.

func (*Stream) Stop

func (s *Stream) Stop()

Stop kills the parec subprocess and unblocks feed if it's stuck mid-send with nothing left to ever drain it. Safe to call more than once.

Jump to

Keyboard shortcuts

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