Documentation
¶
Overview ¶
Package asyncai is a streaming text-to-speech service backed by Async's TTS WebSocket. It holds one connection open for the call: the session is opened with an init message when the pipeline starts, each sentence is sent on the context it belongs to, and the raw PCM audio streams back on that context.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// APIKey is the Async API key. Required.
APIKey string `validate:"required"`
// Voice is the voice id (UUID) to synthesize with. Required.
Voice string `validate:"required"`
// URL overrides the TTS WebSocket endpoint; empty uses the hosted endpoint.
URL string
// Version sets the API version; empty uses a default.
Version string
// Model is the Async model id; empty uses a default.
Model string
// Language is the synthesis language code; empty uses "en".
Language string
// SampleRate is the PCM rate requested and emitted downstream; 0 uses 24 kHz.
SampleRate int
// Websocket configures the connection: whether and how it reconnects, and
// how long it waits on a peer that has stopped answering.
Websocket wsservice.Options
}
Config configures the Async TTS service.
type HTTPTTSConfig ¶ added in v0.7.0
type HTTPTTSConfig struct {
// APIKey is the Async API key. Required.
APIKey string `validate:"required"`
// Voice is the voice id (UUID) to synthesize with. Required.
Voice string `validate:"required"`
// URL overrides the HTTP API base; empty uses the hosted API.
URL string
// Version sets the API version; empty uses a default.
Version string
// Model is the Async model id; empty uses a default.
Model string
// Language for synthesis; the zero value leaves it unset. Mapped to Async's
// language code.
Language language.Language
// SampleRate is the PCM rate requested and emitted downstream; 0 uses 24 kHz.
SampleRate int
// Encoding is the audio encoding; empty uses "pcm_s16le".
Encoding string
// Container is the audio container; empty uses "raw".
Container string
// Client makes the requests; nil uses a client of its own. The service
// sends through a copy of it, so the client itself is left as it is.
Client *http.Client
}
HTTPTTSConfig configures the Async HTTP TTS service.
func (HTTPTTSConfig) Validate ¶ added in v0.7.0
func (c HTTPTTSConfig) Validate() error
Validate reports whether the configuration is usable.
type HTTPTTSService ¶ added in v1.0.0
HTTPTTSService is the Async text-to-speech service NewHTTPTTS builds.
func NewHTTPTTS ¶ added in v0.7.0
func NewHTTPTTS(cfg HTTPTTSConfig) *HTTPTTSService
NewHTTPTTS builds an Async TTS service over the HTTP streaming API. Each sentence is one request, whose audio is read whole and yielded as one frame. Prefer NewTTS on a call, where a connection held open spares each sentence the request.
type TTSService ¶ added in v1.0.0
TTSService is the Async text-to-speech service NewTTS builds.
func NewTTS ¶
func NewTTS(cfg Config) *TTSService
NewTTS builds an Async TTS service.
It holds one connection open for the call, opened when the pipeline starts. When it drops it is restored with backoff, and when that keeps failing the service reports a permanent error and becomes unusable. See tts.Websocket.