speech

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 4 Imported by: 2 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 speech is the voice-dictation module's domain layer: the speech-to-text port, its result value types, and the WAV validator that keeps unbilled garbage audio from reaching the provider. Provider adapters (Meta Model API, OpenAI-compatible transcription) live in the module's infrastructure package and implement the port.

Index

Constants

View Source
const (
	// MaxAudioBytes bounds a dictation upload: five minutes of 16 kHz mono
	// 16-bit PCM (≈9.6 MB with the WAV header) fit, anything larger is
	// rejected before it reaches the provider.
	MaxAudioBytes = 10 << 20
)

Variables

View Source
var (
	// ErrInvalidAudio reports audio that is not a mono 16-bit PCM WAV file
	// at a supported sample rate.
	ErrInvalidAudio = errors.New("audio must be a mono 16-bit PCM WAV file")

	// ErrAudioTooLarge reports an upload beyond MaxAudioBytes.
	ErrAudioTooLarge = errors.New("audio exceeds the maximum dictation length")

	// ErrTranscriptionFailed reports a provider-side transcription failure.
	ErrTranscriptionFailed = errors.New("speech transcription failed")

	// ErrEmptyTranscript reports a provider response that carries no text.
	ErrEmptyTranscript = errors.New("speech transcription returned no text")
)

Functions

func NormalizeLanguage

func NormalizeLanguage(language string) string

NormalizeLanguage trims a language hint for the provider request. An empty hint means auto-detect and stays empty; overlong values are dropped to empty rather than forwarded.

func ValidateWAV

func ValidateWAV(audio []byte) error

ValidateWAV rejects anything that is not a mono 16-bit PCM WAV file at a supported sample rate, or that exceeds MaxAudioBytes. It parses the RIFF envelope and the fmt chunk instead of trusting extensions or MIME types.

Types

type SpeechToTextService

type SpeechToTextService interface {
	Transcribe(
		ctx context.Context,
		audio []byte,
		language string,
	) (Transcription, error)
}

SpeechToTextService defines the interface for speech-to-text providers.

type Transcription

type Transcription struct {
	Text  string
	Turns []Turn
}

Transcription is the outcome of transcribing dictated audio: the full text plus the detected turns behind it.

func NewTranscription

func NewTranscription(text string, turns []Turn) Transcription

NewTranscription assembles a transcription outcome from its text and turns.

type Turn

type Turn struct {
	TurnID     int
	StartMs    int64
	EndMs      int64
	Transcript string
	Speaker    string
}

Turn is a single detected speech segment. Speaker is populated in diarization-style responses and empty for single-turn dictation.

func NewTurn

func NewTurn(
	turnID int,
	startMs, endMs int64,
	transcript, speaker string,
) Turn

NewTurn assembles a speech turn from its boundaries and text.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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