Documentation
¶
Overview ¶
Package tts implements the SpeechKit text-to-speech surface: a small provider interface plus concrete adapters for OpenAI, Google, and Hugging Face. The router in this file picks a provider per request based on Strategy (CloudFirst, LocalFirst) and degrades gracefully when a provider is unavailable.
All providers must go through github.com/kombifyio/SpeechKit/internal/netsec for outbound HTTP. STT has a parallel routing layer in package router; this package is TTS-only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Google ¶
type Google struct {
BaseURL string
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
Google implements Provider using the Google Cloud Text-to-Speech API.
BaseURL is configurable for testing. It is validated against Validation on every request. Default Validation is strict (public https only).
func NewGoogle ¶
func NewGoogle(opts GoogleOpts) *Google
NewGoogle creates a Google Cloud TTS provider.
func (*Google) Synthesize ¶
type GoogleOpts ¶
GoogleOpts configures the Google TTS provider.
type HuggingFace ¶
type HuggingFace struct {
BaseURL string
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
HuggingFace implements Provider using the HuggingFace Inference API with text-to-speech models (e.g. parler-tts).
BaseURL is configurable for testing. It is validated against Validation on every request. Default Validation is strict (public https only).
func NewHuggingFace ¶
func NewHuggingFace(opts HuggingFaceOpts) *HuggingFace
NewHuggingFace creates a HuggingFace TTS provider.
func (*HuggingFace) Name ¶
func (h *HuggingFace) Name() string
func (*HuggingFace) Synthesize ¶
func (h *HuggingFace) Synthesize(ctx context.Context, text string, opts SynthesizeOpts) (*Result, error)
type HuggingFaceOpts ¶
type HuggingFaceOpts struct {
Token string // HF API token
Model string // Model ID, e.g. "parler-tts/parler-tts-mini-multilingual-v1.1"
}
HuggingFaceOpts configures the HuggingFace TTS provider.
type OpenAI ¶
type OpenAI struct {
BaseURL string
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
OpenAI implements Provider using the OpenAI TTS API.
BaseURL is configurable for testing. It is validated against Validation on every request. Default Validation is strict (public https only).
func (*OpenAI) Synthesize ¶
type OpenAIOpts ¶
type OpenAIOpts struct {
APIKey string
Model string // "tts-1" or "tts-1-hd"
Voice string // alloy, echo, fable, onyx, nova, shimmer
}
OpenAIOpts configures the OpenAI TTS provider.
type Provider ¶
type Provider interface {
// Synthesize converts text to audio bytes.
Synthesize(ctx context.Context, text string, opts SynthesizeOpts) (*Result, error)
// Name returns the provider identifier (e.g. "openai", "google", "kokoro").
Name() string
// Health checks if the provider is reachable and ready.
Health(ctx context.Context) error
}
Provider defines the interface for all text-to-speech backends.
type Result ¶
type Result struct {
Audio []byte
Format string // Actual format of the audio data
SampleRate int // Sample rate in Hz (e.g. 24000)
Duration time.Duration // Estimated duration of the audio
Provider string
Voice string
}
Result holds the output of a TTS synthesis.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router selects and falls back between TTS providers.
func NewRouter ¶
NewRouter creates a TTS router with the given strategy and providers. Providers are tried in order according to the strategy.
func (*Router) HealthCheck ¶
HealthCheck returns health status for all providers.
func (*Router) SetProviders ¶
SetProviders replaces the provider list (thread-safe for runtime reconfiguration).
func (*Router) Synthesize ¶
Synthesize tries each provider in order until one succeeds.
type SynthesizeOpts ¶
type SynthesizeOpts struct {
Locale string // "de-DE", "en-US", "auto"
Voice string // Provider-specific voice ID; empty = default
Speed float64 // 0.25 - 4.0, default 1.0
Format string // "wav", "mp3", "opus", "pcm"; default "mp3"
}
SynthesizeOpts configures a single TTS request.