audio

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float32ToPCM

func Float32ToPCM(float32Buffer []float32) ([]byte, error)

Float32ToPCM converts a slice of float32 samples to PCM byte data (int16)

Types

type AudioOptions

type AudioOptions struct {
	SampleRate      float64
	Latency         time.Duration
	FramesPerBuffer int
	Channels        int
	BytesPerSample  int
	BitsPerSample   int
}

func ComputeAudioOptions

func ComputeAudioOptions(opts *AudioOptions) (*AudioOptions, error)

type AudioStream

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

func NewInputStream

func NewInputStream(
	logger *slog.Logger,
	opts *AudioOptions,
	callback func([]float32),
) (*AudioStream, error)

func (*AudioStream) Close

func (a *AudioStream) Close() error

func (*AudioStream) Start

func (a *AudioStream) Start() error

func (*AudioStream) Stop

func (a *AudioStream) Stop() error

type VAD

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

VAD represents the Voice Activity Detection module

func NewVAD

func NewVAD(
	config VADConfig,
	callbacks VADCallbacks,
	logger *slog.Logger,
) *VAD

NewVAD initializes a new VAD instance

func (*VAD) Feed

func (v *VAD) Feed(buffer []float32)

Feed inputs an audio buffer into the VAD

func (*VAD) Start

func (v *VAD) Start()

Start begins the VAD processing

func (*VAD) Stop

func (v *VAD) Stop()

Stop gracefully stops the VAD processing

type VADCallbacks

type VADCallbacks struct {
	OnSpeechStart func()
	OnSpeechEnd   func()
	OnPause       func()
	OnFlush       func([]float32)
}

VADCallbacks defines the callbacks for VAD events

type VADConfig

type VADConfig struct {
	EnergyThreshold float64       // Threshold for energy to detect speech
	FlushInterval   time.Duration // Interval for periodic buffer flushing
	SilenceDuration time.Duration // Duration of continuous silence to detect end of speech
	PauseDuration   time.Duration // Duration of brief silence to detect a pause within speech
}

VADConfig defines configuration options for the VAD

Jump to

Keyboard shortcuts

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