Documentation
¶
Index ¶
Constants ¶
const ( DefaultSilenceThreshold = 0.01 // Default silence threshold DefaultSilenceDuration = time.Millisecond * 500 // Default silence duration MinDuration = time.Millisecond * 250 // Minimum duration )
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 WithSilenceSize ¶ added in v1.7.7
type SegmentFuncFloat32 ¶
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 ¶
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 ¶
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) 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.