audio

package
v0.163.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package audio provides CGO-free microphone capture and audio-format conversion by shelling out to ffmpeg (with arecord/sox fallbacks on Linux). It produces 16kHz mono WAV, the input format whisper.cpp expects, and is used by the chat /voice shortcut and Telegram voice-message transcription.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

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

Converter converts arbitrary audio files into Whisper-ready 16kHz mono WAV. It is used to turn Telegram voice notes (OGG/Opus) into a format whisper.cpp can read.

func NewConverter

func NewConverter(cfg config.SpeechToTextConfig) *Converter

NewConverter creates a Converter from the speech-to-text config.

func (*Converter) SetBinaryEnsurer added in v0.148.0

func (c *Converter) SetBinaryEnsurer(f func(ctx context.Context, name string) (string, error))

SetBinaryEnsurer installs a fallback that resolves (downloading if needed) a named binary when it is not found on PATH.

func (*Converter) ToWhisperWAV

func (c *Converter) ToWhisperWAV(ctx context.Context, srcPath string) (string, error)

ToWhisperWAV converts srcPath into a new 16kHz mono WAV file and returns its path. The caller owns the returned file and should remove it when done.

type Recorder

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

Recorder captures microphone audio into a 16kHz mono WAV file by shelling out to ffmpeg (with arecord/sox fallbacks on Linux), mirroring the candidate-list pattern used by the clipboard text writer. It adds no CGO.

func NewRecorder

func NewRecorder(cfg config.SpeechToTextConfig) *Recorder

NewRecorder creates a Recorder from the speech-to-text config.

func (*Recorder) EnsureAvailable

func (r *Recorder) EnsureAvailable() error

EnsureAvailable reports whether a microphone capture tool is installed, without recording. It lets callers fail fast (with an actionable error) before prompting the user to speak.

func (*Recorder) Record

func (r *Recorder) Record(ctx context.Context, maxSeconds int) (string, error)

Record captures up to maxSeconds of microphone audio and returns the path to a 16kHz mono WAV file. When speech_to_text.silence_timeout is set, ffmpeg recordings stop shortly after the speaker goes quiet instead of always running for the full cap. The caller owns the returned file and should remove it.

Jump to

Keyboard shortcuts

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