New TTS provider (Go)
Build
- One package per provider:
acceleration/internal/tts/<name>/<name>.go, implementingtts.TTS(Start,Synthesize,Interrupt,Events,Close,Provider,Model,Streaming,Performs,Prompt) plusSampleRate() int, which the suite needs. - One utterance is one
Request.ID: several requests stream text into it, the one withFinalcloses it. Lettts.NewSynthesis(id)do the bookkeeping —AddText,Chunk,Complete— so characters, audio duration and time-to-first-byte are counted the same way everywhere. - Emit through
tts.NewEmitter(64). Every utterance must settle exactly once:Interrupt, a dead connection andCloseall owe aSynthesisComplete, interrupted, or the stats lose work. - Options struct with an
APIKeythat falls back to the provider's env var. Validate inNewand return a descriptive error rather than failing at connect time. - Register it in ttsrouter/registry.go so routing config can name it.
Test
Three files, in this order of value:
<name>_test.go— no network. FeedhandleMessage(or its equivalent) server frames and assert the events that come out.socket_test.go— a fake WebSocket or HTTP server. Asserts what goes on the wire (setup frame, flush on final, close).integration_test.go—//go:build integration, embedsttssuite.Suite:
gosuite.Run(t, &XIntegrationSuite{Suite: ttssuite.Suite{ New: func() ttssuite.Provider { p, err := New(Options{}); require.NoError(t, err); return p }, Requires: []string{"X_API_KEY"}, Interruptible: true, // set unless the provider generates the whole utterance regardless MaxTimeToFirstByte: 2_000, // ms; omit when latency is not what this provider is kept for Timeout: time.Minute, // raise for a deployment that scales to zero }})
That inherits real speech (format, chunking, billed characters, duration, TTFB), deltas becoming one utterance, and barge-in. Only add provider-specific tests on top, built on s.Started, s.Say and s.Hangup; .env is loaded for you. A test needing its own options builds the provider itself and passes it to s.Start.
Run
bashcd acceleration go test ./internal/tts/... # unit + socket go test -tags integration -run TestXIntegrationSuite ./internal/tts/x # live


