speechstream

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 6 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 speechstream turns a synthesiser's PCM16LE response body into the speech chunks the action plane paces out.

Every streaming speech adapter here faces the same three problems, and they are not obvious ones: a read boundary can split a sample in half, the output rate is rarely the rate the server chose, and exactly one chunk has to carry the terminal flag - which means the last complete sample must be withheld until the body ends. Solving them once is why this is a package rather than a method on each adapter.

Index

Constants

View Source
const (
	// DefaultReadBufferBytes is the read granularity. It is small enough that
	// the first chunk leaves for the client while the synthesiser is still
	// producing, which is the whole point of streaming.
	DefaultReadBufferBytes = 8 << 10
	// DefaultMaxAudioBytes bounds a single utterance in each direction.
	DefaultMaxAudioBytes = int64(128 << 20)
)

Variables

This section is empty.

Functions

func Consume

func Consume(
	body io.Reader, options Options, candidateID string, consume func(v1.SpeechChunk) error,
) error

Consume reads body to completion and calls consume for each chunk.

Exactly one non-empty chunk is marked Final, and it is the last one. That is why the final output sample is held back rather than emitted as it arrives: the stream does not announce its end in advance, so the only way to know which chunk is last is to still be holding it when the body closes.

Types

type Options

type Options struct {
	// Label names the provider in error messages. An operator reading
	// "returned no audio" needs to know which endpoint did that.
	Label string
	// SourceRateHz is the rate the response body carries.
	SourceRateHz uint32
	// OutputRateHz is the rate chunks are emitted at.
	OutputRateHz uint32
	// ReadBufferBytes is the read granularity. Zero selects the default.
	ReadBufferBytes int
	// MaxAudioBytes bounds the response and the output independently. Zero
	// selects the default.
	MaxAudioBytes int64
}

Options configures one conversion.

Jump to

Keyboard shortcuts

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