voice

package
v0.2.37 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDir

func CacheDir() string

CacheDir returns the voice cache directory path.

func Generate

func Generate(apiKey, model, voice, text string, speed float64) ([]byte, error)

Generate calls the OpenAI TTS API and returns raw WAV bytes.

func TextHash

func TextHash(text string) string

TextHash returns a truncated SHA-256 hash of the text (16 hex chars).

Types

type Cache

type Cache struct {
	Dir     string
	Entries map[string]CacheEntry // hash -> entry
}

Cache manages pre-generated voice WAV files.

func OpenCache

func OpenCache() (*Cache, error)

OpenCache loads or creates the voice cache index.

func (*Cache) Add

func (c *Cache) Add(text, voice string, wavData []byte) error

Add writes a WAV file to the cache and updates the index.

func (*Cache) Clear

func (c *Cache) Clear() (int, error)

Clear deletes all cached WAV files and the index.

func (*Cache) Lookup

func (c *Cache) Lookup(text string) (string, bool)

Lookup checks if text has a cached WAV file. Returns the file path and true if found, or empty string and false if not cached.

func (*Cache) Remove

func (c *Cache) Remove(hash string) error

Remove deletes a single cached WAV by hash and updates the index.

func (*Cache) Save

func (c *Cache) Save() error

Save writes the cache index to disk.

type CacheEntry

type CacheEntry struct {
	Text      string    `json:"text"`
	Voice     string    `json:"voice"`
	Hash      string    `json:"hash"`
	Size      int64     `json:"size"`
	CreatedAt time.Time `json:"created_at"`
}

CacheEntry describes a single cached voice file.

Jump to

Keyboard shortcuts

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