addLanguage

View as MarkdownOpen in Claude

Add a language configuration with voice settings. The agent uses these configurations to support multilingual conversations with appropriate TTS voices.

Language configurations map to the SWML ai.languages array. See the SWML languages reference for the full specification.

Write voice as "engine.voice", optionally with a ":model" suffix. A bare voice name works only alongside an explicit engine field, because on its own it resolves against a default engine that can change.

Parameters

config
LanguageConfigRequired

A language configuration object with the following fields:

config.name
stringRequired

Human-readable language name (e.g., "English", "French", "Spanish").

config.code
stringRequired

Language code (e.g., "en-US", "fr-FR", "es-MX").

config.voice
string

TTS voice identifier. Accepts one of three formats:

  • Engine and voice: "elevenlabs.josh"
  • Engine, voice, and model: "elevenlabs.josh:eleven_turbo_v2_5"
  • Voice name with explicit engine: "josh"

Always name the engine, either in the voice string or through engine. A voice name on its own — "en-US-Neural2-F" — is resolved against a default engine, and that default can change.

config.engine
string

Explicit TTS engine name (e.g., "elevenlabs", "rime").

config.fillers
Record<string, string[]>

Filler phrases keyed by category for this language.

config.speechModel
string

Speech recognition model identifier.

config.functionFillers
Record<string, Record<string, string[]>>

Per-function filler phrases, keyed by function name then language code.

config.params
Record<string, unknown>

Optional per-language params dictionary for engine-specific tuning (e.g. voice settings). Only emitted into the SWML document when non-empty, so existing entries stay byte-identical when omitted. Can also be set or updated later via setLanguageParams().

Returns

AgentBase — Returns this for method chaining.

Examples

Engine and voice (engine.voice)

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'support', route: '/support' });
4agent.setPromptText('You are a helpful assistant.');
5agent.addLanguage({ name: 'English', code: 'en-US', voice: 'rime.spore' });
6await agent.serve();

Explicit engine

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'support', route: '/support' });
4agent.setPromptText('You are a helpful assistant.');
5agent.addLanguage({
6 name: 'English',
7 code: 'en-US',
8 voice: 'josh',
9 engine: 'elevenlabs',
10});
11await agent.serve();

With fillers

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'support', route: '/support' });
4agent.setPromptText('You are a helpful assistant.');
5agent.addLanguage({
6 name: 'English',
7 code: 'en-US',
8 voice: 'rime.spore',
9 fillers: {
10 speech: ['Um...', 'Let me think...'],
11 },
12 functionFillers: {
13 get_weather: { 'en-US': ['Checking the weather...', 'One moment please...'] },
14 },
15});
16await agent.serve();