segmenter

package
v1.7.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultSilenceThreshold = 0.01                   // Default silence threshold
	DefaultSilenceDuration  = time.Millisecond * 500 // Default silence duration
	MinDuration             = time.Millisecond * 250 // Minimum 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 WithSegmentSize added in v1.7.7

func WithSegmentSize(v time.Duration) Opt

func WithSilenceSize added in v1.7.7

func WithSilenceSize(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, sample_rate int, opts ...Opt) (*Segmenter, error)

Create a new segmenter with a reader r which segments into raw audio. The sample rate is the number of samples per second.

Setting option WithSegmentSize will cause the segmenter to segment the audio into fixed-size chunks approximately of the specified duration.

Setting option WithDefaultSilenceThreshold will cause the segmenter to break into smaller chunks, if silence is detected. The length of the silence is specified by the WithSilenceDuration option, which defaults to 2 seconds.

At the moment, the audio format is auto-detected, but there should be a way to specify the audio format. The output samples are always single-channel (mono).

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