BaseTTSProvider
Abstract base class shared by every TTS provider in CompositeVoice.
Defined in: src/providers/base/BaseTTSProvider.ts:68
Abstract base class shared by every TTS provider in CompositeVoice.
Remarks
BaseTTSProvider sits between BaseProvider and the two transport- specific bases (LiveTTSProvider and RestTTSProvider). It adds the audio callback and metadata callback mechanisms that all TTS providers use to deliver synthesized audio back to the SDK core.
The audio delivery pattern mirrors the STT transcription callback:
- The SDK (or consumer) registers listeners via onAudio and optionally onMetadata.
- Subclasses call emitAudio for each chunk of synthesized audio and emitMetadata once at the beginning of synthesis (if the provider can report format details up front).
Inheritance hierarchy:
BaseProvider
+-- BaseTTSProvider <-- you are here
+-- LiveTTSProvider (WebSocket streaming TTS)
+-- RestTTSProvider (REST batch TTS)
You typically do not extend BaseTTSProvider directly. Instead, extend LiveTTSProvider for WebSocket/streaming providers or RestTTSProvider for batch/REST providers.
Example
import { BaseTTSProvider } from 'composite-voice';
import type { TTSProviderConfig } from 'composite-voice';
import type { AudioChunk } from 'composite-voice';
class CustomTTSProvider extends BaseTTSProvider {
constructor(config: TTSProviderConfig) {
super('rest', config);
}
protected async onInitialize(): Promise<void> { }
protected async onDispose(): Promise<void> { }
async synthesize(text: string): Promise<Blob> {
const audioBlob = await myEngine.speak(text);
return audioBlob;
}
}
See
- LiveTTSProvider for WebSocket-based streaming TTS
- RestTTSProvider for REST/batch TTS
- BaseProvider for the root provider lifecycle
Extends
Constructors
Constructor
new BaseTTSProvider(
type,
config,
logger?): BaseTTSProvider;
Defined in: src/providers/base/BaseTTSProvider.ts:94
Create a new TTS provider.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | "rest" | "websocket" | Transport type ('rest' or 'websocket'). |
config | TTSProviderConfig | TTS provider configuration (voice, model, rate, etc.). |
logger? | Logger | Optional parent logger; a child will be derived. |
Returns
BaseTTSProvider
Overrides
Properties
| Property | Modifier | Type | Default value | Description | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|---|---|
audioCallback? | protected | (chunk) => void | undefined | Callback registered by the SDK or consumer to receive audio chunks. Set via onAudio. | - | - | src/providers/base/BaseTTSProvider.ts:79 |
config | public | TTSProviderConfig | undefined | TTS-specific provider configuration. | BaseProviderClass.config | - | src/providers/base/BaseTTSProvider.ts:73 |
initialized | protected | boolean | false | Tracks whether initialize has completed successfully. | - | BaseProviderClass.initialized | src/providers/base/BaseProvider.ts:97 |
logger | protected | Logger | undefined | Scoped logger instance for this provider. | - | BaseProviderClass.logger | src/providers/base/BaseProvider.ts:94 |
metadataCallback? | protected | (metadata) => void | undefined | Callback registered by the SDK or consumer to receive audio metadata. Set via onMetadata. | - | - | src/providers/base/BaseTTSProvider.ts:85 |
roles | readonly | readonly ProviderRole[] | undefined | TTS providers cover the 'tts' pipeline role by default. | BaseProviderClass.roles | - | src/providers/base/BaseTTSProvider.ts:70 |
type | readonly | ProviderType | undefined | Communication transport this provider uses ('rest' or 'websocket'). | - | BaseProviderClass.type | src/providers/base/BaseProvider.ts:74 |
Methods
assertReady()
protected assertReady(): void;
Defined in: src/providers/base/BaseProvider.ts:255
Guard that throws if the provider has not been initialized.
Returns
void
Remarks
Call at the start of any method that requires the provider to be ready.
Throws
Error Thrown with a descriptive message when initialized is false.
Inherited from
dispose()
dispose(): Promise<void>;
Defined in: src/providers/base/BaseProvider.ts:154
Clean up resources and dispose of the provider.
Returns
Promise<void>
Remarks
Delegates to the subclass hook onDispose and resets the initialized flag. If the provider is not initialized, the call is a no-op.
Throws
Re-throws any error raised by onDispose.
Inherited from
emitAudio()
protected emitAudio(chunk): void;
Defined in: src/providers/base/BaseTTSProvider.ts:138
Emit a synthesized audio chunk to the registered callback.
Parameters
| Parameter | Type | Description |
|---|---|---|
chunk | AudioChunk | The audio chunk to emit. |
Returns
void
Remarks
Subclasses call this method for each chunk of audio produced during synthesis. If no callback has been registered the chunk is silently dropped.
emitMetadata()
protected emitMetadata(metadata): void;
Defined in: src/providers/base/BaseTTSProvider.ts:154
Emit audio metadata to the registered callback.
Parameters
| Parameter | Type | Description |
|---|---|---|
metadata | AudioMetadata | The audio metadata to emit. |
Returns
void
Remarks
Typically called once at the start of synthesis when the provider knows the output format. If no callback has been registered the metadata is silently dropped.
getConfig()
getConfig(): TTSProviderConfig;
Defined in: src/providers/base/BaseTTSProvider.ts:165
Get a shallow copy of the current TTS configuration.
Returns
A new TTSProviderConfig object.
Overrides
initialize()
initialize(): Promise<void>;
Defined in: src/providers/base/BaseProvider.ts:127
Initialize the provider, making it ready for use.
Returns
Promise<void>
Remarks
Calls the subclass hook onInitialize. If the provider has already been initialized the call is a no-op.
Throws
ProviderInitializationError Thrown when onInitialize rejects. The original error is wrapped with the provider class name for diagnostics.
Inherited from
isReady()
isReady(): boolean;
Defined in: src/providers/base/BaseProvider.ts:178
Check whether the provider has been initialized and is ready.
Returns
boolean
true when initialize has completed successfully and dispose has not yet been called.
Inherited from
onAudio()
onAudio(callback): void;
Defined in: src/providers/base/BaseTTSProvider.ts:109
Register a callback to receive synthesized audio chunks.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (chunk) => void | Function invoked with each AudioChunk. |
Returns
void
Remarks
All TTS providers — regardless of transport — deliver audio through this callback. CompositeVoice registers it during pipeline setup so that audio data flows into the AudioPlayer.
onConfigUpdate()
protected onConfigUpdate(_config): void;
Defined in: src/providers/base/BaseProvider.ts:242
Hook called after updateConfig merges new values.
Parameters
| Parameter | Type | Description |
|---|---|---|
_config | Partial<BaseProviderConfig> | The partial configuration that was merged. |
Returns
void
Remarks
The default implementation is a no-op. Override in subclasses to react to runtime configuration changes (e.g. reconnect with a new API key).
Inherited from
BaseProviderClass.onConfigUpdate
onDispose()
abstract protected onDispose(): Promise<void>;
Defined in: src/providers/base/BaseProvider.ts:229
Provider-specific disposal logic.
Returns
Promise<void>
Remarks
Subclasses must implement this method to release any resources acquired during onInitialize (e.g. close connections, free memory).
Inherited from
onInitialize()
abstract protected onInitialize(): Promise<void>;
Defined in: src/providers/base/BaseProvider.ts:217
Provider-specific initialization logic.
Returns
Promise<void>
Remarks
Subclasses must implement this method to perform any setup required before the provider can be used (e.g. validate credentials, open connections, load models).
Inherited from
BaseProviderClass.onInitialize
onMetadata()
onMetadata(callback): void;
Defined in: src/providers/base/BaseTTSProvider.ts:124
Register a callback to receive audio metadata.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (metadata) => void | Function invoked with AudioMetadata when available. |
Returns
void
Remarks
Metadata (sample rate, encoding, channels, etc.) helps the AudioPlayer configure playback correctly. Providers may emit metadata once at the start of synthesis but are not required to.
updateConfig()
updateConfig(config): void;
Defined in: src/providers/base/BaseProvider.ts:201
Merge partial configuration updates into the current config.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | Partial<BaseProviderConfig> | A partial configuration object whose keys will overwrite existing values. |
Returns
void
Remarks
After merging, the subclass hook onConfigUpdate is called so providers can react to changed values at runtime.