audio

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package audio provides audio analysis utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractSegment

func ExtractSegment(samples []float64, startSample, endSample int) []float64

ExtractSegment extracts a segment from samples.

func WriteWAV

func WriteWAV(path string, samples []float64, sampleRate uint32) error

WriteWAV writes samples to a WAV file.

Types

type AnalyzeConfig

type AnalyzeConfig struct {
	// TargetDuration is the desired segment length in seconds
	TargetDuration float64

	// StepSize is the sliding window step in seconds
	StepSize float64

	// FrameSize is the analysis frame size in seconds
	FrameSize float64

	// SilenceThreshold is the RMS threshold for silence detection (0-1)
	SilenceThreshold float64

	// TopN returns the top N segments
	TopN int
}

AnalyzeConfig configures the segment analysis.

func DefaultAnalyzeConfig

func DefaultAnalyzeConfig() AnalyzeConfig

DefaultAnalyzeConfig returns sensible defaults.

type SegmentMetrics

type SegmentMetrics struct {
	// MeanEnergy is the average RMS energy (higher = louder speech)
	MeanEnergy float64

	// EnergyVariance measures consistency (lower = more consistent)
	EnergyVariance float64

	// SpeechRatio is the fraction of frames with speech activity
	SpeechRatio float64

	// SilenceGaps is the number of silence gaps > 0.5s
	SilenceGaps int

	// MaxSilenceGap is the longest silence gap in seconds
	MaxSilenceGap float64

	// PeakClipping is the fraction of samples near clipping
	PeakClipping float64
}

SegmentMetrics contains quality metrics for a segment.

type SegmentScore

type SegmentScore struct {
	StartSample int
	EndSample   int
	StartTime   float64
	EndTime     float64
	Score       float64
	Metrics     SegmentMetrics
}

SegmentScore represents a scored segment of audio.

func FindBestSegments

func FindBestSegments(samples []float64, sampleRate uint32, config AnalyzeConfig) ([]SegmentScore, error)

FindBestSegments analyzes audio and returns the best segments for voice cloning.

type WAVHeader

type WAVHeader struct {
	SampleRate    uint32
	NumChannels   uint16
	BitsPerSample uint16
	DataSize      uint32
}

WAVHeader represents a WAV file header.

func ReadWAV

func ReadWAV(path string) (*WAVHeader, []float64, error)

ReadWAV reads a WAV file and returns the header and samples as float64 (-1 to 1).

Directories

Path Synopsis
Package codec provides audio codec implementations for telephony.
Package codec provides audio codec implementations for telephony.
Package converter provides audio format conversion for voice gateways.
Package converter provides audio format conversion for voice gateways.
Package format defines audio format types for voice processing.
Package format defines audio format types for voice processing.

Jump to

Keyboard shortcuts

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