audio

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: ISC Imports: 14 Imported by: 0

README

Ogg encoding originally from https://github.com/chenbh/skynetbot.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	IsDefault bool   `json:"is_default"`
}

func FindDevice

func FindDevice(typ DeviceType, id string) *Device

FindDevice finds the device with the given ID or returns nil.

type DeviceType

type DeviceType string
const (
	DeviceTypeCapture  DeviceType = "capture"
	DeviceTypePlayback DeviceType = "playback"
)

type Devices

type Devices struct {
	Playback []Device `json:"playback"`
	Capture  []Device `json:"capture"`
}

func ListAudioDevices

func ListAudioDevices(log slog.Logger) (Devices, error)

ListAudioDevices lists available audio devices.

type NoteRecorder

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

NoteRecorder can record and playback audio notes.

func NewRecorder

func NewRecorder(log slog.Logger) (*NoteRecorder, error)

func (*NoteRecorder) Busy

func (ar *NoteRecorder) Busy() (recording bool, playing bool)

Busy returns the state of the recorder.

func (*NoteRecorder) Capture

func (ar *NoteRecorder) Capture(ctx context.Context) error

Capture audio data until the context is canceled or Stop() is called.

func (*NoteRecorder) FreeContext

func (ar *NoteRecorder) FreeContext() error

FreeContext releases all resources.

func (*NoteRecorder) HasRecorded

func (ar *NoteRecorder) HasRecorded() bool

HasRecorded returns whether there's a recorded note.

func (*NoteRecorder) OpusFile

func (ar *NoteRecorder) OpusFile() ([]byte, error)

OpusFile encodes the recorded audio note as an opusfile (a .ogg file with opus-encoded audio data).

func (*NoteRecorder) Playback

func (ar *NoteRecorder) Playback(ctx context.Context) error

Playback the recorded audio until it ends or the context is canceled or Stop() is called.

func (*NoteRecorder) RecordInfo

func (ar *NoteRecorder) RecordInfo() RecordInfo

RecordInfo returns information about the latest recording.

func (*NoteRecorder) SetCaptureDevice

func (ar *NoteRecorder) SetCaptureDevice(dev *Device) error

SetCaptureDevice sets the capture device to use for recording. If nil, uses the default device.

func (*NoteRecorder) SetPlaybackDevice

func (ar *NoteRecorder) SetPlaybackDevice(dev *Device) error

SetPlaybackDevice sets the playback device to use for playing. If nil, uses the default device.

func (*NoteRecorder) Stop

func (ar *NoteRecorder) Stop()

Stop the current operation (record or playback).

type OggHeader

type OggHeader struct {
	Version     uint8
	IsContinued bool
	IsFirstPage bool
	IsLastPage  bool

	GranulePosition uint64
	BitstreamSerial uint32
	PageSequence    uint32
	CrcChecksum     uint32

	PageSegments uint8
	SegmentTable []uint8
}

type OggPage

type OggPage struct {
	OggHeader
	Segments [][]byte

	// Size of all segments in bytes
	SegmentTotal int
}

type OpusPacket

type OpusPacket []byte

type RecordInfo

type RecordInfo struct {
	SampleCount int `json:"sample_count"`
	DurationMs  int `json:"duration_ms"`
	EncodedSize int `json:"encoded_size"`
	PacketCount int `json:"packet_count"`
}

Jump to

Keyboard shortcuts

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