tts

package
v0.40.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 3 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 tts exposes the embeddable SpeechKit text-to-speech surface.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingRouter = errors.New("speechkit tts: router is required")

Functions

func PreferredProviderForProfileID

func PreferredProviderForProfileID(profileID string) string

PreferredProviderForProfileID maps a Voice-Output profile ID to Provider.Name.

Types

type Provider

type Provider interface {
	Synthesize(ctx context.Context, text string, opts SynthesizeOpts) (*Result, error)
	Name() string
	Kind() ProviderKind
	Health(ctx context.Context) error
}

Provider defines the interface for text-to-speech backends.

func OrderByPreferredProvider

func OrderByPreferredProvider(providers []Provider, preferred string) []Provider

OrderByPreferredProvider returns providers with the matching provider first.

type ProviderKind

type ProviderKind string

ProviderKind identifies whether a provider is local, cloud-routed, or a direct external API. Router strategies use this instead of provider names.

const (
	ProviderKindLocalBuiltIn   ProviderKind = "local_built_in"
	ProviderKindLocalProvider  ProviderKind = "local_provider"
	ProviderKindCloudProvider  ProviderKind = "cloud_provider"
	ProviderKindDirectProvider ProviderKind = "direct_provider"
)

type Result

type Result struct {
	Audio      []byte
	Format     string
	SampleRate int
	Duration   time.Duration
	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.

func (*Router) CloseIdleConnections

func (r *Router) CloseIdleConnections()

CloseIdleConnections asks HTTP-backed providers to drop idle connection pools.

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.

func (*Router) Synthesize

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

Synthesize tries each eligible provider until one succeeds.

type Service

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

Service is a small stable facade over Router. It gives embedders one construction point while still letting them provide their own providers.

func NewService

func NewService(router *Router, opts ...ServiceOption) (*Service, error)

func (*Service) Router

func (s *Service) Router() *Router

func (*Service) Synthesize

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

type ServiceOption

type ServiceOption func(*Service)

func WithDefaultOpts

func WithDefaultOpts(opts SynthesizeOpts) ServiceOption

type Strategy

type Strategy string

Strategy determines how Router selects providers.

const (
	StrategyCloudFirst Strategy = "cloud-first"
	StrategyLocalFirst Strategy = "local-first"
	StrategyCloudOnly  Strategy = "cloud-only"
	StrategyLocalOnly  Strategy = "local-only"
)

type SynthesizeOpts

type SynthesizeOpts struct {
	Locale string
	Voice  string
	Speed  float64
	Format string
}

SynthesizeOpts configures a single TTS request.

Jump to

Keyboard shortcuts

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