speech

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 60 Imported by: 0 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

Speech: the voices that read text aloud, the recognizers that turn speech into text and the engines that hear a wake word, each a plugin, with the pipelines every surface shares around them

Index

Constants

View Source
const (
	ListenHeard     = "heard"
	ListenCancelled = "cancelled"
	ListenFailed    = "failed"
	ListenTimeout   = "timeout"
)

How a fed live transcription ended: its final transcript heard, cancelled, failed, or out of time

View Source
const (
	InUse        = "In use"
	Ready        = "Ready"
	Free         = "Free"
	NotInstalled = "Not installed"
	NeedsKey     = "Needs an API key"
	NeedsSignIn  = "Needs a sign-in"
	CantRun      = "Can't run here"
)

State words of a service, the same on every page and in every sentence; Needs and a program, such as Needs espeak-ng, besides

View Source
const Agent = "icebath/speech"

Agent every service of speech is told

View Source
const BodyCap = 16 << 20

Largest reply body a speech service may send

View Source
const FinishTimeout = 20.0

Seconds a live session waits for its final transcript once the audio ends

View Source
const LiveRate = 16000

Rate live sessions are fed at

View Source
const None = "none"

Name the recognizer in use takes when none can transcribe

View Source
const OpenAIAudioKey = "VOICE_TOOLS_OPENAI_KEY"

Variable OpenAI's audio services prefer over the general OpenAI key, kept apart from routers that take OPENAI_API_KEY

View Source
const OpenAIBase = "https://api.openai.com/v1"

Address of OpenAI's API, where an audio client goes when given none

View Source
const ShortEspeak = `` /* 563-byte string literal not displayed */

Python of a local engine that moves eSpeak NG data under a short path, as its C library fails on data paths of 160 bytes or more

View Source
const UploadCap = 25 << 20

Largest upload of the cloud services that state none of their own

View Source
const WakeRate = 16000

Sample rate every wake engine hears, 16 kHz mono 16 bit

Variables

View Source
var Fires = []hooks.Site{
	{Point: hooks.PreTranscription, By: "speech", When: "before a recording is turned into text"},
}

The moments of speech the hook points hear of, which the hooks screen and Doctor say of each point

View Source
var WhisperModels = []string{"base", "tiny", "small", "medium", "large-v3", "turbo"}

Sizes of the Whisper model a local engine runs, the first the default

Functions

func Absent

func Absent(message string) error

func Base64

func Base64(text string) ([]byte, error)

Bytes of base64 text in the standard or the URL alphabet, white space skipped and the padding optional, as services send audio

func Base64Std

func Base64Std(text string) ([]byte, error)

Bytes of base64 text in the standard alphabet read leniently: any other character dropped and the padding made whole after its first sign; text cut short of a whole quantum refused

func Body

func Body(response *http.Response, label string, limit int) ([]byte, error)

A reply body read under the cap, the reply closed

func Chosen

func Chosen(cfg *config.Config, key string) string

Chosen returns the service the setting picks, in normal form.

func Chunks

func Chunks(body io.ReadCloser, size int, fill bool) iter.Seq2[[]byte, error]

Pieces of a reply body as they arrive, at most size bytes each and exactly size when filled but for the last, the body closed after

func Client

func Client(env httpx.Env, timeout time.Duration) *http.Client

Client through the proxy and authorities of the environment, the profile's, none meaning no proxy and the system's authorities, whose connect, TLS and first byte each get the timeout

func Container

func Container(head []byte) string

Container of audio bytes by their magic, empty when they match none

func Decoded

func Decoded(data []byte) string

Text of a command's output decoded as the whisper programs write it, a byte order mark dropped

func Detail

func Detail(captured *terminal.Captured, err error) string

What a failed helper said, its error output first, then its output, else the error itself

func Echo

func Echo(transcript, spoken string) bool

Whether a transcript reads as the speaker's own sound picked up again: alike with what was spoken as a whole, or with a stretch of it

func Failed

func Failed(response *http.Response) error

The failure of a 4xx or 5xx reply, its body read and closed, nil for any other

func Field

func Field(event map[string]any, key string) string

Text of an event field, empty when it is missing or empty

func Flag

func Flag(event map[string]any, key string) bool

Whether an event field is true

func Form

func Form(parts []Part) ([]byte, string, error)

Multipart body of the parts and its content type

func Hallucination

func Hallucination(transcript string) bool

Whether a transcript is empty or what Whisper is known to hear in silence

func Held

func Held(value any) bool

Whether a JSON value holds something: not null, false, zero, empty text, an empty list or an empty object

func IsConfig

func IsConfig(err error) bool

Whether the error is the configuration error of a service

func Key

func Key(section, name string) string

Settings key a service keeps one of its values under

func Kind

func Kind(value any) string

What a JSON value is, as a refusal of a reply of the wrong shape names it

func MediaType

func MediaType(path string) string

Media type of a file by its extension, this machine's table for those speech has none of, application/octet-stream when unknown

func Misconfigured

func Misconfigured(message string) error

Refusal naming what to set

func Normal

func Normal(name string) string

Lower case name with its spaces trimmed, as the settings name services

func Number

func Number(value any) float64

Float of a setting's value, the integers and text YAML gives included

func Object

func Object(response *http.Response, label string) (map[string]any, error)

A JSON object of a reply body read under the cap, empty for an empty body

func PCMBytes

func PCMBytes(in []int16) []byte

Little endian bytes of samples

func PostJSON

func PostJSON(ctx context.Context, env httpx.Env, url string, payload any, headers map[string]string) (*http.Response, error)

A JSON body posted through the proxy and authorities of the environment, the profile's, with a 60 second bound on each phase

func Prefix

func Prefix(text string, n int) string

First n characters of text, any bytes that are no text shown as �, such as of the body of a failed reply

func PromptIgnored

func PromptIgnored(label string)

Line kept of a log of what a prompt did, the backend ignoring prompts

func Raised

func Raised(kind, message string) error

Failure a Python engine answered, read by the kind of error it raised: a bad value a configuration error, a missing file a missing dependency

func Render

func Render(template string, values map[string]string) string

A command template with each {name} or {{name}} placeholder put in quoted for where it sits, ${name} left to the shell, and the other doubled braces made single

func ResponseFormat

func ResponseFormat(path string) string

Format of an OpenAI style speech reply the path's extension asks for: opus for .ogg, wav, flac, else mp3

func Run

func Run(ctx context.Context, argv []string, timeout time.Duration, env []string) (*terminal.Captured, error)

Runs a helper program with its output captured in the environment given, such as a job's Environ, this machine's variables alone when nil as Capture takes them: an error naming it for a failure, a non-zero exit or a time out

func Save

func Save(response *http.Response, path, label string) (string, error)

Writes a reply body to a file under the cap, the reply closed

func Seconds

func Seconds(value any, unit time.Duration) float64

Seconds a length of time holds: a number counts the unit, text such as 500ms or 2m is read as a length

func Send

func Send(ctx context.Context, env httpx.Env, method, url string, body []byte, headers map[string]string, timeout time.Duration) (*http.Response, error)

A request sent with the headers through the proxy and authorities of the environment, the profile's, its connect, first byte and every quiet stretch of its body each bounded by the timeout

func SocketURL

func SocketURL(base, suffix, query string) string

Websocket address of a base URL with a path and query, wss for an https base

func Split

func Split(text string, limit int) []string

Splits text under the cap at sentence punctuation, an over long sentence at its words and then hard, nothing dropped but repeated space

func Spoken

func Spoken(text string, limit int) string

Spoken script of text an assistant wrote: reasoning blocks, markdown, symbols, identifiers and layout turned into what a voice reads well, cut to limit characters when the limit is positive

func StopPhrase

func StopPhrase(phrases []string, transcript string) bool

Whether the whole utterance, its punctuation trimmed, is one of the stop phrases

func StopPhrases

func StopPhrases(cfg *config.Config) []string

Stop phrases of a profile, lower case with blanks dropped

func TagRules

func TagRules(extra string) string

Rules of a tag rewrite with the tail every prompt ends with

func Text

func Text(value any) string

Text of a value as JSON gives it

func Transcribed

func Transcribed(path, via, model string, text string)

Log line of a transcription

func TranscriptOf

func TranscriptOf(reply any) (string, error)

Plain transcript of a reply that is text, an object with text, or another value; an object without text fails with its error

func Upload

func Upload(ctx context.Context, env httpx.Env, url string, parts []Part, headers map[string]string, timeout time.Duration) (*http.Response, error)

A multipart upload through the proxy and authorities of the environment, the profile's, with a bound on each phase

func VoiceNoteType

func VoiceNoteType(format string) string

Media type of the kind of voice message whose files end so, empty for a kind ffmpeg makes none of

func WAV

func WAV(pcm []byte, rate, channels, width int) []byte

Raw little endian PCM in a RIFF WAV

func WAVPath

func WAVPath(output string) string

Path a native engine writes WAV to before it becomes the requested container

func WakePhrase

func WakePhrase(cfg *config.Config) string

The wake phrase in effect for the profile, the one every page, message and listener says: its own, else hey and the profile's name while each profile has its own phrase, the profile icebath starts with keeping hey icebath, else hey icebath

func WhisperLanguage

func WhisperLanguage(language string, supported []string) string

Whisper code of a language hint such as en-US, empty with a warning when it is not a code, or not one of those supported when they are known

func WhisperModel

func WhisperModel(model string) string

Model a local Whisper engine runs: base for none, and for a cloud only name with a warning

Types

type APIError

type APIError struct {
	Status int
	Body   any
}

Failed status of an OpenAI style API, worded as its SDK words it

func (*APIError) Error

func (e *APIError) Error() string

The status and what the service said, its own message when the body carries one

type AbsentError

type AbsentError struct{ Message string }

A local engine is not installed: its text is the whole answer, with the way to install it

func (*AbsentError) Error

func (e *AbsentError) Error() string

type Asset

type Asset struct {
	Name   string
	URL    string
	SHA256 string
	Size   int64
}

One file speech fetches on first use, such as a voice or a model, pinned by its sha256

type Call

type Call struct {
	Text       string
	OutputPath string
	// Speed asked for, nil for none
	Speed        *float64
	Instructions string
	// Voice of the call, for a voice that lets the model pick
	Voice string
	// The text is speech text already, as Spoken gives it, and is read as it is
	Speech bool
}

What one text_to_speech call asks

type Catalog

type Catalog struct {
	// Setting that keeps the voice a person picked
	Setting string
	// The model may pick a voice for each call
	Picks bool
	// What the voices are of, as the model is told it, such as Narrator of the extension acme
	Title string
	// One page of the voices a search finds
	Find func(ctx context.Context, job *Job, search Search) (Page, error)
}

Voices a voice speaks with, one catalog the host offers twice: as the list a person picks the voice its setting keeps from on its page in Voice, and to the model, which may pick one for each call with voice_id after it searched them with find_voices

type Chats

type Chats interface {
	// The chat apps of the profile of the settings as choices, by the name the sessions of each record as their source
	ChatApps(cfg *config.Config) []config.Option
	// How the names of the files the app of the name plays as voice messages end, such as ogg, m4a or amr; empty for an app that says
	// none
	VoiceFormat(cfg *config.Config, app string) string
}

Registrant that connects chat apps, which says which apps there are and the kind of file each plays as a voice message: the settings of speech name every app where they keep something for each, and what is read aloud for an app is made a voice message it plays

type Choices

type Choices struct {
	Setting string
	// Values in the order offered, the setting's own value among them or not; none, with why, when they can't be listed now
	List func(ctx context.Context, job *Job) ([]Pick, error)
}

Values a person may pick for one setting of a service on its page in Voice, listed when the list is opened

func Fixed

func Fixed(setting string, values ...string) Choices

Fixed values of a setting

func Listed

func Listed(setting string, list func(ctx context.Context, job *Job) []string) Choices

Values of a setting read when the list is opened, such as the models a catalog holds

type Chunker

type Chunker struct {
	Least int
	// contains filtered or unexported fields
}

Reads a streamed reply out as speech text a sentence at a time, sentences shorter than the least merged into the next. The reply is never cleaned piece by piece: each time a sentence may have ended, the whole reply so far is cleaned as Spoken cleans it, to its last space, and the sentences that cleaning completes beyond what was handed out are handed out, a sentence once the word after it came, since only that word settles how it ends. A span of markup the cut falls inside is taken out as Spoken takes out one that never closes, so no markup is read whatever the cut, and the speech of a reply streamed in pieces is the speech Spoken gives the whole reply, cut at the same places

func NewChunker

func NewChunker(least int) *Chunker

func (*Chunker) Feed

func (c *Chunker) Feed(delta string) []string

Absorbs a delta and answers every sentence of speech it completes

func (*Chunker) Flush

func (c *Chunker) Flush() []string

Answers the rest of the speech of the whole reply

func (*Chunker) Spill

func (c *Chunker) Spill(over int) []string

Hands out the speech held back but its last word when more than over characters of it wait, for a reply that pauses mid-sentence

type ConfigError

type ConfigError struct{ Message string }

Settings or credentials keep a service from running: its text tells the person what to set

func (*ConfigError) Error

func (e *ConfigError) Error() string

type ConnectionError

type ConnectionError struct {
	Timeout bool
	Err     error
}

A connection to the API that broke, or a try that ran out of time

func (*ConnectionError) Error

func (e *ConnectionError) Error() string

func (*ConnectionError) Unwrap

func (e *ConnectionError) Unwrap() error

type Delivery

type Delivery struct {
	Platform     string  `json:"platform"`
	MaxFileBytes int     `json:"max_file_bytes"`
	SafetyRatio  float64 `json:"-"`
	TargetBytes  int     `json:"target_file_bytes"`
}

Upload limits of the chat app speech goes to

type DependencyError

type DependencyError struct{ Message string }

Something a service needs on this machine is missing, such as a file a local engine reads

func (*DependencyError) Error

func (e *DependencyError) Error() string

type Endpointed

type Endpointed interface {
	Live
	Ended() <-chan struct{}
}

A live session whose recognizer hears where the speaker stopped, which ends a recording there rather than at the silence the microphone hears; a recognizer that does not leaves the end to the recording. Ended is closed once it heard the speaker stop

type Engine

type Engine struct {
	// As wake_word.provider names it, and the other names that pick it
	Name    string
	Aliases []string
	Title   string
	About   string
	// Place in the automatic choice when a model file is set, lower first
	Rank int
	// Detects any phrase, so it is the automatic choice when no model file is set
	Open bool
	// Python set whose native library it runs, empty for one that runs on icebath's own speech engine
	Extra string
	// Whether this machine has a build of it at all
	Supported func(s *Speech) bool
	// Whether what it runs is installed now with its settings by key, never installing anything
	Installed func(s *Speech, settings map[string]string) bool
	// Downloads what it runs onto this computer, saying each step, for an engine whose install is a download rather than a Python set;
	// what it would otherwise fetch the first time it listens
	Fetch func(ctx context.Context, wake *Wake, say func(step string)) error
	// Setting of the model file it needs set, empty for an engine that needs none
	Model string
	// Needs the Picovoice access key of the profile's environment
	Key bool
	// Builds the detector of the wake settings
	New func(ctx context.Context, wake *Wake) (Hotword, error)
}

An engine that hears a wake word, what a speech plugin registers; it runs where the microphone is

type ExitError

type ExitError struct {
	Command        string
	Code           int
	Stdout, Stderr string
}

A program of yours that exited with a failure

func (*ExitError) Detail

func (e *ExitError) Detail() string

What a failed program said, its error output and output labelled, else that it said nothing

func (*ExitError) Error

func (e *ExitError) Error() string

type Fed

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

A live transcription fed to a recognizer that hears in feeds, such as one of an extension: the audio sent in order on one worker, all that came while a feed was out going in the next, so a slow recognizer gets larger feeds and never two at once; the partial text the final words so far and the interim ones after them; the end of the speech said where the recognizer hears it

func Feeding

func Feeding(ctx context.Context, provider string, partial func(string), feed Feeder, abandon func()) *Fed

Live transcription of the recognizer named provider fed through feed, its partial text handed to partial as it changes; abandon, when given, is told once it is given up. Its worker starts at once on a context of its own, the caller's own ending none of it

func (*Fed) Cancel

func (f *Fed) Cancel()

Stops the transcription, which finishes as cancelled

func (*Fed) Done

func (f *Fed) Done() <-chan struct{}

Closed once the transcription ended

func (*Fed) Ended

func (f *Fed) Ended() <-chan struct{}

Closed once the recognizer heard the speaker stop, which ends a recording there rather than at the silence the microphone hears

func (*Fed) Finish

func (f *Fed) Finish(timeout float64) Transcript

Ends the audio and waits for the final transcript, giving the transcription up after the seconds

func (*Fed) How

func (f *Fed) How() (string, time.Duration)

How the transcription ended, once it did: heard, cancelled, failed or timeout; and how long it lasted

func (*Fed) Push

func (f *Fed) Push(pcm []byte)

Queues audio, dropped once the audio ended or the transcription did

type Feeder

type Feeder func(ctx context.Context, pcm []byte, end bool) (Hearing, error)

Hands a recognizer the audio of a live transcription in order, one feed at a time: the audio spoken since the last feed, and whether the audio ended, a feed of none after the end asking for what is left; answered with what it heard since

type Hearing

type Hearing struct {
	Words    []Words
	Ended    bool
	Done     bool
	Text     string
	NoSpeech bool
}

What one feed of a live transcription heard: the words since the last feed, each interim one replacing the interim words before it and each final one kept; whether the recognizer heard the speaker stop; and once it finished after the end of the audio, the whole text it heard, empty to take the final words, and whether nothing was said

type Hindrance

type Hindrance struct {
	// A clause, such as Local Whisper is not installed
	Cause string
	Lack  Lack
	// Service it is about, empty for none in particular
	Service string
	// Command that installs the program of the system it lacks
	Install string
}

What keeps a part of voice from working: what is wrong in a person's words, and the kind of thing that fixes it

func (*Hindrance) Remedy

func (h *Hindrance) Remedy(place string) string

What to do about it, for a sentence that can't open the place it is done in and names that place instead

func (*Hindrance) Sentence

func (h *Hindrance) Sentence() string

Cause as a sentence of its own

type Hints

type Hints struct {
	Model    string
	Language string
	Prompt   string
}

What one transcription is told besides the audio

type Hotword

type Hotword interface {
	FrameLength() int
	// Whether the frame completes the wake word
	Process(frame []int16) (bool, error)
	// Forgets what it heard, so audio from before a pause cannot fire
	Reset() error
	Close()
}

Hotword detector over 16 kHz frames

type Job

type Job struct {
	Speech *Speech
	Config *config.Config
	// Helper models, for the tags some voices add to text; those of the profile when the job runs in no session
	Aux *auxiliary.Client
	// Surface the speech is delivered on, such as telegram, which takes Ogg Opus voice bubbles; empty for this machine
	Platform string
	// Why a file the job is asked to write, or to read, may not be touched, such as a credential store; nil where nothing guards paths
	Unwritable, Unreadable func(path string) string
	// contains filtered or unexported fields
}

What one piece of speech work is done for: the profile, its helper models and the surface the result goes to

func (*Job) AbsentPrograms

func (j *Job) AbsentPrograms(programs []string) []Program

Programs among those named that the search path of the profile's environment lacks, each with the command that installs it

func (*Job) AudioCache

func (j *Job) AudioCache() string

Folder generated speech is kept in, the profile's audio cache

func (*Job) Automatic

func (j *Job) Automatic(ctx context.Context) (Recognizer, Standing, bool)

Recognizer Automatic stands for now: the first that is ready of the local engines and then the cloud services, by their rank

func (*Job) CanSpeak

func (j *Job) CanSpeak() bool

Whether the voice the profile speaks with can run now, never installing anything; a name no voice has can't

func (*Job) Compact

func (j *Job) Compact(ctx context.Context, path, work string) (string, string)

Compact 16 kHz mono copy of audio for an upload, or why it could not be made

func (*Job) Duration

func (j *Job) Duration(ctx context.Context, path string) (float64, bool)

Seconds of audio a file holds as ffprobe reads it, false when it can't

func (*Job) Environ

func (j *Job) Environ(extra map[string]string) []string

Environment of a program speech runs for the profile: its own, without the credentials programs may not see, extra on top

func (*Job) FFmpeg

func (j *Job) FFmpeg(ctx context.Context) string

ffmpeg of this machine, empty when there is none

func (*Job) FFprobe

func (j *Job) FFprobe(ctx context.Context) string

ffprobe beside ffmpeg, else of this machine, empty when there is none

func (*Job) Float

func (j *Job) Float(key string) float64

Number setting as a float, the integers YAML gives included

func (*Job) For

func (j *Job) For(ctx context.Context) *Job

The job, for the request of the context given: its calls renew a sign-in under that context

func (*Job) FromWAV

func (j *Job) FromWAV(ctx context.Context, wav, output string) (string, error)

Moves the WAV an engine wrote into the requested container, converted with ffmpeg, renamed as it is without one

func (*Job) Getenv

func (j *Job) Getenv(name string) string

Variable of the profile's environment: its own, its .env, its secret stores, then this process's

func (*Job) Helper

func (j *Job) Helper(ctx context.Context, extra string, args []string, timeout time.Duration) (string, string, int, error)

Runs a helper script in the interpreter of a provisioned Python set to its end within the timeout, its output captured

func (*Job) Key

func (j *Job) Key(variable string, kinds ...string) string

Key of a service: the variable of the profile's environment, else the account of a provider of a kind the profile connected

func (*Job) Limit

func (j *Job) Limit(voice Voice) int

Characters one request to a voice takes: its own setting, then what the voice says, else 4000

func (*Job) Listen

func (j *Job) Listen(ctx context.Context, partial func(string)) (Live, string, error)

Live transcription session of the recognizer in use, nil when stt.streaming is off or it transcribes whole files only

func (*Job) Missing

func (j *Job) Missing(ctx context.Context, r Recognizer) string

Why the recognizer can't transcribe with the profile's settings now, empty when it can

func (*Job) OpenAIKey

func (j *Job) OpenAIKey() string

Key of OpenAI's speech and transcription: the voice key, then the OpenAI key or account

func (*Job) OpenAITranscribe

func (j *Job) OpenAITranscribe(ctx context.Context, r Recognizer, client OpenAI, path, model string, hints Hints, label string) Transcript

Transcribes through an OpenAI style transcriptions API with the language and prompt hinted; a file the API refuses as unsupported, corrupted or invalid, or that a failing service could not take, is sent once more transcoded to compact m4a

func (*Job) Opus

func (j *Job) Opus(ctx context.Context, source, output string) string

Encodes audio ffmpeg reads into voip tuned Ogg Opus at the path, in place when it is the source; empty when ffmpeg is missing or fails

func (*Job) Passed

func (j *Job) Passed(names []string) map[string]string

Variables of the profile's environment by name, those set

func (*Job) Provider

func (j *Job) Provider(kind string) string

Provider of the profile of a kind, by its name in the profile; empty while the profile has none. A reading looks each kind up once

func (*Job) Provisioned

func (j *Job) Provisioned(extra string) bool

Whether a provisioned Python set is there, looked up once by a reading

func (*Job) Python

func (j *Job) Python(extra string) (string, error)

Interpreter of a provisioned Python set of a local engine, the refusal saying where to install it when it is not installed

func (*Job) Ready

func (j *Job) Ready(v Voice) bool

Whether the voice can speak with the profile's settings now

func (*Job) Recognition

func (j *Job) Recognition(ctx context.Context) Recognition

The one answer to which recognizer turns the profile's speech into text and what keeps it from it: speech to text switched off, the service chosen and what it lacks, or none chosen and none ready. A chosen service that can't run stays the one named, so what it lacks is what is said

func (*Job) RecognizerStanding

func (j *Job) RecognizerStanding(ctx context.Context, r Recognizer) Standing

How the recognizer stands for the profile, asked once by a reading

func (*Job) Recognizing

func (j *Job) Recognizing(ctx context.Context) string

Recognizer that transcribes now, None while something keeps speech from being turned into text

func (*Job) Recording

func (j *Job) Recording(ctx context.Context, path string) Transcript

Transcription of a voice recording, a known hallucination on silence read as nothing said unless it is a stop phrase

func (*Job) RenewXAI

func (j *Job) RenewXAI(ctx context.Context) error

Renews the Grok sign in of the profile after xAI refused a call made with it

func (*Job) Scratch

func (j *Job) Scratch() string

Folder the job's passing files go in, such as a recording a window sent to be transcribed or speech on its way to a file: the profile's scratch folder, where its commands' TMPDIR points, so those of one profile never sit where another's do; empty, the system's own, when it can't be made

func (*Job) Seconds

func (j *Job) Seconds(key string, unit time.Duration) float64

Seconds a setting kept as a plain number holds: its number counts the unit, text such as 500ms or 2m is read as a length. A setting declared a length of time is read with Config.GetDuration, by its own unit

func (*Job) Settle

func (j *Job) Settle(t Transcript) Transcript

A recording's transcript with what Whisper hears in silence read as nothing said, a stop phrase kept

func (*Job) Shell

func (j *Job) Shell(ctx context.Context, command string, timeout time.Duration, passthrough []string, purpose string) (string, string, error)

Runs a command line of yours through the shell, in a group of its own that dies with icebath, without the credentials programs may not see but with the variables it passes through; its whole tree killed once it writes nothing for the timeout

func (*Job) SilkToWAV

func (j *Job) SilkToWAV(ctx context.Context, source, output string, rate int) error

Decodes a SILK voice note of QQ or WeChat to WAV at the sample rate with pilk

func (*Job) Speak

func (j *Job) Speak(ctx context.Context, text string, live bool, sink Sink) error

Speaks one sentence of speech text for the app to play: as PCM while it is made when asked and a voice streams, else as the files text_to_speech writes, each sent as a clip and removed. The app cleaned the sentence with the whole of its reply, as Spoken does, so it is read as it is: cleaning a sentence alone again would read it unlike the reply it was cut from

func (*Job) Speaker

func (j *Job) Speaker() Voice

Voice the profile speaks with, for the tool's schema

func (*Job) Speaking

func (j *Job) Speaking() Speaking

The one answer to which voice reads the profile's replies aloud and what keeps it from it: a name no voice has, or what the voice lacks

func (*Job) Speed

func (j *Job) Speed(request Request, own string) (float64, bool)

Speed returns the call's speed, else the service's speed setting, else tts.speed.

func (*Job) Streams

func (j *Job) Streams() bool

Whether the profile's speech streams as PCM while it is made

func (*Job) Tagged

func (j *Job) Tagged(ctx context.Context, system, prompt, fallback, label, instead string, level zerolog.Level) string

Text of a voice rewritten by the speech tags model under the system prompt, the fallback when the call fails or comes back empty; a failure is logged at the level given

func (*Job) Text

func (j *Job) Text(key, fallback string) string

Text setting of a service with its spaces trimmed, the fallback when it is empty

func (*Job) TextToSpeech

func (j *Job) TextToSpeech(ctx context.Context, call Call) Outcome

Speaks text into audio files for the model and the chat apps: text cleaned for speech and split under the voice's limit, each piece written, the files packed under the platform's upload limit and named by the media tag

func (*Job) Transcribe

func (j *Job) Transcribe(ctx context.Context, path, model, source string) Transcript

Transcribes an audio file with the recognizer in use: the file checked, a SILK note decoded, Apple's CAF converted for a cloud service, silence trimmed before an upload and a file too large for one request split at its pauses

func (*Job) Unsupported

func (j *Job) Unsupported(extra string) string

Why a Python set can't run on this computer, empty when it can or no feature declares it; looked up once by a reading

func (*Job) VoiceNote

func (j *Job) VoiceNote(ctx context.Context, source, format string) (string, bool)

The recording as a file of the kind a chat app plays as a voice message, the kind named by how such a file ends: the file itself when it holds that already, else one made of it in the job's scratch folder, which is the caller's to delete. False where ffmpeg makes none of the kind, is missing, or fails

func (*Job) VoiceStanding

func (j *Job) VoiceStanding(v Voice) Standing

How the voice stands for the profile, asked once by a reading

func (*Job) Which

func (j *Job) Which(name string) string

Program of the name on the search path of the profile's environment, the one its programs run with; empty when there is none. A reading looks each name up once, on the search path it read once

func (*Job) Worker

func (j *Job) Worker(extra, script string, env map[string]string) (*Worker, error)

Starts the script in the interpreter of a provisioned Python set, its error output logged, with the variables given over the profile's

func (*Job) WriteWAV

func (j *Job) WriteWAV(ctx context.Context, wav []byte, output string) (string, error)

Writes WAV bytes under the path, converted with ffmpeg to the path's container and to voip Opus for .ogg, the raw WAV kept under the path's name without ffmpeg

func (*Job) XAI

func (j *Job) XAI(preferKey bool) (web.XAI, bool)

Bearer of direct calls to xAI and where they go: the API key first when preferred, else the Grok sign in first. A reading glances at each kind's credential as credential does; any other job renews the sign-in when due

type Lack

type Lack int

Kind of thing that fixes what keeps a part of voice from working

const (
	// Nothing a page of Voice does
	LacksNothing Lack = iota
	// Its Python set, which its page installs
	LacksInstall
	// An API key, which its page takes
	LacksKey
	// A sign-in at a provider
	LacksSignIn
	// A program of the system, which Install says how to install
	LacksProgram
	// A build for this computer, so another service is needed
	LacksBuild
	// A setting of its own, set on its page
	LacksSetup
	// The switch that turns it on
	LacksSwitch
	// A service: the one chosen does not exist, or none is chosen and none is ready
	LacksService
)

type Limit

type Limit struct {
	Bytes int64
	// Seconds of audio, 0 for no cap
	Seconds float64
}

Most one upload request may carry

type Live

type Live interface {
	Push(pcm []byte)
	// Ends the audio and waits for the final transcript, giving up after the seconds
	Finish(timeout float64) Transcript
	Cancel()
}

One live transcription session: 16 kHz mono PCM in, partial text out through the callback it was opened with, the final transcript once the audio ends

type Matcher

type Matcher interface {
	LastMatch() (phrase, profile string, ok bool)
}

Detector that tells which phrase, and so which profile, its last fire heard

type Model

type Model interface {
	Close()
}

Model of a local voice that holds memory until closed

type OpenAI

type OpenAI struct {
	Key     string
	BaseURL string
	// Tries after the first, and the limit of each try
	Retries int
	Timeout time.Duration
	// Environment of the profile the requests are for, which names their proxy and the authorities they trust: no proxy and the system's
	// authorities alone when nil
	Env httpx.Env
	// Headers every request carries under those of the call, such as OpenAI-Project
	Headers map[string]string
}

Audio endpoints of OpenAI and the services that copy them, such as Groq and DeepInfra, tried again as OpenAI's SDK tries

func SpeechClient

func SpeechClient(env httpx.Env, key, base string) OpenAI

Speech client of the profile's environment as OpenAI's SDK makes one: two tries after the first, ten minutes each

func (OpenAI) Speak

func (c OpenAI) Speak(ctx context.Context, r SpeechRequest) error

Writes the speech of the request to its path

func (OpenAI) Speech

func (c OpenAI) Speech(ctx context.Context, body map[string]any, headers map[string]string, path string) error

Writes the speech of a body POSTed to audio/speech to the path

func (OpenAI) SpeechStream

func (c OpenAI) SpeechStream(ctx context.Context, body map[string]any, headers map[string]string) (*http.Response, error)

Open reply of a body POSTed to audio/speech, for its audio to be read as it arrives

func (OpenAI) Transcription

func (c OpenAI) Transcription(ctx context.Context, path string, fields [][2]string) (any, error)

Transcription of a file POSTed to audio/transcriptions with the fields: the text for response_format text, else the reply's JSON

type Opus

type Opus int

How a voice gives Ogg Opus

const (
	// Gives none, its files sent as plain attachments
	NoOpus Opus = iota
	// Writes Ogg Opus itself when asked for an .ogg path
	NativeOpus
	// Its files are transcoded to Ogg Opus with ffmpeg where the platform shows voice bubbles
	TranscodedOpus
	// Opted in to voice bubbles, its files always transcoded to Ogg Opus, such as a program of yours marked voice_compatible
	OptedOpus
)

type Outcome

type Outcome struct {
	Success         bool      `json:"success"`
	Error           string    `json:"error,omitempty"`
	FilePath        string    `json:"file_path"`
	FilePaths       []string  `json:"file_paths"`
	MediaTag        string    `json:"media_tag"`
	Provider        string    `json:"provider"`
	VoiceCompatible bool      `json:"voice_compatible"`
	ChunkCount      int       `json:"chunk_count"`
	DeliveryFiles   int       `json:"delivery_file_count"`
	CombinedChunks  bool      `json:"combined_chunks"`
	DeliveryProfile *Delivery `json:"delivery_profile"`
	// contains filtered or unexported fields
}

Result of a speech synthesis, as the model reads it when it succeeded

func (Outcome) Result

func (o Outcome) Result() string

Result as the model reads it: a failure with its error cut to the error bound ahead of success, a refused output path whole after it

type PCM

type PCM struct {
	Rate   int
	Chunks iter.Seq2[[]byte, error]
	// Lets go of the speech once it is not read to its end, such as when the app could not take it; nil for speech that holds nothing
	Stop func()
}

type Page

type Page struct {
	Voices []Persona
	Next   string
	Total  int
}

One page of a catalog: its voices, the cursor of the next page, empty after the last, and how many voices the search finds in all, 0 when not known

type Part

type Part struct {
	Name, Value string
	// File to upload under the name, with its type, guessed from the extension when empty
	File, Type string
}

One field or file of a multipart form

type Persona

type Persona struct {
	ID, Name  string
	Languages []string
	Gender    string
	Styles    []string
	Rate      int
	About     string
	Preview   string
}

One voice of a catalog: the id a call or the setting names it by, the name a person knows it by, the languages it speaks as BCP 47 codes, its gender, the styles it speaks in, the samples a second of its audio, what it is, and the address of a sample of it

type Phrase

type Phrase struct {
	Profile string
	Phrase  string
}

Phrase a wake enabled profile answers to

type Pick

type Pick struct {
	Value, Title, About string
}

One value a setting of a service may be picked as, with the name a person knows it by and what it is, both empty for a value that says it all

type Picker

type Picker struct {
	// What the tool's description says of picking, in place of the line saying the person picks
	Sentence string
	// Description of the voice_id argument
	About string
	// Schema of the find_voices argument
	Search map[string]any
	// Refusal of a voice id the service would not take
	Valid func(id string) error
	// One page of voices for a find_voices argument, as the model reads it; an error the model is told
	Find func(ctx context.Context, job *Job, query map[string]any) (map[string]any, error)
}

Voices the model may pick from, per call

type Pieces

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

Speech a voice hands over in numbered pieces as it makes them, played in their order whatever order they come in. The voice waits while the pieces held come to the limit of bytes, so a fast voice never fills memory; a piece played or held already is dropped, as is every piece once the pieces were stopped, such as when the person cut the speech; a voice that sends nothing for the stall ends the speech with what was said

func NewPieces

func NewPieces(rate, limit int, first, stall time.Duration) *Pieces

Numbered pieces of PCM at the rate, holding at most limit bytes before the voice waits, the reader waiting at most first for the first piece and stall for each piece after it; a limit or a wait of zero takes the host's own

func (*Pieces) Done

func (p *Pieces) Done() <-chan struct{}

Closed once the pieces are over: every one played, or stopped

func (*Pieces) End

func (p *Pieces) End(count int, err error)

Says the voice made count pieces in all, and why it failed when it did: those before the count are still played, then the failure is the reader's

func (*Pieces) PCM

func (p *Pieces) PCM() *PCM

The pieces as PCM at their rate, played in their order as they come; the speech ends at the last piece, at the failure of the voice, at a stall with what was said, or once the reader stops, which stops the pieces as letting go of the PCM does

func (*Pieces) Put

func (p *Pieces) Put(ctx context.Context, number int, pcm []byte) bool

Hands over the piece of the number, from 0, waiting while the pieces held come to the limit unless it is the one played next, which is always taken so the speech goes on. A piece played or held already is dropped and the voice goes on; false once the pieces are over, a piece past the count the voice ended with, or the context ended, the piece dropped

func (*Pieces) Rate

func (p *Pieces) Rate() int

Rate of the PCM

func (*Pieces) Stop

func (p *Pieces) Stop()

Stops the pieces before the end, what is held dropped and every piece put after it too; nothing once they are over

func (*Pieces) Stopped

func (p *Pieces) Stopped() (stopped, stalled bool)

Whether the pieces were stopped before every one was played, and whether the voice stalled

type Placeholder

type Placeholder struct {
	Names []string
	// What icebath puts there, after "where"
	Holds string
}

A placeholder a command must name: one of the names will do

type Profiles

type Profiles struct {
	Config *config.Config
}

Speech as profiles are made: a new profile takes the recognizer, voice and voice input settings of the profile it was made from that it has none of its own of, unless it takes nothing from it

func (Profiles) Delete

func (Profiles) Delete(string) error

Speech keeps what it has of a profile in the profile's folder, which goes with it

func (Profiles) Made

func (p Profiles) Made(making profile.Making) ([]string, error)

type Program

type Program struct {
	Name    string
	Install string
}

A program of the system a service needs, and the command that installs it

type Programs

type Programs struct {
	// Section they may also sit directly under, and the table that holds them
	Section, Table string
	// Placeholders a command must name, each a set of which one will do, with what goes there
	Needs []Placeholder
	// Setting that chooses the service in use
	Choice string
	// contains filtered or unexported fields
}

Programs of yours of one kind: where their entries are kept, the placeholders a command must name and the services whose names they can't take

func (Programs) Add

func (p Programs) Add(cfg *config.Config, name, command string) error

Adds a program of yours with its command, after the checks of its name and command

func (Programs) Change

func (p Programs) Change(cfg *config.Config, name, field string, value any) error

Changes one field of a program of yours, null putting its default back, that field alone written so the rest of the program stays as written; refused when the program could then not run as it reads

func (Programs) Command

func (p Programs) Command(command string) error

Why a command can't run as a program of this kind, nil when it can: empty, or naming none of the names of a placeholder it needs

func (Programs) Guard

func (p Programs) Guard() config.Guard

Guard of the table of programs: a write that would keep a program that can't run is refused, whichever way it comes, and a program the settings rename is renamed as Rename renames it, the choice of it following

func (Programs) Key

func (p Programs) Key(cfg *config.Config, name string) string

Key of a program of yours as the settings keep it, its name as the settings file spells it: under the table, or directly under the section when it sits there; empty for a name no program has

func (Programs) Name

func (p Programs) Name(cfg *config.Config, name, old string) error

Why a name can't be a new program's, nil when it can: not a name a key holds, or the name of a service there is already. Old is the name of the program given the new one, empty for a program added, which keeps its own name in any case

func (Programs) Remove

func (p Programs) Remove(cfg *config.Config, name string) (bool, error)

Removes a program of yours, the choice of it going back to its default; whether the settings chose it

func (Programs) Rename

func (p Programs) Rename(cfg *config.Config, name, to string) (bool, error)

Gives a program of yours another name, the choice of it following; whether the settings chose it

type Recognition

type Recognition struct {
	// Recognizer in use: the one stt.provider names, its fallback while that one can't and the fallback can, else the first that is ready
	// of the local engines and then the cloud services; None when none is named and none is ready
	Name string
	// stt.provider as written, empty for Automatic
	Chosen string
	// The recognizer of Name, its zero value for a name no recognizer has
	Recognizer Recognizer
	// How the recognizer of Name stands
	Standing Standing
	// What keeps speech from being turned into text, nil while nothing does
	Hindrance *Hindrance
}

The recognizer the profile turns speech into text with, and whether it can now

func (Recognition) Label

func (r Recognition) Label() string

Short name of the recognizer in use for the logs, empty for none

type Recognizer

type Recognizer struct {
	// As stt.provider names it
	Name  string
	Title string
	About string
	// Short name the voice requirements show it by, such as Groq or command: name; the title when empty
	Label string
	// What the log names it by when no local engine is installed and it transcribes in their place, such as Groq Whisper API
	Detected string
	// Warning logged when stt.provider names it and neither it nor its fallback can transcribe; empty logs its reason after the name
	Warning string
	// Info logged when its fallback transcribes in its place, nothing logged when empty
	Instead string
	// Runs on this machine: no upload cap applies and Apple's CAF is read as it is
	Local bool
	// A program of yours, which the settings hold
	Program bool
	// A cloud service, whose uploads have their silence trimmed
	Cloud bool
	// Place among the cloud services stt.provider falls back to when no local engine is installed, lower first; 0 for none
	Rank int
	// Why it can't transcribe with the profile's settings now, empty when it can, never installing anything
	Missing func(ctx context.Context, job *Job) string
	// Service tried in its place when it is chosen but missing, such as the other local engine
	Fallback string
	// Model it transcribes with, the call's own first, then its setting
	Model func(job *Job, model string) string
	// Language its own setting gives, empty to leave it to stt.language
	Language func(job *Job) string
	// Hint text its own setting gives, empty to leave it to stt.prompt
	Prompt func(job *Job) string
	// Byte and duration caps of one upload with the model, none for a local engine
	Limit func(model string) Limit
	// Of the whisper family, which reads only the last 224 tokens of a prompt, so a longer one is cut to them
	Whisper    bool
	Transcribe func(ctx context.Context, job *Job, path string, hints Hints) Transcript
	// Live session of the speech as it is spoken, nil for a recognizer that only transcribes whole files
	Live func(ctx context.Context, job *Job, hints Hints, partial func(string)) (Live, error)
	// What a person sets up to use it
	Setup Setup
	// Settings of it a person picks from a list on its page in Voice, such as its model
	Choices []Choices
}

A service that turns speech into text, what a speech plugin registers as a recognizer

func (Recognizer) CloudFailure

func (r Recognizer) CloudFailure(err error, path, label, detail string) Transcript

Transcript of a failed call to a service's own API: the file's permission, the reply's own message, else the label and detail

func (Recognizer) Failure

func (r Recognizer) Failure(message string) Transcript

Transcript of a failure of a recognizer, named

func (Recognizer) Heard

func (r Recognizer) Heard(text string) Transcript

Transcript of a success of a recognizer

func (Recognizer) OpenAIFailure

func (r Recognizer) OpenAIFailure(err error, path, label string) Transcript

Transcript of a failed call to an OpenAI style transcription API: the file's permission, the reply's own message, the connection, the status, else the error itself

func (Recognizer) Replied

func (r Recognizer) Replied(response *http.Response, err error, path, label string, detail func(map[string]any) string,
	text func(map[string]any) (string, error)) (Transcript, map[string]any)

Transcript of a service's reply to an upload: an error status with the detail the reply gives else its start, an empty transcript as nothing said, else the text found in the reply

type Registrant

type Registrant interface {
	Voices(cfg *config.Config) []Voice
	Recognizers(cfg *config.Config) []Recognizer
	Engines(cfg *config.Config) []Engine
}

What a speech plugin adds for the profile of the settings: voices, recognizers and wake engines, such as those of programs its settings name and of the extensions it installed

type Registry

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

func (*Registry) Engine

func (r *Registry) Engine(cfg *config.Config, name string) (Engine, bool)

Wake engine of the profile a name or one of its aliases picks

func (*Registry) Engines

func (r *Registry) Engines(cfg *config.Config) []Engine

Wake engines of the profile, a name or alias an earlier engine took never given to a later one, so an extension never shadows a built in engine

func (*Registry) Host

func (r *Registry) Host() *Speech

Host the registry is nested in, through which surfaces speak, transcribe and listen

func (*Registry) Recognizer

func (r *Registry) Recognizer(cfg *config.Config, name string) (Recognizer, bool)

func (*Registry) Recognizers

func (r *Registry) Recognizers(cfg *config.Config) []Recognizer

Recognizers of the profile, a name an earlier recognizer took never given to a later one, as with the voices

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

func (*Registry) Voice

func (r *Registry) Voice(cfg *config.Config, name string) (Voice, bool)

Voice of the name for the profile, the first registered of a name winning so a program of yours never shadows a built in one

func (*Registry) Voices

func (r *Registry) Voices(cfg *config.Config) []Voice

Voices of the profile, a name an earlier voice took never given to a later one, so an extension or a program of yours never shadows a built in voice; the voices of a voice's catalog offered in its pickers

func (*Registry) WakeEngine

func (r *Registry) WakeEngine(cfg *config.Config, provider string, model bool) (Engine, bool)

Engine of the profile a wake_word.provider setting resolves to, auto taking the open vocabulary engine this machine has a build of unless a model file is set, else the first by rank this machine has a build of, else the first by rank; false for a name no engine has. The engines are in the fixed order their plugins register them, so the choice is the same on every run

type ReplyError

type ReplyError struct{ Message string }

Reply of a structured transcription without text, its message as the service gave it

func (*ReplyError) Error

func (e *ReplyError) Error() string

type Request

type Request struct {
	Text string
	// File to write, whose extension names the format: .mp3 unless asked otherwise, .ogg for a voice bubble, .wav for PCM
	Path string
	// Speed the call asked for, 0.25 to 4, 0 when it asked none
	Speed float64
	// How to speak, which the services that take voice design follow
	Instructions string
	// Voice the call picked, such as an ElevenLabs voice id, empty for the configured one
	Voice string
}

One piece of speech a voice is asked to write

type Resampler

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

Resamples s16le mono PCM between rates across chunk boundaries, averaging whole ratios and interpolating others

func NewResampler

func NewResampler(from, to int) *Resampler

func (*Resampler) Resample

func (r *Resampler) Resample(pcm []byte) []byte

Converts one chunk, the rest it could not use yet carried into the next

type Resident

type Resident[T Model] struct {
	// contains filtered or unexported fields
}

Models a local voice keeps loaded by what they were loaded with, the least recently used closed once more than three are held, each closed after the request it serves

func (*Resident[T]) Clear

func (r *Resident[T]) Clear() int

Closes every model held, how many there were

func (*Resident[T]) Load

func (r *Resident[T]) Load(key string, load func() (T, error)) (T, error)

Model of the key, loaded now when it isn't held

type Search struct {
	Query, Language, Gender, Cursor string
	Size                            int
}

What a search of a catalog asks: words of a voice's name or description, a language, a gender, the cursor of the page asked for, empty for the first, and the most voices the page holds

type Services

type Services struct {
	Speakers    []Voice
	Recognizing []Recognizer
	Waking      []Engine
}

Services fixed once they are registered, whatever the profile

func (Services) Engines

func (s Services) Engines(*config.Config) []Engine

func (Services) Recognizers

func (s Services) Recognizers(*config.Config) []Recognizer

func (Services) Voices

func (s Services) Voices(*config.Config) []Voice

type Session

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

A live transcription feeding 16 kHz PCM to a service on one worker, its partial text handed out as it changes

func Socketed

func Socketed(ctx context.Context, env httpx.Env, provider, url string, headers http.Header, rate int, wire Wire, partial func(string)) *Session

Live session of a service at a websocket address, reached through the proxy and authorities of the environment, the profile's, fed audio at the rate given; its worker starts at once

func (*Session) Cancel

func (s *Session) Cancel()

Stops the worker, the session finishing as cancelled

func (*Session) Finish

func (s *Session) Finish(timeout float64) Transcript

Ends the audio and waits for the final transcript, a failure when the service keeps it longer than the timeout

func (*Session) Heard

func (s *Session) Heard(text string) *Transcript

Transcript a session finished with as a success

func (*Session) Partial

func (s *Session) Partial(text string)

Records a changed partial and hands it on

func (*Session) Provider

func (s *Session) Provider() string

func (*Session) Push

func (s *Session) Push(pcm []byte)

Queues audio until the session finishes

func (*Session) Refused

func (s *Session) Refused(message string) *Transcript

Failure the service reported

type Setup

type Setup struct {
	// Variables of the profile's environment that hold its key, the first taking a key pasted in setup
	Keys []string
	// Provider kind whose sign in serves it in place of a key, connected in Providers
	SignIn string
	// Python set it runs in, installed on request
	Extra string
	// Programs of this machine it needs besides, such as espeak-ng
	Programs []string
	// Where to get a key
	Link string
	// What it costs and whether it is the one to start with, as the setup lists it: recommended · free, paid, free tier, free
	Badge string
	// What it needs to run when none of the rest says, after Needs, such as a whisper program; empty for a service that runs once the rest is
	// there
	Needs string
}

What a person sets up to use a service

type Sink

type Sink struct {
	Clip func(format string, rate int) error
	Data func(data []byte) error
}

Where a piece of speech the app plays comes from: the start of each clip, its format and the rate of PCM, then its bytes

type Socket

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

Websocket of a live session, read on a goroutine of its own so a wait for an event can time out

func (*Socket) Binary

func (s *Socket) Binary(data []byte) error

func (*Socket) JSON

func (s *Socket) JSON(value any) error

func (*Socket) Text

func (s *Socket) Text(text string) error

type Speaking

type Speaking struct {
	// As tts.provider names it, Edge when it names none
	Name string
	// The voice of Name, its zero value for a name no voice has
	Voice    Voice
	Standing Standing
	// What keeps replies from being read aloud, nil while nothing does
	Hindrance *Hindrance
}

The voice the profile reads replies aloud with, and whether it can now

type Speech

type Speech struct {
	Registry
	// contains filtered or unexported fields
}

Speech of every profile: the services the plugins registered, and what they run on

func (*Speech) Acquire

func (s *Speech) Acquire(ctx context.Context, job *Job, lease string)

Loads the voice the profile speaks with ahead of use, the leases holding it until the last one is dropped

func (*Speech) Assets

func (s *Speech) Assets() string

Folder of the fetched speech assets, beside which a plugin keeps what it makes of them, such as converted voices

func (*Speech) Dir

func (s *Speech) Dir() string

Folder of the settings every profile shares, which this machine's speech caches live under

func (*Speech) Drop

func (s *Speech) Drop(ctx context.Context, job *Job, lease string)

Drops a lease, the last one out starting the keep warm window before resident voices unload

func (*Speech) Fetched

func (s *Speech) Fetched(a Asset) bool

Whether the asset is fetched already, so using it downloads nothing

func (*Speech) File

func (s *Speech) File(ctx context.Context, env httpx.Env, a Asset) (string, error)

Path of the verified asset, downloaded on first use through the proxy and authorities of the environment, that of the profile asking, none meaning no proxy and the system's authorities as the package manager's downloads take it

func (*Speech) Job

func (s *Speech) Job(cfg *config.Config) *Job

Job of a profile outside a session: its own helper models, no surface of a chat app, the paths it touches guarded as the tools guard them

func (*Speech) Local

func (s *Speech) Local() *Job

Job of the profile this process runs in, for what a client does on its own machine such as running a player

func (*Speech) Packages

func (s *Speech) Packages() *packages.Packages

Package host of this machine, which installs and finds the programs, libraries and Python sets speech runs on

func (*Speech) Profile

func (s *Speech) Profile(name string) (*config.Config, error)

Settings of the profile with the name, the one in use for none

func (*Speech) Reading

func (s *Speech) Reading(cfg *config.Config) *Job

Job of a profile for one reading of how its voices and recognizers stand, such as a page of Voice: each program, Python set, provider, credential of a kind of provider and standing of a service its checks ask for looked up once, the programs on its search path and the Python sets those a reading of a moment before found, and the credentials glanced at, nothing renewed or probed while the page waits

func (*Speech) RecognitionPrograms

func (s *Speech) RecognitionPrograms() Programs

Programs of yours that turn a recording into text

func (*Speech) Register

func (s *Speech) Register(registrant Registrant)

Adds a registrant; a registry nested in the host reaches it through Host

func (*Speech) SpeechPrograms

func (s *Speech) SpeechPrograms() Programs

Programs of yours that read text aloud

func (*Speech) Tree

func (s *Speech) Tree(ctx context.Context, env httpx.Env, a Asset) (string, error)

Folder holding the unpacked contents of a verified archive, downloaded in the environment of the profile asking and unpacked on first use

type SpeechRequest

type SpeechRequest struct {
	Model, Voice, Text string
	// File written, whose extension names the format asked for
	Path string
	// 1 for none sent
	Speed        float64
	Instructions string
	// Fields of the body beside OpenAI's own, such as lang_code
	Extra map[string]any
}

One OpenAI style speech call

type Standing

type Standing struct {
	State string
	// Nil while nothing keeps it from running
	Hindrance *Hindrance
	// What the service says it lacks in its own words, empty when it lacks nothing
	Missing string
}

How a voice or recognizer stands for a profile: the state its row shows and what keeps it from running

type StatusError

type StatusError struct {
	Status int
	Reason string
	URL    string
	Body   string
}

A failed reply worded as HTTP libraries word it, with what the service said

func (*StatusError) Error

func (e *StatusError) Error() string

type Stream

type Stream struct {
	// Place among the voices tried when tts.streaming.provider is auto, lower first
	Rank int
	// Name the log gives the stream, such as OpenAI streaming TTS; the title's when empty
	Label string
	// Whether it can stream with the profile's settings now
	Ready func(job *Job) bool
	// Opens the sentence's speech: 16 bit little endian mono PCM at the rate answered, which the reply's own headers may change
	Open func(ctx context.Context, job *Job, text string) (*PCM, error)
}

PCM a voice makes while it speaks one sentence

type TimeoutError

type TimeoutError struct {
	Command string
	Timeout time.Duration
}

A program of yours that went quiet past its timeout

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

The seconds written as a fraction, a whole number keeping its .0

type Transcript

type Transcript struct {
	Success bool   `json:"success"`
	Text    string `json:"transcript"`
	Error   string `json:"error,omitempty"`
	// Recognizer that answered
	Provider string `json:"provider,omitempty"`
	// Nothing was said
	NoSpeech bool `json:"no_speech,omitempty"`
	// What was heard was a known hallucination on silence, so it reads as nothing
	Filtered bool `json:"filtered,omitempty"`
	// Pieces an upload too large for one request was cut into
	Segments int `json:"segments,omitempty"`
	// Why nothing claimed the configured service
	Kind string `json:"error_type,omitempty"`
}

What a transcription came back with

func Failing

func Failing(err error, path, label string) Transcript

Why a transcription failed, the permission of the file named on its own

func Failure

func Failure(message string) Transcript

Transcript of a failure

type Voice

type Voice struct {
	// As tts.provider names it
	Name  string
	Title string
	About string
	// Name the log says it speaks with, such as OpenAI TTS; the title when empty
	Label string
	// Runs on this machine
	Local bool
	// A program of yours, which the settings hold
	Program bool
	// Whether it can speak with the profile's settings now, its key or engine there, never installing anything
	Ready func(job *Job) bool
	// Most characters one request takes, which longer text is split under; tts.<name>.max_text_length wins over it
	Limit func(job *Job) int
	// Writes the speech of the request's text to its path in the format the path's extension names where the service can, answering the
	// path it wrote, which may differ
	Synthesize func(ctx context.Context, job *Job, request Request) (string, error)
	// Speech as PCM while it is made, nil for a voice that writes whole files only
	Stream *Stream
	// How it gives the Ogg Opus a chat app shows as a voice bubble
	Opus Opus
	// Extension of the files it writes whatever it is asked, such as a program of yours that writes wav; empty for one that follows the path
	Format string
	// Readies and frees what it keeps loaded, nil for a voice that keeps nothing
	Warm, Release func(ctx context.Context, job *Job) error
	// Keeps a model loaded between requests, unloaded once no lease holds speech warm
	Resident bool
	// Lets the model pick a voice per call and search for one, nil for a voice whose voice the person sets
	Picker *Picker
	// Voices it speaks with as one catalog, which the host offers as the list of the catalog's setting and, where the model may pick, as
	// its Picker; nil for a voice that lists none or gives both itself
	Catalog *Catalog
	// What a person sets up to use it
	Setup Setup
	// Settings of it a person picks from a list on its page in Voice, such as its voice or model
	Choices []Choices
}

A service that speaks text, what a speech plugin registers as a voice

type Wake

type Wake struct {
	Speech *Speech
	Phrase string
	// 0 to 1, higher catching more
	Sensitivity float64
	// Over threshold frames in a row that fire, 1 to 10
	Frames int
	// The phrases other wake enabled profiles chose are heard too
	Routing bool
	// Profile of the settings, and the phrase of every wake enabled profile
	Profile  string
	Profiles []Phrase
	// Engine settings by key, such as its model file
	Settings map[string]string
	// PORCUPINE_ACCESS_KEY of the profile's environment
	AccessKey string
}

Wake settings of a profile as the listener arms with them, and the speech of the machine it listens on

func (*Wake) Getenv

func (w *Wake) Getenv(name string) string

Variable of the environment of the profile of the settings, the one in use for none, empty when it has none or the profile can't be read: what the downloads of the listener reach the network through

func (*Wake) Scratch

func (w *Wake) Scratch() string

Folder the listener's passing files go in, such as the keywords an engine is armed with: the scratch folder of the profile, the one in use for none; empty, the system's own, when it can't be made

func (*Wake) Setting

func (w *Wake) Setting(key string) string

Setting of the engine, its spaces trimmed

type Wave

type Wave struct {
	Channels, Width, Rate int
	Frames                []byte
}

Header and frames of a PCM WAV

func ParseWave

func ParseWave(data []byte) (*Wave, error)

func ReadWave

func ReadWave(path string) (*Wave, error)

PCM WAV a file holds, extensible headers of plain PCM included

type Wire

type Wire interface {
	Open(socket *Socket) error
	Ready() bool
	Send(socket *Socket, chunk []byte) error
	// Ends the audio; a transcript it answers finishes the session at once, such as an empty one when no audio was sent
	End(socket *Socket) (*Transcript, error)
	// Final transcript the event carries, nil while the session goes on
	Event(session *Session, event map[string]any) (*Transcript, error)
}

One wire of a live service over a websocket: what it sends first, whether it takes audio yet, how it sends audio and ends it, and the transcript an event finishes with

type Words

type Words struct {
	Text  string
	Final bool
}

What a recognizer heard of the speech: interim words stand until others replace them, final ones are kept

type Worker

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

Long lived Python process of a local engine holding one loaded model, asked one JSON line at a time

func (*Worker) Ask

func (w *Worker) Ask(request, reply any) error

Sends one request line and decodes the reply line into the reply

func (*Worker) Close

func (w *Worker) Close()

Ends the process after any request in flight, killing it when it does not exit within five seconds

Directories

Path Synopsis
Page of Voice in the settings menu: voice input and spoken replies, the pages of speech to text, text to speech and the wake word with their services and listeners, each set up there, and the options of each
Page of Voice in the settings menu: voice input and spoken replies, the pages of speech to text, text to speech and the wake word with their services and listeners, each set up there, and the options of each
The voice command: the microphones of the computer the server runs on, by the names the Microphone setting takes, so a person who sets it from the command line sees what to set it to
The voice command: the microphones of the computer the server runs on, by the names the Microphone setting takes, so a person who sets it from the command line sees what to set it to
Native libraries speech runs on, loaded at run time without cgo: PortAudio, the speech engine and the wake word engines
Native libraries speech runs on, loaded at run time without cgo: PortAudio, the speech engine and the wake word engines
What speech needs on this machine: ffmpeg, which converts, trims, splits and joins audio, BtbN's builds on Windows and Linux, martin-riedl's on macOS and Termux's own build with its closure on Android; and pilk, which reads the SILK voice notes of QQ and WeChat
What speech needs on this machine: ffmpeg, which converts, trims, splits and joins audio, BtbN's builds on Windows and Linux, martin-riedl's on macOS and Termux's own build with its closure on Android; and pilk, which reads the SILK voice notes of QQ and WeChat
PortAudio, loaded at run time without cgo: the microphones and speakers of this machine, streams of 16 bit samples, one playback of a buffer at a time
PortAudio, loaded at run time without cgo: the microphones and speakers of this machine, streams of 16 bit samples, one playback of a buffer at a time
Connect service of speech, through which voice input and the pages of Voice reach the voices and recognizers of the server's profiles
Connect service of speech, through which voice input and the pages of Voice reach the voices and recognizers of the server's profiles
The sherpa-onnx speech engine, loaded at run time from its pinned release: offline voices such as Piper's, and keyword spotting
The sherpa-onnx speech engine, loaded at run time from its pinned release: offline voices such as Piper's, and keyword spotting
Voice input on the machine the app runs on: recordings from its microphone turned into text by the server, replies the server speaks played on its speakers, talking over a reply to cut it off, and the wake word
Voice input on the machine the app runs on: recordings from its microphone turned into text by the server, replies the server speaks played on its speakers, talking over a reply to cut it off, and the wake word

Jump to

Keyboard shortcuts

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