tts

package
v0.14.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Google

type Google struct {
	// contains filtered or unexported fields
}

Google implements Provider using the Google Cloud Text-to-Speech API.

func NewGoogle

func NewGoogle(opts GoogleOpts) *Google

NewGoogle creates a Google Cloud TTS provider.

func (*Google) Health

func (g *Google) Health(ctx context.Context) error

func (*Google) Name

func (g *Google) Name() string

func (*Google) Synthesize

func (g *Google) Synthesize(ctx context.Context, text string, opts SynthesizeOpts) (*Result, error)

type GoogleOpts

type GoogleOpts struct {
	APIKey string
	Voice  string // e.g. "de-DE-Neural2-B", "en-US-Neural2-J"
}

GoogleOpts configures the Google TTS provider.

type HuggingFace

type HuggingFace struct {
	// contains filtered or unexported fields
}

HuggingFace implements Provider using the HuggingFace Inference API with text-to-speech models (e.g. parler-tts).

func NewHuggingFace

func NewHuggingFace(opts HuggingFaceOpts) *HuggingFace

NewHuggingFace creates a HuggingFace TTS provider.

func (*HuggingFace) Health

func (h *HuggingFace) Health(ctx context.Context) error

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 {
	// contains filtered or unexported fields
}

OpenAI implements Provider using the OpenAI TTS API.

func NewOpenAI

func NewOpenAI(opts OpenAIOpts) *OpenAI

NewOpenAI creates an OpenAI TTS provider.

func (*OpenAI) Health

func (o *OpenAI) Health(ctx context.Context) error

func (*OpenAI) Name

func (o *OpenAI) Name() string

func (*OpenAI) Synthesize

func (o *OpenAI) Synthesize(ctx context.Context, text string, opts SynthesizeOpts) (*Result, error)

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

func NewRouter(strategy Strategy, providers ...Provider) *Router

NewRouter creates a TTS router with the given strategy and providers. Providers are tried in order according to the strategy.

func (*Router) HealthCheck

func (r *Router) HealthCheck(ctx context.Context) map[string]error

HealthCheck returns health status for all providers.

func (*Router) SetProviders

func (r *Router) SetProviders(providers ...Provider)

SetProviders replaces the provider list (thread-safe for runtime reconfiguration).

func (*Router) Synthesize

func (r *Router) Synthesize(ctx context.Context, text string, opts SynthesizeOpts) (*Result, error)

Synthesize tries each provider in order until one succeeds.

type Strategy

type Strategy string

Strategy determines how the TTS router selects a provider.

const (
	StrategyCloudFirst Strategy = "cloud-first" // Default: try cloud providers first
	StrategyLocalFirst Strategy = "local-first" // Try local (Kokoro) first, cloud fallback
	StrategyCloudOnly  Strategy = "cloud-only"
	StrategyLocalOnly  Strategy = "local-only"
)

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.

Jump to

Keyboard shortcuts

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