tts

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 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 AudioFormat added in v0.2.0

type AudioFormat int
const (
	AudioFormatUnknown AudioFormat = iota
	AudioFormatMp3
)

type CachedTTSEngine

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

CachedTTSEngine is a wrapper around an Engine that caches the generated audio data. It uses redis to store the audio data with a key based on hash of the text, language code, and voice name.

func NewCachedTTSEngine

func NewCachedTTSEngine(nextEngine Engine, redisCache *cache.Cache, ttl time.Duration, hash hash.Hash) *CachedTTSEngine

NewCachedTTSEngine creates a new CachedTTSEngine with the provided nextEngine, redisCache, expiration time, and hash function.

func (*CachedTTSEngine) GenerateSpeech

func (c *CachedTTSEngine) GenerateSpeech(ctx context.Context, request SpeechRequest) (*SpeechResponse, error)

Generate generates the audio data for the given text, language code, and voice name.

func (*CachedTTSEngine) Name

func (c *CachedTTSEngine) Name() string

type Engine

type Engine interface {
	// Name returns the name of the TTS engine, e.g. "Google TTS", "Azure TTS", etc.
	Name() string

	// GenerateSpeech generates speech from the given text and returns the audio content.
	GenerateSpeech(ctx context.Context, request SpeechRequest) (resp *SpeechResponse, err error)
}

Engine is a generic interface for text-to-speech engines. It can be implemented by various TTS engines to provide a unified interface for text-to-speech operations. However, currently it is only implemented by the Google TTS engine so SynthetizeRequest leaks some Google TTS specific parameters.

FIXME: when other TTS engines are implemented, this interface should be made more generic. Yet, it is not clear how to make it generic, since different TTS engines have different parameters.

type EngineRegistry

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

func NewEngineRegistry

func NewEngineRegistry() *EngineRegistry

func (*EngineRegistry) Get

func (r *EngineRegistry) Get(identifier string) (Engine, bool)

func (*EngineRegistry) MustGet

func (r *EngineRegistry) MustGet(identifier string) Engine

func (*EngineRegistry) Register

func (r *EngineRegistry) Register(identifier string, engine Engine)

type GoogleEngine

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

GoogleEngine is an implementation of the Engine interface for Google Text-to-Speech.

func NewGoogleTTSEngine

func NewGoogleTTSEngine(client *texttospeech.Client) *GoogleEngine

func (*GoogleEngine) GenerateSpeech

func (g *GoogleEngine) GenerateSpeech(ctx context.Context, request SpeechRequest) (*SpeechResponse, error)

func (*GoogleEngine) Name

func (g *GoogleEngine) Name() string

type SpeechRequest

type SpeechRequest struct {
	Text         string
	LanguageCode string
	VoiceName    string
	SpeakingRate float64
}

type SpeechResponse added in v0.2.0

type SpeechResponse struct {
	Format       AudioFormat
	Channels     int
	AudioContent []byte
}

Jump to

Keyboard shortcuts

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