Documentation
¶
Overview ¶
Package opus wraps the Opus codec for jargo's audio path: it decodes Opus packets to PCM on the way in and encodes PCM to Opus packets on the way out.
The codec runs at 48 kHz — the rate WebRTC negotiates for Opus — so audio crosses the transport without resampling. Encoding produces 20 ms frames, the standard WebRTC packetization.
Both the decoder and the encoder are pure Go, so the package needs no cgo: the decoder handles every Opus mode, and the encoder emits wideband SILK (see encoder.go), which is the mode tuned for speech.
Index ¶
Constants ¶
const ( // SampleRate is the codec sample rate in Hz. Opus runs at 48 kHz. SampleRate = 48000 // FrameDuration is the duration of one encoded packet. FrameDuration = 20 * time.Millisecond // FrameSamples is the number of samples per channel in one 20 ms frame. FrameSamples = SampleRate / 1000 * 20 // 960 )
Variables ¶
This section is empty.
Functions ¶
func FrameBytes ¶
FrameBytes is the size in bytes of one 20 ms S16LE frame for channels.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes Opus packets into signed 16-bit little-endian PCM.
func NewDecoder ¶
NewDecoder builds a Decoder that outputs channels-channel 48 kHz PCM. It decodes all Opus modes (SILK, CELT and hybrid).
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes 48 kHz S16LE PCM into Opus packets using the pure-Go pion SILK encoder. SILK is tuned for speech and needs no cgo. The 48 kHz input is downmixed to mono and resampled to 16 kHz with the pure-Go resampler, then encoded as wideband SILK.
func NewEncoder ¶
func NewEncoder(cfg EncoderConfig) (*Encoder, error)
NewEncoder builds a SILK Encoder for 48 kHz audio from cfg.
type EncoderConfig ¶ added in v0.1.0
type EncoderConfig struct {
// Channels is the number of channels in the PCM handed to Encode.
Channels int
// Bitrate is the target bitrate in bits per second; 0 uses the codec
// default. Speech is transparent well below the codec's fullband range, so
// raising this past ~32 kbps for a single voice mostly costs bandwidth.
Bitrate int
}
EncoderConfig configures an Encoder.