Documentation
¶
Overview ¶
Package audio provides CGO-free microphone capture, audio-format conversion, and speech-to-text. Capture and conversion shell out to ffmpeg (with arecord/sox fallbacks on Linux) to produce 16kHz mono WAV; transcription shells out to a local whisper.cpp binary (whisper-cli / whisper-cpp), downloading binaries and GGML models on demand. Gated by config.SpeechToTextConfig and 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 BinaryManager ¶ added in v0.178.0
type BinaryManager struct {
// contains filtered or unexported fields
}
BinaryManager downloads prebuilt STT helper binaries (whisper-cli, ffmpeg) into ~/.infer/bin on demand, mirroring ModelManager for GGML models.
func NewBinaryManager ¶ added in v0.178.0
func NewBinaryManager(cfg config.SpeechToTextConfig) *BinaryManager
NewBinaryManager creates a BinaryManager from the speech-to-text config.
func (*BinaryManager) EnsureBinary ¶ added in v0.178.0
EnsureBinary returns the local path to the named binary under ~/.infer/bin, downloading it (checksum-verified) on first use when auto_download is enabled. An existing file is returned as-is.
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
SetBinaryEnsurer installs a fallback that resolves (downloading if needed) a named binary when it is not found on PATH.
type FileTranscriber ¶ added in v0.178.0
type FileTranscriber struct {
// contains filtered or unexported fields
}
FileTranscriber transcribes an arbitrary audio file by first converting it to 16kHz mono WAV with ffmpeg, then running Whisper. It is used for Telegram voice messages (OGG/Opus), which must be decoded before transcription.
func NewFileTranscriber ¶ added in v0.178.0
func NewFileTranscriber(cfg config.SpeechToTextConfig) *FileTranscriber
NewFileTranscriber creates a FileTranscriber from the speech-to-text config.
func (*FileTranscriber) TranscribeFile ¶ added in v0.178.0
TranscribeFile converts audioPath to WAV and returns its transcription. The intermediate WAV file is removed before returning.
type ModelManager ¶ added in v0.178.0
type ModelManager struct {
// contains filtered or unexported fields
}
ModelManager resolves and (optionally) downloads the GGML model file.
func NewModelManager ¶ added in v0.178.0
func NewModelManager(cfg config.SpeechToTextConfig) *ModelManager
NewModelManager creates a ModelManager from the speech-to-text config.
func (*ModelManager) EnsureModel ¶ added in v0.178.0
func (m *ModelManager) EnsureModel(ctx context.Context) (string, error)
EnsureModel returns the local path to the model file, downloading it on first use when AutoDownload is enabled. Downloads are cached; an existing file is returned as-is.
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 ¶
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 ¶
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.
type WhisperTranscriber ¶ added in v0.178.0
type WhisperTranscriber struct {
// contains filtered or unexported fields
}
WhisperTranscriber transcribes a 16kHz mono WAV file using whisper.cpp.
func NewWhisperTranscriber ¶ added in v0.178.0
func NewWhisperTranscriber(cfg config.SpeechToTextConfig) *WhisperTranscriber
NewWhisperTranscriber creates a transcriber from the speech-to-text config.
func (*WhisperTranscriber) EnsureAvailable ¶ added in v0.178.0
func (w *WhisperTranscriber) EnsureAvailable() error
EnsureAvailable reports whether the whisper binary can be resolved (possibly by downloading it), without transcribing or downloading a model. It lets callers fail fast (with an actionable install hint) before recording audio.
func (*WhisperTranscriber) Transcribe ¶ added in v0.178.0
Transcribe converts the audio at wavPath (16kHz mono WAV) into text.