Documentation
¶
Overview ¶
Package speech defines provider-agnostic speech synthesis types and the SpeechProvider interface that all text-to-speech backends implement.
The types in this package form the canonical request/response shape used across the SDK. Concrete providers translate to and from these types so that higher-level code can remain backend-independent.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoProvider indicates the Client has no underlying Provider configured. ErrNoProvider = errors.New("speech: no provider configured") // ErrInvalidRequest indicates the Request is malformed or missing // required fields (for example, no Model or no Text). ErrInvalidRequest = errors.New("speech: invalid request") // unreachable or returned a transient failure. ErrProviderUnavailable = errors.New("speech: provider unavailable") // ErrRateLimited indicates the upstream provider rejected the request // due to rate limiting or quota exhaustion. ErrRateLimited = errors.New("speech: rate limited") // ErrAuthFailed indicates the provider rejected the supplied credentials. ErrAuthFailed = errors.New("speech: authentication failed") // ErrUnsupported indicates the provider does not support a requested // capability (for example, a specific voice or format). ErrUnsupported = errors.New("speech: unsupported operation") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin, provider-agnostic facade over a Provider. It centralises concerns that are independent of the underlying backend and provides a single entry point that higher-level code can depend on.
func NewClient ¶
NewClient returns a Client backed by the given Provider. The Provider may be nil; in that case the Client's methods will return ErrNoProvider.
func (*Client) GenerateSpeech ¶
func (c *Client) GenerateSpeech(ctx context.Context, req GenerateSpeechRequest) (GenerateSpeechResponse, error)
GenerateSpeech generates speech audio from text by delegating to the underlying Provider. If the Client or its Provider is nil, it returns ErrNoProvider.
type GenerateSpeechRequest ¶
type GenerateSpeechRequest struct {
// Model identifies the speech model to use.
Model string `json:"model"`
// Text is the text to convert to speech.
Text string `json:"text"`
// Voice is the voice identifier (e.g. "alloy", "nova").
Voice string `json:"voice,omitempty"`
// Speed is the speaking rate multiplier (e.g. 1.0 is normal).
Speed float64 `json:"speed,omitempty"`
// Format is the output audio format (e.g. "mp3", "wav").
Format string `json:"format,omitempty"`
// ProviderOptions carries provider-specific options.
ProviderOptions map[string]any `json:"provider_options,omitempty"`
}
GenerateSpeechRequest is a provider-agnostic text-to-speech request.
type GenerateSpeechResponse ¶
type GenerateSpeechResponse struct {
// Audio contains the raw audio data.
Audio []byte `json:"audio"`
// Format is the audio format (e.g. "mp3", "wav").
Format string `json:"format,omitempty"`
}
GenerateSpeechResponse is the result of a speech generation request.
type Provider ¶
type Provider interface {
// Name returns a short, stable identifier for the provider
// (for example, "openai", "elevenlabs").
Name() string
// GenerateSpeech generates speech audio from the given text.
GenerateSpeech(ctx context.Context, req GenerateSpeechRequest) (GenerateSpeechResponse, error)
}
Provider is implemented by text-to-speech model backends. Implementations translate between the provider-agnostic types defined in this package and their underlying API.