voice

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package voice carries speech both ways. Inbound, it transcribes voice notes with whisper.cpp; outbound, it renders replies with piper. Both run locally by shelling out, so no audio leaves the machine and there is no cloud speech API to key. A voice note becomes ordinary text in the session, and a spoken reply becomes an Opus clip a channel can send back.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Speaker

type Speaker struct {
	Bin    string // piper cli, default "piper"
	Model  string // path to a piper voice model, required
	FFmpeg string // encoder to opus, default "ffmpeg"
	// contains filtered or unexported fields
}

Speaker synthesizes with piper and packs the result as an Opus voice note. It runs piper to render a WAV, then encodes that to OGG/Opus with ffmpeg, which is the container messaging apps treat as a real voice note. Both steps are local, so nothing is sent to a cloud voice API.

func (*Speaker) Synthesize

func (s *Speaker) Synthesize(ctx context.Context, text string) ([]byte, string, error)

Synthesize renders text to speech in a scratch dir and returns the Opus bytes. The scratch dir is always cleaned up.

type Synthesizer

type Synthesizer interface {
	Synthesize(ctx context.Context, text string) (audio []byte, ext string, err error)
}

Synthesizer turns reply text into a speech clip. ext is the container of the returned bytes so a channel can label the upload.

type Transcriber

type Transcriber interface {
	Transcribe(ctx context.Context, audio []byte, ext string) (string, error)
}

Transcriber turns a speech clip into text. ext is the source container (".ogg", ".m4a", and so on) so the implementation can decode it.

type Whisper

type Whisper struct {
	Bin    string // whisper.cpp cli, default "whisper-cli"
	Model  string // path to a ggml model file, required
	FFmpeg string // decoder for non-wav input, default "ffmpeg"
	// contains filtered or unexported fields
}

Whisper transcribes with whisper.cpp. It writes the clip to a temp file, converts it to 16 kHz mono WAV with ffmpeg when the source is not already WAV (voice notes never are), then runs the whisper binary and reads back the transcript it writes as a sidecar text file.

func (*Whisper) Transcribe

func (w *Whisper) Transcribe(ctx context.Context, audio []byte, ext string) (string, error)

Transcribe writes the clip to a scratch dir, decodes it to WAV if needed, and runs whisper over it. The scratch dir is always cleaned up.

Jump to

Keyboard shortcuts

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