download

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package download fetches speech.cpp's shared library and its models.

Library installs the libspeech release archive for a target (OS, architecture, backend) after checking it against the release's SHA256SUMS and, for the pinned release, against the module's own copy of that file. Model fetches a catalog model's weight file, checks its size and SHA-256, reports progress, and resumes an interrupted fetch.

Only the targets speech.cpp publishes archives for are supported: linux/amd64 (cpu, vulkan), darwin/arm64 (metal) and windows/amd64 (vulkan). Any other target returns ErrUnsupportedTarget; a library built by the caller can still be opened by path.

Index

Constants

View Source
const (
	// DialTimeout bounds opening a connection.
	DialTimeout = 30 * time.Second
	// TLSHandshakeTimeout bounds the TLS handshake.
	TLSHandshakeTimeout = 10 * time.Second
	// ResponseHeaderTimeout bounds the wait for a response's headers once the
	// request is sent.
	ResponseHeaderTimeout = 60 * time.Second
	// StallTimeout ends a download, with ErrStalled, when its body brings no
	// byte for this long.
	StallTimeout = 60 * time.Second
)

Timeouts of the default HTTP client. None of them bounds a download's total time, so a large model on a slow link is not cut off; a context deadline does that.

View Source
const PartialSuffix = ".partial"

PartialSuffix is appended to a model file's name while it downloads.

View Source
const PinnedVersion = "0.11.3"

PinnedVersion is the speech.cpp release this module is built against.

View Source
const RecordName = "speech-install.json"

RecordName is the file an install writes beside the library it extracted.

Variables

View Source
var (
	// ErrUnsupportedTarget means speech.cpp publishes no archive for the target.
	ErrUnsupportedTarget = errors.New("no published libspeech archive for this target")
	// ErrInvalidVersion means a version is not MAJOR.MINOR.PATCH.
	ErrInvalidVersion = errors.New("invalid speech.cpp version")
	// ErrIntegrity means bytes do not match their published size or SHA-256,
	// or the release's SHA256SUMS disagrees with the module's pinned copy.
	ErrIntegrity = errors.New("integrity check failed")
	// ErrNoChecksum means the release's SHA256SUMS does not list the archive.
	ErrNoChecksum = errors.New("no SHA-256 for the archive")
	// ErrUnsafeArchive means an archive entry escapes the destination, is too
	// large, or is a link or file type that is not allowed.
	ErrUnsafeArchive = errors.New("unsafe archive")
	// ErrBadArchive means the archive does not hold the shared library.
	ErrBadArchive = errors.New("archive does not hold libspeech")
	// ErrHTTPStatus means a server answered with an unexpected status.
	ErrHTTPStatus = errors.New("unexpected HTTP status")
	// ErrNotInstallDir means the destination holds files that are not a
	// libspeech install, so it is not replaced.
	ErrNotInstallDir = errors.New("destination is not a libspeech install directory")
	// ErrNotInstalled means a directory holds no complete libspeech install.
	ErrNotInstalled = errors.New("libspeech is not installed")
	// ErrInvalidFile means a model file description cannot be fetched safely.
	ErrInvalidFile = errors.New("invalid model file description")
	// ErrStalled means a download with the default HTTP client received no
	// byte for StallTimeout. A model's partial file is kept for the next call.
	ErrStalled = errors.New("download stalled")
)

Set of errors the package returns; test them with errors.Is.

Functions

func ArchiveName

func ArchiveName(version string, t Target) (string, error)

ArchiveName returns the release archive's file name for the target, e.g. "speech-0.11.3-macos-arm64-metal.zip"; an empty version means PinnedVersion.

func DefaultUserAgent

func DefaultUserAgent() string

DefaultUserAgent returns "speech-cpp-go/<module version>", or "speech-cpp-go/devel" when the version is not known.

func LibraryName

func LibraryName(goos string) (string, error)

LibraryName returns the file name of the shared library to open on goos, for libspeech's API major 4: libspeech.4.dylib, libspeech.so.4 or speech.dll. An install records the name it holds; see Install.Library.

func Model

func Model(ctx context.Context, name, weightType, dir string) (string, error)

Model downloads the catalog model name's file of weightType (the model's default type when empty) into dir and returns its path. See Client.File.

func ModelPath

func ModelPath(dir, name, weightType string) (string, error)

ModelPath returns where Model puts the catalog model name's file of weightType (the default type when empty) in dir.

func VerifyFile

func VerifyFile(path string, f catalog.File) error

VerifyFile checks that the file at path has f's size and SHA-256; a difference is ErrIntegrity, a missing file fs.ErrNotExist.

Types

type Backend

type Backend string

Backend is the compute backend a libspeech build uses.

const (
	BackendCPU    Backend = "cpu"
	BackendVulkan Backend = "vulkan"
	BackendMetal  Backend = "metal"
)

The backends speech.cpp publishes builds for.

type Client

type Client struct {
	// HTTPClient sends the requests. nil means a client of this package with
	// DialTimeout, TLSHandshakeTimeout and ResponseHeaderTimeout, and a body
	// that brings no byte for StallTimeout ends the download with ErrStalled;
	// none of them limits a download's total time. A client set here is used
	// as it is, with none of these: its own timeouts and the context apply.
	HTTPClient *http.Client
	// UserAgent is sent with every request; empty means DefaultUserAgent().
	UserAgent string
	// Progress, if set, is called as a download advances, at least every MiB
	// and once when it completes.
	Progress ProgressFunc
}

Client downloads libraries and models. The zero value is ready to use.

func (*Client) File

func (c *Client) File(ctx context.Context, f catalog.File, dir string) (string, error)

File downloads f into dir as dir/<f.Name> and returns that path.

A file already there with f's size and SHA-256 is kept; one that differs is replaced. The download is written to dir/<f.Name>.partial and resumed from there with an HTTP Range request; a server that ignores the range, refuses it, or answers another range, and a partial file larger than f, restart the download from the start. A cancelled or interrupted download keeps the partial file for the next call. Once the partial file has f's size, its bytes on disk are hashed before it is renamed into place: when they do not match f's SHA-256 the partial file is removed and ErrIntegrity returned.

func (*Client) Library

func (c *Client) Library(ctx context.Context, t Target, version, dir string) (Install, error)

Library is the package-level Library with c's settings.

func (*Client) Model

func (c *Client) Model(ctx context.Context, name, weightType, dir string) (string, error)

Model is the package-level Model with c's settings.

type Install

type Install struct {
	// Dir is the install directory; it is not stored in the record.
	Dir           string            `json:"-"`
	Version       string            `json:"version"` // speech.cpp release
	Target        Target            `json:"target"`
	Archive       string            `json:"archive"`
	ArchiveSHA256 string            `json:"archive_sha256"`
	Library       string            `json:"library"` // file name of the library to open
	Files         map[string]string `json:"files"`   // extracted file → SHA-256
	Links         map[string]string `json:"links,omitzero"`
	Installed     time.Time         `json:"installed,omitzero"`
}

Install describes a libspeech install, as recorded in its directory.

func Installed

func Installed(dir string) (Install, error)

Installed reads the install record in dir and checks that the library file it names is present. A directory with no record, or whose library is missing, is ErrNotInstalled. It is cheap: it hashes nothing, so a file changed since the install goes unnoticed; Install.Verify checks that.

func Library

func Library(ctx context.Context, t Target, version, dir string) (Install, error)

Library downloads the release archive of version (PinnedVersion when empty) for target t, checks it, and installs its shared library files into dir.

dir belongs to the install: it must not exist, be empty, or hold an earlier install (it has a RecordName file); anything else is ErrNotInstallDir. The archive is checked against the release's SHA256SUMS (and, for PinnedVersion, the module's pinned copy) before anything is extracted. Extraction goes to a new directory beside dir, which then replaces dir; a failure at any step leaves dir as it was. Two installs into the same dir at once are not supported.

func (Install) LibraryPath

func (i Install) LibraryPath() string

LibraryPath returns the path of the library to open.

func (Install) Verify

func (i Install) Verify() error

Verify hashes every file the install recorded and compares it with the record. A file that is missing, unreadable, or has another SHA-256 is ErrIntegrity naming the file; the first one found, in name order, is returned.

type ProgressFunc

type ProgressFunc func(done, total int64)

ProgressFunc receives the bytes done and the total of one download; total is -1 when the server does not say.

type Target

type Target struct {
	OS      string  `json:"os"`
	Arch    string  `json:"arch"`
	Backend Backend `json:"backend"`
}

Target is a platform a libspeech build runs on. OS and Arch use Go's names (runtime.GOOS, runtime.GOARCH).

func HostTarget

func HostTarget(backend Backend) Target

HostTarget returns the running platform with backend.

func Targets

func Targets() []Target

Targets returns the targets speech.cpp publishes archives for.

func (Target) Platform

func (t Target) Platform() (string, error)

Platform returns speech.cpp's name for the target, e.g. "macos-arm64-metal".

func (Target) String

func (t Target) String() string

String returns "os/arch/backend".

Directories

Path Synopsis
Package catalog is speech.cpp's model catalog for the pinned release, embedded in the module: each model's name, task, languages and weight files, and per file its Hugging Face URL pinned to a revision, size and SHA-256.
Package catalog is speech.cpp's model catalog for the pinned release, embedded in the module: each model's name, task, languages and weight files, and per file its Hugging Face URL pinned to a revision, size and SHA-256.

Jump to

Keyboard shortcuts

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