segmenter

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultSilenceThreshold = 0.0005          // Default silence threshold
	DefaultSilenceDuration  = time.Second * 2 // Default silence duration
)
View Source
const (
	Int16Gain = float64(math.MaxInt16) // Gain for converting int16 to float32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt added in v1.7.6

type Opt func(*opts) error

func WithDefaultSilenceThreshold added in v1.7.6

func WithDefaultSilenceThreshold() Opt

func WithSilenceDuration added in v1.7.6

func WithSilenceDuration(v time.Duration) Opt

type SegmentFuncFloat32

type SegmentFuncFloat32 func(time.Duration, []float32) error

SegmentFuncFloat is a callback function which is called for the next segment of audio samples. The first argument is the timestamp of the segment.

type SegmentFuncInt16

type SegmentFuncInt16 func(time.Duration, []int16) error

SegmentFuncInt16 is a callback function which is called for the next segment of audio samples. The first argument is the timestamp of the segment.

type Segmenter

type Segmenter struct {
	// contains filtered or unexported fields
}

A segmenter reads audio samples from a reader and segments them into fixed-size chunks. The segmenter can be used to process audio samples

func NewReader

func NewReader(r io.Reader, dur time.Duration, sample_rate int, opts ...Opt) (*Segmenter, error)

Create a new segmenter with a reader r which segments into raw audio of 'dur' length. If dur is zero then no segmenting is performed, the whole audio file is read and output in one go, which could cause some memory issues. The sample rate is the number of samples per second.

At the moment, the audio format is auto-detected, but there should be a way to specify the audio format.

func (*Segmenter) Close

func (s *Segmenter) Close() error

Close the segmenter

func (*Segmenter) DecodeFloat32

func (s *Segmenter) DecodeFloat32(ctx context.Context, fn SegmentFuncFloat32) error

Segments are output through a callback, with the samples and a timestamp At the moment the "best" audio stream is used, based on ffmpeg heuristic.

func (*Segmenter) DecodeInt16

func (s *Segmenter) DecodeInt16(ctx context.Context, fn SegmentFuncInt16) error

Segments are output through a callback, with the samples and a timestamp At the moment the "best" audio stream is used, based on ffmpeg heuristic.

func (*Segmenter) Duration

func (s *Segmenter) Duration() time.Duration

Return current timestamp

Jump to

Keyboard shortcuts

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