ProviderEventAdapter
Optional adapter that bridges provider callbacks to a typed EventEmitter.
Defined in: src/core/ProviderEventAdapter.ts:70
Optional adapter that bridges provider callbacks to a typed EventEmitter.
Remarks
This is not used by the default pipeline. CompositeVoice wires providers directly via callbacks for minimal overhead. Use this adapter when you need provider-level event subscriptions outside of CompositeVoice, such as for testing, debugging, or building custom pipelines.
The adapter registers itself as the callback consumer on each provider via bridgeSTT() and bridgeTTS(), then re-emits each callback invocation as a typed event through the inherited EventEmitter interface.
Important: Calling bridgeSTT() or bridgeTTS() will replace any previously registered callback on the provider. Do not use this adapter on providers that are already wired into a CompositeVoice instance.
Examples
import { ProviderEventAdapter } from 'composite-voice';
import { DeepgramSTT, DeepgramTTS } from 'composite-voice';
const adapter = new ProviderEventAdapter();
const stt = new DeepgramSTT({ apiKey: '...' });
const tts = new DeepgramTTS({ apiKey: '...' });
adapter.bridgeSTT(stt);
adapter.bridgeTTS(tts);
// Subscribe to provider-level events
adapter.on('tts.audio', (event) => {
console.log('Raw TTS chunk:', event.chunk.data.byteLength, 'bytes');
});
adapter.on('transcription.interim', (event) => {
console.log('Interim:', event.text);
});
const adapter = new ProviderEventAdapter();
adapter.bridgeSTT(myCustomSTT);
const results: TranscriptionResult[] = [];
adapter.on('stt.transcription', (event) => {
results.push(event.result);
});
await myCustomSTT.initialize();
// ... trigger transcription ...
expect(results).toHaveLength(1);
See
- EventEmitter for subscription methods (
on,once,off) - ARCHITECTURE.md for why this adapter exists and when to use it
Extends
Constructors
Constructor
new ProviderEventAdapter(maxListeners?): ProviderEventAdapter;
Defined in: src/core/events/EventEmitter.ts:77
Creates a new EventEmitter instance.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
maxListeners | number | 100 | The maximum number of listeners allowed per event type before a memory leak warning is logged to the console. Defaults to 100. |
Returns
ProviderEventAdapter
Inherited from
Methods
bridgeSTT()
bridgeSTT(stt): void;
Defined in: src/core/ProviderEventAdapter.ts:83
Bridge an STT provider’s transcription callback to this event emitter.
Parameters
| Parameter | Type | Description |
|---|---|---|
stt | BaseSTTProvider | The STT provider to bridge. |
Returns
void
Remarks
Registers an onTranscription callback on the provider that re-emits each TranscriptionResult as an 'stt.transcription' event.
Warning: This replaces any previously registered transcription callback on the provider.
bridgeTTS()
bridgeTTS(tts): void;
Defined in: src/core/ProviderEventAdapter.ts:105
Bridge a TTS provider’s audio and metadata callbacks to this event emitter.
Parameters
| Parameter | Type | Description |
|---|---|---|
tts | BaseTTSProvider | The TTS provider to bridge. |
Returns
void
Remarks
Registers onAudio and onMetadata callbacks on the provider that re-emit as 'tts.audio' and 'tts.metadata' events respectively.
Warning: This replaces any previously registered audio and metadata callbacks on the provider.
emit()
emit<T>(event): Promise<void>;
Defined in: src/core/events/EventEmitter.ts:206
Emit an event to all registered listeners
Type Parameters
| Type Parameter |
|---|
T extends CompositeVoiceEvent |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | T | Event object to emit |
Returns
Promise<void>
Inherited from
emitSync()
emitSync<T>(event): void;
Defined in: src/core/events/EventEmitter.ts:228
Emit an event synchronously (doesn’t wait for async listeners)
Type Parameters
| Type Parameter |
|---|
T extends CompositeVoiceEvent |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | T | Event object to emit |
Returns
void
Inherited from
eventNames()
eventNames(): (
| "transcription.start"
| "transcription.interim"
| "transcription.final"
| "transcription.speechFinal"
| "transcription.preflight"
| "transcription.error"
| "llm.start"
| "llm.chunk"
| "llm.complete"
| "llm.error"
| "tts.start"
| "tts.audio"
| "tts.metadata"
| "tts.complete"
| "tts.error"
| "agent.ready"
| "agent.stateChange"
| "agent.error"
| "audio.capture.start"
| "audio.capture.stop"
| "audio.capture.error"
| "audio.playback.start"
| "audio.playback.end"
| "audio.playback.error"
| "queue.overflow"
| "queue.stats"
| "*")[];
Defined in: src/core/events/EventEmitter.ts:258
Get all event types that have listeners
Returns
( | "transcription.start" | "transcription.interim" | "transcription.final" | "transcription.speechFinal" | "transcription.preflight" | "transcription.error" | "llm.start" | "llm.chunk" | "llm.complete" | "llm.error" | "tts.start" | "tts.audio" | "tts.metadata" | "tts.complete" | "tts.error" | "agent.ready" | "agent.stateChange" | "agent.error" | "audio.capture.start" | "audio.capture.stop" | "audio.capture.error" | "audio.playback.start" | "audio.playback.end" | "audio.playback.error" | "queue.overflow" | "queue.stats" | "*")[]
Array of event types
Inherited from
getMaxListeners()
getMaxListeners(): number;
Defined in: src/core/events/EventEmitter.ts:274
Get the maximum number of listeners per event
Returns
number
Maximum number of listeners
Inherited from
listenerCount()
listenerCount(event): number;
Defined in: src/core/events/EventEmitter.ts:249
Get the number of listeners for an event
Parameters
| Parameter | Type | Description |
|---|---|---|
event | | "transcription.start" | "transcription.interim" | "transcription.final" | "transcription.speechFinal" | "transcription.preflight" | "transcription.error" | "llm.start" | "llm.chunk" | "llm.complete" | "llm.error" | "tts.start" | "tts.audio" | "tts.metadata" | "tts.complete" | "tts.error" | "agent.ready" | "agent.stateChange" | "agent.error" | "audio.capture.start" | "audio.capture.stop" | "audio.capture.error" | "audio.playback.start" | "audio.playback.end" | "audio.playback.error" | "queue.overflow" | "queue.stats" | "*" | Event type |
Returns
number
Number of listeners
Inherited from
off()
off<T>(event, listener): void;
Defined in: src/core/events/EventEmitter.ts:177
Remove an event listener
Type Parameters
| Type Parameter |
|---|
T extends | "transcription.start" | "transcription.interim" | "transcription.final" | "transcription.speechFinal" | "transcription.preflight" | "transcription.error" | "llm.start" | "llm.chunk" | "llm.complete" | "llm.error" | "tts.start" | "tts.audio" | "tts.metadata" | "tts.complete" | "tts.error" | "agent.ready" | "agent.stateChange" | "agent.error" | "audio.capture.start" | "audio.capture.stop" | "audio.capture.error" | "audio.playback.start" | "audio.playback.end" | "audio.playback.error" | "queue.overflow" | "queue.stats" |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | "*" | T | Event type |
listener | T extends "*" ? EventListener : EventListenerMap[T] | Listener function to remove |
Returns
void
Inherited from
on()
on<T>(event, listener): () => void;
Defined in: src/core/events/EventEmitter.ts:110
Registers an event listener for the specified event type.
Type Parameters
| Type Parameter | Description |
|---|---|
T extends | "transcription.start" | "transcription.interim" | "transcription.final" | "transcription.speechFinal" | "transcription.preflight" | "transcription.error" | "llm.start" | "llm.chunk" | "llm.complete" | "llm.error" | "tts.start" | "tts.audio" | "tts.metadata" | "tts.complete" | "tts.error" | "agent.ready" | "agent.stateChange" | "agent.error" | "audio.capture.start" | "audio.capture.stop" | "audio.capture.error" | "audio.playback.start" | "audio.playback.end" | "audio.playback.error" | "queue.overflow" | "queue.stats" | The event type string, inferred from the event argument. |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | "*" | T | The event type to listen for (e.g., 'llm.chunk'), or '*' to receive all events. |
listener | T extends "*" ? EventListener : EventListenerMap[T] | The callback function invoked when the event fires. |
Returns
A function that, when called, removes this listener (equivalent to calling off()).
(): void;
Returns
void
Remarks
If the number of listeners for the given event exceeds the configured maximum (see setMaxListeners()), a warning is logged to the console to help detect memory leaks. The listener is stored in a Set, so adding the same function reference twice for the same event is a no-op.
Example
const unsubscribe = emitter.on('tts.complete', () => {
console.log('TTS playback finished');
});
// Later, remove the listener
unsubscribe();
Inherited from
once()
once<T>(event, listener): () => void;
Defined in: src/core/events/EventEmitter.ts:160
Registers a one-time event listener that automatically unsubscribes after its first invocation.
Type Parameters
| Type Parameter | Description |
|---|---|
T extends | "transcription.start" | "transcription.interim" | "transcription.final" | "transcription.speechFinal" | "transcription.preflight" | "transcription.error" | "llm.start" | "llm.chunk" | "llm.complete" | "llm.error" | "tts.start" | "tts.audio" | "tts.metadata" | "tts.complete" | "tts.error" | "agent.ready" | "agent.stateChange" | "agent.error" | "audio.capture.start" | "audio.capture.stop" | "audio.capture.error" | "audio.playback.start" | "audio.playback.end" | "audio.playback.error" | "queue.overflow" | "queue.stats" | The event type string, inferred from the event argument. |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | T | The event type to listen for. |
listener | EventListenerMap[T] | The callback function invoked once when the event fires. |
Returns
A function that, when called, removes this listener before it has a chance to fire.
(): void;
Returns
void
Remarks
Internally, this wraps the provided listener in a function that calls off() before invoking the original callback. The returned unsubscribe function can be called to cancel the listener before it fires.
Example
emitter.once('agent.ready', () => {
console.log('This will only fire once');
});
Inherited from
removeAllListeners()
removeAllListeners(event?): void;
Defined in: src/core/events/EventEmitter.ts:194
Remove all listeners for an event, or all listeners if no event specified
Parameters
| Parameter | Type | Description |
|---|---|---|
event? | | "transcription.start" | "transcription.interim" | "transcription.final" | "transcription.speechFinal" | "transcription.preflight" | "transcription.error" | "llm.start" | "llm.chunk" | "llm.complete" | "llm.error" | "tts.start" | "tts.audio" | "tts.metadata" | "tts.complete" | "tts.error" | "agent.ready" | "agent.stateChange" | "agent.error" | "audio.capture.start" | "audio.capture.stop" | "audio.capture.error" | "audio.playback.start" | "audio.playback.end" | "audio.playback.error" | "queue.overflow" | "queue.stats" | "*" | Optional event type to remove listeners for |
Returns
void
Inherited from
EventEmitter.removeAllListeners
setMaxListeners()
setMaxListeners(n): void;
Defined in: src/core/events/EventEmitter.ts:266
Set the maximum number of listeners per event
Parameters
| Parameter | Type | Description |
|---|---|---|
n | number | Maximum number of listeners |
Returns
void