tts

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 10 Imported by: 0

README

togo

togo-framework/ai-tts

marketplace pkg.go.dev MIT

Part of the togo framework.

Install

togo install togo-framework/ai-tts

togo

ai-tts

Text-to-Speech for togo — multi-provider, one interface.


ai-tts adds text-to-speech to a togo app. It mirrors the togo driver pattern: a single Synthesize interface with swappable provider drivers, selected by TTS_DRIVER.

Install

togo install togo-framework/ai-tts

Drivers

Driver Env Notes
openai (default) OPENAI_API_KEY OpenAI TTS (tts-1, voices: alloy/echo/fable/onyx/nova/shimmer)
elevenlabs ELEVENLABS_API_KEY ElevenLabs (multilingual v2; voice = voice id)
TTS_DRIVER=elevenlabs
ELEVENLABS_API_KEY=...

Add another provider by registering a driver in an init() — see tts.RegisterDriver.

Use (Go)

svc, _ := tts.FromKernel(k)
res, err := svc.Synthesize(ctx, tts.Request{Text: "Hello from togo", Voice: "nova"})
// res.Audio (bytes), res.ContentType ("audio/mpeg")

Use (REST)

Mount the handler under /api/ai/tts:

mux.Handle("/api/ai/tts/", http.StripPrefix("/api/ai/tts", tts.Handler(k)))
curl -X POST http://localhost:8080/api/ai/tts/ \
  -H 'content-type: application/json' \
  -d '{"text":"Hello from togo","voice":"nova"}' --output hello.mp3

Pairs with ai-stt (speech-to-text) and the ai plugin. MIT.


Premium sponsors

ID8 Media  ·  One Studio

Support togo — become a sponsor.

Documentation

Overview

Package tts adds Text-to-Speech to togo. Drivers (elevenlabs, openai, …) register via init(); select one with TTS_DRIVER. Mirrors the ai plugin's driver pattern, so adding a provider is one self-contained driver. Mount the REST handler under /api/ai/tts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Drivers

func Drivers() []string

Drivers returns the registered driver names.

func Handler

func Handler(k *togo.Kernel) http.Handler

Handler exposes the TTS service over REST. Mount under /api/ai/tts in your app:

mux.Handle("/api/ai/tts/", http.StripPrefix("/api/ai/tts", tts.Handler(k)))

POST / with a JSON Request -> raw audio (audio/mpeg or audio/wav).

func RegisterDriver

func RegisterDriver(name string, f DriverFactory)

RegisterDriver registers a TTS driver (called from init()).

Types

type DriverFactory

type DriverFactory func(k *togo.Kernel) (Provider, error)

DriverFactory builds a Provider from the kernel/env.

type Provider

type Provider interface {
	Synthesize(ctx context.Context, req Request) (Result, error)
}

Provider is the TTS driver interface every driver implements.

type Request

type Request struct {
	Text   string `json:"text"`
	Voice  string `json:"voice,omitempty"`  // provider voice id/name
	Model  string `json:"model,omitempty"`  // provider model
	Format string `json:"format,omitempty"` // mp3 (default) | wav
}

Request is a synthesis request.

type Result

type Result struct {
	Audio       []byte
	ContentType string
}

Result is synthesized audio + its MIME type.

type Service

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

Service is the kernel-bound TTS service.

func FromKernel

func FromKernel(k *togo.Kernel) (*Service, bool)

FromKernel returns the TTS service bound to the kernel.

func (*Service) Driver

func (s *Service) Driver() string

Driver returns the active driver name.

func (*Service) Synthesize

func (s *Service) Synthesize(ctx context.Context, req Request) (Result, error)

Synthesize turns text into audio using the configured driver.

Jump to

Keyboard shortcuts

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