ttsAdapters

Registry of TTS adapters and related utilities.

Classes

BaseTTSAdapter
GoogleTTSAdapter
RestTTSAdapter
TTSAbortError
TTSSynthesizeError

Methods

(async, static) buildAuth(cfg) → {Promise.<{authHeaders: Object.<string, string>, authQuery: Object.<string, string>}>}

Build Authorization header (via jwtGet) and optional apiKey query.

Parameters:
NameTypeDescription
cfgObject
Properties
NameTypeAttributesDescription
jwtGetfunction<optional>

Optional async function to get JWT.

jwtHeaderNamestring<optional>

Header name, defaults to "Authorization".

jwtPrefixstring<optional>

Value prefix, defaults to "Bearer ".

apiKeystring<optional>

API key value.

apiKeyParamstring<optional>

API key query parameter name, defaults to "key".

Returns:
Type: 
Promise.<{authHeaders: Object.<string, string>, authQuery: Object.<string, string>}>

(static) defaultBuildRequest(input, cfg) → {Object}

Default request builder (HeadTTS-like JSON payload).

Parameters:
NameTypeDescription
inputObject
cfgObject
Returns:
Type: 
Object

(async, static) defaultParseResponse(res, input, _cfg) → {Promise.<*>}

Default response parser: expects JSON with base64 "audioContent" (or raw audio) and optional timings.

Parameters:
NameTypeDescription
resResponse
inputObject
_cfgObject
Returns:

Resolves with adapter output (see contracts: TTSAdapterOutput).

Type: 
Promise.<*>

(async, static) safeFetch(input, initopt) → {Promise.<Response>}

Wrap fetch with AbortSignal support and uniform errors.

Parameters:
NameTypeAttributesDescription
inputRequestInfo
initRequestInit<optional>

Fetch options. May include an AbortSignal to support cancellation.

Throws:

When aborted via init.signal.

Type
TTSAbortError
Returns:
Type: 
Promise.<Response>

Type Definitions

TTSAdapter

Minimal TTS adapter interface.

Type:
  • Object
Properties
NameTypeDescription
synthesizefunction

TTSAdapterInput

TTS adapter input. Plain text only (no SSML). Words array is optional but recommended if you want 1:1 word timings. The adapter should respect AbortSignal for cancellation.

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
textstring

plain text to synthesize (no SSML)

ssmlstring<optional>

optional SSML; if provided, adapter should prefer it over plain text

wordsArray.<string><optional>

words array (if provided, adapter should return 1:1 timings)

voicestring | Object<optional>

string or provider-specific voice object

ratenumber<optional>

normalized speed, adapter maps to provider scale

pitchnumber<optional>

semitones or provider scale

volumenumber<optional>

dB or provider scale

timeUnit'ms' | 's'<optional>
'ms'

time unit for words timings if provided

batchMode'sentence' | 'all'<optional>
'sentence'

how to batch input text

adapterConfigany<optional>

endpoint, headers, keys, etc.

signalAbortSignal<optional>

optional signal to support cancellation

TTSAdapterOutput

TTS adapter output. If provider does not support timings — return only audio. If you provide word-level timings use fields: words, wtimes, wduration. If you provide visemes — use fields: visemes, vtimes, vduration.

NOTE: timeUnit defaults to 'ms' unless explicitly set to 's'.

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
audioArrayBuffer<optional>

raw audio data (e.g., WAV, MP3, OGG)

timeUnit'ms' | 's'<optional>
'ms'

time unit for all timings below

wordsArray.<string><optional>

words as returned by provider or echoed from input

wtimesArray.<number><optional>

start times of words

wdurationArray.<number><optional>

durations of words

visemesArray.<string><optional>

visemes (e.g., "AI", "E", "U", "O", "CDGKNRSThYZ", "L", "MBP", "FV", "WQ", "rest")

vtimesArray.<number><optional>

center times of visemes

vdurationArray.<number><optional>

durations of visemes