configureSTTFromMetadata
Auto-configures an STT provider's audio format settings from input metadata.
function configureSTTFromMetadata(stt, metadata): void;
Defined in: src/core/pipeline/configureSTTFromMetadata.ts:166
Auto-configures an STT provider’s audio format settings from input metadata.
Parameters
| Parameter | Type | Description |
|---|---|---|
stt | BaseProvider | The STT provider to auto-configure. Must have a public config property (all SDK STT providers expose this). |
metadata | AudioMetadata | Audio metadata from the input provider’s getMetadata() method. |
Returns
void
Remarks
This function bridges the gap between the input provider (which knows what audio format it produces) and the stt provider (which needs to know what format to expect). It identifies the STT provider by class name and fills in any unset audio format fields.
Detection: Uses provider.constructor.name to identify supported providers. This is reliable because the SDK is published as ES modules and class names are never minified.
Rules:
- Only sets fields that are currently
undefined— never overwrites user-specified values. - For DeepgramSTT / DeepgramFlux: fills
options.encoding,options.sampleRate, andoptions.channels. Creates theoptionsobject if it does not exist. - For AssemblyAISTT: fills
sampleRateon the top-level config. - For all other providers (NativeSTT, ElevenLabsSTT, etc.): no-op.
Example
import { configureSTTFromMetadata } from 'composite-voice';
import type { AudioMetadata } from 'composite-voice';
// Input provider reports its audio format
const metadata: AudioMetadata = {
sampleRate: 16000,
encoding: 'linear16',
channels: 1,
bitDepth: 16,
};
// DeepgramSTT with no explicit encoding/sampleRate/channels
const deepgramSTT = new DeepgramSTT({ apiKey: 'dg_...' });
configureSTTFromMetadata(deepgramSTT, metadata);
// deepgramSTT.config.options is now { encoding: 'linear16', sampleRate: 16000, channels: 1 }
// AssemblyAISTT with no explicit sampleRate
const assemblySTT = new AssemblyAISTT({ apiKey: 'aai_...' });
configureSTTFromMetadata(assemblySTT, metadata);
// assemblySTT.config.sampleRate is now 16000
// NativeSTT — no-op (browser manages its own audio)
const nativeSTT = new NativeSTT();
configureSTTFromMetadata(nativeSTT, metadata);
// No changes made
See
- AudioMetadata for the metadata structure
- AudioInputProvider.getMetadata for how metadata is obtained