voice

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 30 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

Package voice is dictation for the composer's server engine: the page streams whatever its recorder produces over a socket, ffmpeg decodes it to PCM as it arrives, and the machine's recognition service, reached over a Unix socket, answers with partial and final text. No audio is written to disk and no transcript is logged.

The page sends {type: "start", lang}, binary audio, {type: "stop" | "abort"}; it gets {type: "ready" | "partial" | "final" | "preparing" | "error"}, an error carrying code "unavailable" when this machine cannot recognize at all (the page then tries another engine) and "failed" otherwise.

Index

Constants

View Source
const WhisperModel = "onnx-community/whisper-small"

WhisperModel is the only model the page may ask for.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Upstream, CacheKey, ContentType string
}

Asset is one allowed file: where it comes from and where it is kept.

type Assets

type Assets struct {
	CacheDir string
	// ModelHost and RuntimeHost are the bases of the model files and of the runtime's dist (tests serve their own).
	ModelHost, RuntimeHost string
	Client                 *http.Client
	Log                    func(level, msg string, kv ...any)
}

Assets serves the files.

func (*Assets) Resolve

func (a *Assets) Resolve(segments []string) (Asset, bool)

Resolve is the file segments name: hf/<org>/<model>/resolve/main/<file> mirrors the model host's layout the page's library builds, ort/<library version>/<file> the dist it would otherwise load from a CDN.

func (*Assets) Serve

func (a *Assets) Serve(w http.ResponseWriter, r *http.Request, segments []string)

Serve answers GET /api/voice/assets/<segments…>; the caller checked the session or token and the method.

type Config

type Config struct {
	// Socket is the recognition service's Unix socket.
	Socket string
	// FFmpeg is ffmpeg's absolute path; when empty the usual places are looked in (Candidates).
	FFmpeg     string
	Candidates []string
	// ReadyTimeout is how long the service may take to load its model (30 s).
	ReadyTimeout time.Duration
	Log          func(level, msg string, kv ...any)
	// Credentials gives the saved key and Yandex's folder id of a cloud engine ("openai", "yandex"), or the Codex
	// sign-in's token and ChatGPT account ("chatgpt"); an error says
	// there is none. nil: no cloud engine is offered.
	Credentials func(engine string) (key, folder string, err error)
	// Cloud replaces the cloud recognizers (tests); nil is the real ones.
	Cloud map[string]cloud.Func
}

Config is what the deployment names.

type Error added in v0.15.40

type Error struct {
	Unavailable bool
	Message     string
}

Error is a recognition that did not happen. Unavailable: this machine cannot recognize at all (no ffmpeg, no recognition service, a model that did not load), as opposed to a recording that failed.

func (*Error) Error added in v0.15.40

func (e *Error) Error() string

type Server

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

Server serves dictation sockets; the request is already authenticated.

func New

func New(cfg Config) *Server

func (*Server) Available added in v0.15.40

func (s *Server) Available() bool

Available says whether this machine is set up to recognize: ffmpeg is there and the recognition service has a socket. It does not say the service is ready; a model still loading is waited for, up to ReadyTimeout.

func (*Server) Decodes

func (s *Server) Decodes() bool

Decodes says whether ffmpeg is there: a machine whose recognition service is set up but not listening yet (it starts with the machine, beside the runtime) still recognizes once it does.

func (*Server) HasDecoder added in v0.16.5

func (s *Server) HasDecoder() bool

HasDecoder says ffmpeg is on this machine.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades the request and serves one dictation until either side closes.

func (*Server) Transcribe added in v0.15.40

func (s *Server) Transcribe(ctx context.Context, audio io.Reader, lang, engine string) (string, error)

Transcribe recognizes a whole recording (whatever container ffmpeg reads: webm/opus, mp4/aac, wav) and returns its text, empty for silence. The recording is decoded once, cut into pieces of at most segmentMax at its quietest moments, and every piece is recognized as a dictation of its own, with the engine the person picked ("" or "local" is the machine's service), as the live dictation does; lang is "ru", "en" or "auto" ("" is "ru"). Nothing is written to disk.

Directories

Path Synopsis
Package cloud holds the streaming recognizers that send the audio to a provider (OpenAI Realtime transcription, Yandex SpeechKit v3).
Package cloud holds the streaming recognizers that send the audio to a provider (OpenAI Realtime transcription, Yandex SpeechKit v3).
Package consent sorts an agent's tool calls by what they touch, for the voice mode: while the person talks to a chat by voice, a call that reaches outside — a message to people, a push, a merge or a rollout, a task made or changed, a publication, a deletion, a payment, a letter — waits for their «да» (by voice or with the button); reading, looking around, opening and the chat's own files go at once.
Package consent sorts an agent's tool calls by what they touch, for the voice mode: while the person talks to a chat by voice, a call that reaches outside — a message to people, a push, a merge or a rollout, a task made or changed, a publication, a deletion, a payment, a letter — waits for their «да» (by voice or with the button); reading, looking around, opening and the chat's own files go at once.
Package dict applies a personal word dictionary to speech-recognition text.
Package dict applies a personal word dictionary to speech-recognition text.
Package engine is the speech recognition the runtime brings with it: a pinned whisper.cpp server run as a child of the runtime, and a Unix socket speaking the protocol internal/voice already knows, so that a machine with nothing set up dictates out of the box.
Package engine is the speech recognition the runtime brings with it: a pinned whisper.cpp server run as a child of the runtime, and a Unix socket speaking the protocol internal/voice already knows, so that a machine with nothing set up dictates out of the box.
Package quickedit makes the voice's small edits fast: «сделай заголовок крупнее» on the open board, slide or file goes not to the chat's agent, which takes a turn of minutes, but to one short run of a fast model whose whole context is the file, what is picked in it and the words said.
Package quickedit makes the voice's small edits fast: «сделай заголовок крупнее» on the open board, slide or file goes not to the chat's agent, which takes a turn of minutes, but to one short run of a fast model whose whole context is the file, what is picked in it and the words said.
Package realtime is the voice mode: a spoken conversation in real time, with interruptions, whose requests can go to the agent of the chat it was opened from as tasks.
Package realtime is the voice mode: a spoken conversation in real time, with interruptions, whose requests can go to the agent of the chat it was opened from as tasks.
Package router turns what the person asked the voice for into actions on the whole harnessly.
Package router turns what the person asked the voice for into actions on the whole harnessly.

Jump to

Keyboard shortcuts

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