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