bysentence

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: 1 module, 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 bysentence synthesises a turn one sentence at a time.

A streaming synthesiser still reads the whole text before it emits anything. Measured against Fish Audio S2-Pro on SGLang, with stream set and PCM out, the wait for the first byte is a function of the text it was handed:

one word        289ms
a short clause  607ms
one sentence    911ms
two sentences   977ms

That is not what streaming is supposed to mean, and it is not something to fix in the engine: whatever it is doing - planning prosody, prefilling, deciding a length - it is doing it over everything it was given. So give it less. The first sentence is all the agent needs to start talking, and the rest is synthesised while that sentence plays.

The saving is the difference between those rows, which is three to six hundred milliseconds on every spoken turn in the system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Split

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

Split cuts text at the first place a speaker would pause, keeping each piece at least minimum runes long so a stray "Mr." does not produce a one-word request.

Only the first cut earns anything - it is what the agent starts talking on - so the rest is left whole rather than chopped at every comma, each piece paying its own round trip while the ear is already occupied.

func SplitWithClauseMinimum

func SplitWithClauseMinimum(text string, minimum, clauseMinimum int) []string

SplitWithClauseMinimum permits short complete sentences while requiring a longer phrase before a comma, semicolon, colon, or dash. Streaming callers can release "Yes." promptly without sending "First," alone to synthesis. Both minima apply to clause breaks; sentence ends use minimum alone.

Types

type Provider

type Provider struct {
	Inner v1.StreamingSpeechProvider
	// Minimum is how short a first piece may be. Below this the split is not
	// worth the second request: "Yes." synthesises in under three hundred
	// milliseconds whole, and cutting it in two would add a round trip to save
	// nothing.
	Minimum int
}

Provider wraps a streaming speech provider.

func (Provider) Descriptor

func (provider Provider) Descriptor() v1.Descriptor

func (Provider) Stream

func (provider Provider) Stream(
	ctx context.Context, plan v1.SpeechPlan, consume func(v1.SpeechChunk) error,
) error

Stream synthesises each sentence in turn and forwards the audio as it comes.

Sequential rather than concurrent, and deliberately. The pieces have to reach the ear in order, so a second request running ahead would have to be buffered until the first finished - which saves nothing, because playback is paced in real time and a sentence takes longer to say than the next one takes to synthesise. What matters is only that the first piece is short.

func (Provider) Synthesize

func (provider Provider) Synthesize(ctx context.Context, plan v1.SpeechPlan) ([]v1.SpeechChunk, error)

Jump to

Keyboard shortcuts

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