playTTS

View as MarkdownOpen in Claude

Play text-to-speech on the call. A typed convenience over play() that builds the TTS media item for you.

Parameters

text
stringRequired

The text to speak.

options
object

Voice and playback options.

options.language
string

Language code for the voice, such as "en-US".

options.gender
TtsGender

"male" or "female".

options.voice
string

Voice identifier for the TTS engine.

options.volume
number

Volume adjustment in dB, from -40 to 40.

options.onCompleted
(event: RelayEvent) => void | Promise<void>

Callback invoked when the operation reaches a terminal state.

Returns

Promise<PlayAction> — An action handle with stop(), pause(), resume(), volume(), and wait() methods.

Example

import { RelayClient } from '@signalwire/sdk';
const client = new RelayClient({
project: process.env.SIGNALWIRE_PROJECT_ID!,
token: process.env.SIGNALWIRE_API_TOKEN!,
contexts: ['default']
});
client.onCall(async (call) => {
await call.answer();
const action = await call.playTTS('Welcome to Bayview Taxi.', { language: 'en-US' });
await action.wait();
});
await client.run();