Providers
TTS Adapters
Configure text-to-speech adapters for avatar speech synthesis.
ElevenLabs
import { ElevenLabsAdapter } from "avatarlayer";
const tts = new ElevenLabsAdapter({
apiKey: "...",
voiceId: "21m00Tcm4TlvDq8ikWAM", // optional, defaults to Rachel
modelId: "eleven_multilingual_v2", // optional
baseURL: "https://...", // optional
});Constructor options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | ElevenLabs API key |
voiceId | string | "21m00Tcm4TlvDq8ikWAM" (Rachel) | Default voice ID |
modelId | string | "eleven_multilingual_v2" | Default TTS model |
baseURL | string | "https://api.elevenlabs.io/v1" | Base URL for API |
Synthesize options
You can override defaults per-call via TTSOptions:
const blob = await tts.synthesize("Hello world", {
voiceId: "different-voice",
speed: 1.2,
stability: 0.5,
similarityBoost: 0.75,
outputFormat: "mp3_44100_128",
});| Option | Type | Description |
|---|---|---|
voiceId | string | Override voice for this call |
modelId | string | Override model for this call |
speed | number | Playback speed multiplier |
outputFormat | string | Audio format (default: mp3_44100_128) |
stability | number | Voice stability (0-1) |
similarityBoost | number | Voice similarity boost (0-1) |
signal | AbortSignal | Cancellation signal |
OpenAI TTS
import { OpenAITTSAdapter } from "avatarlayer";
const tts = new OpenAITTSAdapter({
apiKey: "sk-...",
voice: "alloy", // optional
model: "tts-1", // optional
baseURL: "https://...", // optional
});Constructor options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | OpenAI API key |
voice | string | "alloy" | Voice name (alloy, echo, fable, onyx, nova, shimmer) |
model | string | "tts-1" | TTS model (tts-1 or tts-1-hd) |
baseURL | string | OpenAI default | Base URL for API |
Azure TTS
import { AzureTTSAdapter } from "avatarlayer";
const tts = new AzureTTSAdapter({
subscriptionKey: "...",
region: "eastus",
voice: "en-US-JennyNeural", // optional
});Constructor options
| Option | Type | Default | Description |
|---|---|---|---|
subscriptionKey | string | required | Azure Speech subscription key |
region | string | required | Azure region (e.g. "eastus") |
voice | string | "en-US-JennyNeural" | Voice name |
outputFormat | string | "audio-24khz-48kbitrate-mono-mp3" | Audio output format |
Google TTS
import { GoogleTTSAdapter } from "avatarlayer";
const tts = new GoogleTTSAdapter({
apiKey: "...",
voice: "en-US-Standard-C", // optional
languageCode: "en-US", // optional
});Constructor options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Google Cloud API key |
voice | string | "en-US-Standard-C" | Voice name |
languageCode | string | "en-US" | BCP-47 language code |
audioEncoding | string | "MP3" | Audio encoding (MP3, LINEAR16, OGG_OPUS) |
TTSProvider interface
Implement this interface to add your own TTS engine:
interface TTSProvider {
readonly id: string;
synthesize(text: string, opts?: TTSOptions): Promise<Blob>;
}The returned Blob should contain audio data (MP3, WAV, etc.) that can be decoded by the browser's AudioContext.decodeAudioData or played via an <audio> element.
See Custom Adapters for a full implementation example.