Documentation
¶
Overview ¶
Package speechsocket speaks openrealtime-incremental-speech/1, the same-context synthesis WebSocket served by the duplex-plan TTS services (tools/duplexmodels/common.py documents the wire contract).
Two layers are exported. Context is the incremental synthesis session the streaming plan asks for: open a context, append text while audio is already being produced, flush without ending, end, or cancel - with accepted-text and generated-audio positions kept separately. Adapter is an ordinary api/v1 StreamingSpeechProvider built on it, one context per plan, so any such service can replace a complete-text synthesiser without further runtime changes.
A service states how it consumes text in context.ready (incremental_text, input_granularity). The adapter reports that declaration in its descriptor rather than assuming every model conditions on a growing prefix.
Index ¶
- Constants
- type Adapter
- type Capabilities
- type Chunk
- type Config
- type Context
- func (speech *Context) Accepted() int64
- func (speech *Context) Append(ctx context.Context, text string) error
- func (speech *Context) Audio() <-chan Chunk
- func (speech *Context) Cancel(ctx context.Context) error
- func (speech *Context) Capabilities() Capabilities
- func (speech *Context) Close()
- func (speech *Context) End(ctx context.Context) error
- func (speech *Context) Err() error
- func (speech *Context) Flush(ctx context.Context) error
- func (speech *Context) Model() string
- func (speech *Context) SampleRate() uint32
- func (speech *Context) Sent() int64
Constants ¶
const ( // DefaultURL is the CosyVoice service of the duplex deployment profiles. DefaultURL = "ws://127.0.0.1:9120/v1/tts/stream" // DefaultModel names the service's model in descriptors; the server // chooses the model at start-up. DefaultModel = "Fun-CosyVoice3-0.5B" // Protocol is the wire contract this package speaks. Protocol = "openrealtime-incremental-speech/1" )
const CapabilityIncrementalText v1.Capability = "incremental_text_input"
CapabilityIncrementalText is reported when the service declares that it conditions on text appended while a generation is running.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is a StreamingSpeechProvider over one context per plan.
func (*Adapter) Descriptor ¶
func (adapter *Adapter) Descriptor() v1.Descriptor
Descriptor implements api/v1.SpeechProvider.
func (*Adapter) Stream ¶
func (adapter *Adapter) Stream(ctx context.Context, plan v1.SpeechPlan, consume func(v1.SpeechChunk) error) error
Stream implements api/v1.StreamingSpeechProvider: open a context, append the plan's text, end it, and emit audio as it arrives. Cancelling ctx cancels the context, and nothing generated after that reaches consume.
func (*Adapter) Synthesize ¶
func (adapter *Adapter) Synthesize(ctx context.Context, plan v1.SpeechPlan) ([]v1.SpeechChunk, error)
Synthesize implements api/v1.SpeechProvider by collecting the stream.
type Capabilities ¶
type Capabilities struct {
IncrementalText bool `json:"incremental_text"`
NonterminalFlush bool `json:"nonterminal_flush"`
InputGranularity string `json:"input_granularity"`
}
Capabilities is what a service declares in context.ready.
type Config ¶
type Config struct {
URL string
Model string
Voice string
BearerToken string
Header http.Header
HTTPClient *http.Client
OutputRateHz uint32
DialTimeout time.Duration
// IdleTimeout bounds the wait for the next server event once a context
// has been ended; a service that stops answering fails the utterance
// rather than holding it forever.
IdleTimeout time.Duration
}
Config configures a speech socket client.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is one incremental synthesis context on its own socket.
func Open ¶
Open dials the service and opens one context. The context is ready when Open returns: its sample rate and declared capabilities are known.
func (*Context) Accepted ¶
Accepted is the cumulative number of characters the service has accepted.
func (*Context) Audio ¶
Audio delivers generated audio in order. It is closed after audio.done, cancellation, or failure; Err then says which.
func (*Context) Cancel ¶
Cancel stops the context. Audio already queued on this side is discarded: nothing is delivered on Audio after Cancel returns.
func (*Context) Capabilities ¶
func (speech *Context) Capabilities() Capabilities
Capabilities is what the service declared for this context.
func (*Context) End ¶
End says no more text will be appended; audio continues until audio.done. From here on a service that goes silent for longer than the idle timeout fails the context instead of holding it open.
func (*Context) Err ¶
Err reports why Audio closed: nil after audio.done, context.Canceled after Cancel, or the failure.
func (*Context) Flush ¶
Flush asks the service to synthesise what it has buffered without ending the context.
func (*Context) SampleRate ¶
SampleRate is the rate of every chunk this context produces.