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 ¶
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 ¶
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)