speechsocket

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: 15 Imported by: ? 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 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

View Source
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"
)
View Source
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 New

func New(config Config) (*Adapter, error)

New validates the configuration without opening a socket.

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 Chunk

type Chunk struct {
	Sequence int
	PCM16LE  []byte
}

Chunk is one piece of generated audio at the service's rate.

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

func Open(ctx context.Context, config Config) (*Context, error)

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

func (speech *Context) Accepted() int64

Accepted is the cumulative number of characters the service has accepted.

func (*Context) Append

func (speech *Context) Append(ctx context.Context, text string) error

Append adds text to the running context.

func (*Context) Audio

func (speech *Context) Audio() <-chan Chunk

Audio delivers generated audio in order. It is closed after audio.done, cancellation, or failure; Err then says which.

func (*Context) Cancel

func (speech *Context) Cancel(ctx context.Context) error

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

func (speech *Context) Close()

Close releases the socket.

func (*Context) End

func (speech *Context) End(ctx context.Context) error

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

func (speech *Context) Err() error

Err reports why Audio closed: nil after audio.done, context.Canceled after Cancel, or the failure.

func (*Context) Flush

func (speech *Context) Flush(ctx context.Context) error

Flush asks the service to synthesise what it has buffered without ending the context.

func (*Context) Model

func (speech *Context) Model() string

Model is the model the service reported, when it did.

func (*Context) SampleRate

func (speech *Context) SampleRate() uint32

SampleRate is the rate of every chunk this context produces.

func (*Context) Sent

func (speech *Context) Sent() int64

Sent is the cumulative number of characters appended by this client.

Jump to

Keyboard shortcuts

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