audio

package
v0.0.0-...-05c9cfb Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package audio provides microphone capture and speaker playback for the voice-interview example. It is a thin adapter over the shared pure-Go runtime/audio Session (purego/dlopen PortAudio — no CGO), preserving the capture/playback API the interview controller depends on.

Index

Constants

View Source
const (
	// InputSampleRate is the sample rate for microphone input (16kHz for speech)
	InputSampleRate = 16000
	// OutputSampleRate is the sample rate for speaker output (24kHz for TTS)
	OutputSampleRate = 24000
	// Channels is mono audio
	Channels = 1
	// InputFramesPerBuffer is 100ms of audio at 16kHz
	InputFramesPerBuffer = 1600
	// OutputFramesPerBuffer is 40ms of audio at 24kHz
	OutputFramesPerBuffer = 960
	// EnergyThreshold for voice activity detection
	EnergyThreshold = 500
)

Variables

This section is empty.

Functions

func BytesToInt16

func BytesToInt16(data []byte) []int16

BytesToInt16 converts bytes to int16 audio samples (little-endian PCM16)

func HasVoiceActivity

func HasVoiceActivity(samples []int16) bool

HasVoiceActivity checks if audio has significant energy

Types

type AudioCapture

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

AudioCapture handles microphone input

func (*AudioCapture) AudioChunks

func (ac *AudioCapture) AudioChunks() <-chan []byte

AudioChunks returns the channel for receiving audio data

func (*AudioCapture) EnergyLevels

func (ac *AudioCapture) EnergyLevels() <-chan float64

EnergyLevels returns the channel for receiving audio energy levels

func (*AudioCapture) Start

func (ac *AudioCapture) Start(ctx context.Context) error

Start begins audio capture

func (*AudioCapture) Stop

func (ac *AudioCapture) Stop()

Stop stops audio capture

type AudioPlayback

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

AudioPlayback handles speaker output

func (*AudioPlayback) AudioInput

func (ap *AudioPlayback) AudioInput() chan<- []byte

AudioInput returns the channel for sending audio data to play

func (*AudioPlayback) Start

func (ap *AudioPlayback) Start(ctx context.Context) error

Start begins audio playback

func (*AudioPlayback) Stop

func (ap *AudioPlayback) Stop()

Stop stops audio playback

func (*AudioPlayback) Write

func (ap *AudioPlayback) Write(data []byte) error

Write sends audio data for playback

type AudioSystem

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

AudioSystem manages both capture and playback over one shared audio session.

func NewAudioSystem

func NewAudioSystem() (*AudioSystem, error)

NewAudioSystem creates a new audio system backed by the shared runtime/audio Session (16kHz capture, 24kHz playback).

func (*AudioSystem) Capture

func (as *AudioSystem) Capture() *AudioCapture

Capture returns the audio capture component

func (*AudioSystem) Close

func (as *AudioSystem) Close() error

Close shuts down the audio system

func (*AudioSystem) Playback

func (as *AudioSystem) Playback() *AudioPlayback

Playback returns the audio playback component

Jump to

Keyboard shortcuts

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