Documentation
¶
Overview ¶
Package audiocpp is a Go binding for audio.cpp's TTS engine, loaded in-process via purego (no cgo) over the extern "C" shim in shim/audiocpp_c.h. It mirrors a common purego binding approach.
The surface is deliberately small (nine C symbols), so — unlike sd-go, which splits a ~50-symbol API into pkg/sd + a root layer — the raw bindings and the ergonomic API live in one package here.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrDeviceAPIUnavailable is returned by the device functions when the loaded library predates the device registry (shim 0.2.0). Such a library still loads and synthesises; only these readings are missing.
Functions ¶
func DeviceID ¶ added in v0.2.0
DeviceID returns the lower-case PCI bus id ("0000:01:00.0") of the device at index where the backend knows it (CUDA, ROCm, Vulkan), else "". It names the same card under any tool's numbering. Like DeviceMemory it opens the device.
func EncodeWAV ¶
EncodeWAV encodes an Audio result as a 16-bit PCM WAV file (little-endian). A convenience for callers/examples; the worker ships base64 WAV to the API.
func HasDeviceAPI ¶ added in v0.2.0
func HasDeviceAPI() bool
HasDeviceAPI reports whether the loaded library has the device registry. False before Load, and for a library older than shim 0.2.0.
func Load ¶
Load resolves and dlopens the audiocpp shared library from libDir (an empty libDir falls back to the OS default search path). It is idempotent, safe for concurrent use, and returns an error — never panics — when the library is absent or a symbol is missing, so importing this package or calling Load with no library present keeps the caller healthy.
Types ¶
type Device ¶ added in v0.2.0
type Device struct {
// Index is the device's position in the library's device list, as returned
// by Devices. It is what DeviceMemory takes and is fixed for the process.
Index int
// Backend is the ggml registry name: "CUDA", "Vulkan", "MTL", "ROCm", "CPU".
Backend string
// BackendIndex is the index within Backend — the value ModelParams.Device
// takes. For CUDA it is CUDA's own device ordinal, which is not nvidia-smi's
// index (CUDA orders fastest first unless CUDA_DEVICE_ORDER says otherwise,
// and CUDA_VISIBLE_DEVICES renumbers). DeviceID names the card itself.
BackendIndex int
// Name is ggml's device handle, e.g. "CUDA0".
Name string
// Description is the hardware name, e.g. "NVIDIA GeForce RTX 4090".
Description string
// Type is the device kind. CUDA reports DeviceTypeGPU for every device,
// shared-memory ones (DGX Spark, Jetson) included.
Type DeviceType
}
Device describes one device in the library's own ggml registry. The library links ggml statically and hides it, so this is the only view of the devices — and the device numbering — a loaded speech model actually uses.
func Devices ¶ added in v0.2.0
Devices lists the devices the library can run a model on, in the library's own order (Devices()[i].Index == i). The list is fixed for the life of the process, so callers may cache it. Safe for concurrent use, including during a Synthesize. Listing runs the backend start-up the first synthesis would run anyway, and does not read from the devices.
func ResolveDevice ¶ added in v0.2.0
ResolveDevice returns the device a model loaded with ModelParams.Backend backend and ModelParams.Device device runs on, resolved the way the engine resolves them ("" is "cpu"; "best" is the first GPU, else the first integrated GPU, else the CPU; both ignore device). It needs no loaded model, so a caller can pick the device to watch before New. An unknown backend, or a device this library does not have, is an *Error with the bad-argument code.
type DeviceType ¶ added in v0.2.0
type DeviceType int
DeviceType is the kind of a device, mirroring ggml's ggml_backend_dev_type.
const ( DeviceTypeCPU DeviceType = 0 // host CPU, system memory DeviceTypeGPU DeviceType = 1 // GPU with its own memory DeviceTypeIGPU DeviceType = 2 // integrated GPU sharing host memory DeviceTypeAccel DeviceType = 3 // accelerator used alongside the CPU backend DeviceTypeMeta DeviceType = 4 // wrapper over several devices )
func (DeviceType) String ¶ added in v0.2.0
func (t DeviceType) String() string
type Error ¶
Error is a synthesis or load failure from the engine. Code is the coarse shim status (see the shim's audiocpp_status); Msg is the engine's free-text message. The whole point of the in-process binding over the old HTTP path is that this arrives synchronously — no status code to re-parse off a response.
type Memory ¶ added in v0.2.0
Memory is a device's free and total memory in bytes, as the backend reports it. CUDA reports the whole card, so every process's use counts; Metal and Vulkan report this process's budget less this process's use (and Vulkan reports FreeBytes == TotalBytes on a driver without VK_EXT_memory_budget). Both are zero when the backend has no reading.
func DeviceMemory ¶ added in v0.2.0
DeviceMemory reads the free and total memory of the device at index (a Device.Index) now. It is not a per-model figure: a model's share is the drop in FreeBytes across its load and its first synthesis — the engine allocates on the device at the first synthesis, not at load. The CPU device reports FreeBytes == TotalBytes except on Windows, so it cannot show a drop. Safe for concurrent use, including during a Synthesize.
Reading opens the device: on CUDA it creates this process's context on that GPU if there is none yet (a few hundred MB of its memory), so read the model's device rather than every device. A CUDA driver error during the read aborts the process, as it does inside the engine.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is a loaded TTS model. It is NOT safe for concurrent use — synthesise serially — hold one model behind a single-slot mutex. An internal mutex is kept only to prevent a use-after-free race between Synthesize and Close, not to enable parallelism.
func New ¶
func New(p ModelParams) (m *Model, err error)
New loads a model. The returned Model must be Close()d to free native memory.
func (*Model) Device ¶ added in v0.2.0
Device returns the device the model was loaded for: ResolveDevice for its backend and device. (A model may still keep some of its parts on the CPU.) It does not touch the native model, so it is safe during a Synthesize and after Close.
func (*Model) Synthesize ¶
func (m *Model) Synthesize(p SynthParams) (a *Audio, err error)
Synthesize turns text into audio. Safe against a concurrent Close (returns an error if the model is closed); concurrent Synthesize calls are serialized.
type ModelParams ¶
type ModelParams struct {
ModelPath string // path to the GGUF (required)
FamilyHint string // audio.cpp family, e.g. "qwen3_tts"
Backend string // "cpu"|"metal"|"cuda"|"vulkan"|"hip"|"best" ("" == cpu)
Device int // GPU device index
Threads int // CPU threads (<=0 -> engine default)
LoadOptions map[string]string // extra load-time options
}
ModelParams configures a model load.
type SynthParams ¶
type SynthParams struct {
Task string // "tts" (default) | "voice_design" | "voice_clone"
Text string // text to speak (required)
VoiceID string // preset speaker id, e.g. "ryan"
RefPCM []float32 // reference-audio voice (mono f32); alternative to VoiceID
RefSampleRate int // sample rate of RefPCM
Options map[string]string // per-request options (instruct, seed, temperature, ...)
}
SynthParams configures one synthesis call.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
tts
command
Command tts is a minimal end-to-end example: load a model and synthesise a WAV, exercising the Go -> shim -> engine path end to end.
|
Command tts is a minimal end-to-end example: load a model and synthesise a WAV, exercising the Go -> shim -> engine path end to end. |