promptTTS

View as Markdown

promptTTS

  • promptTTS(params): Promise<CallPrompt> - See CallPrompt for more details.

Play text-to-speech while collecting user input from the call, such as digits or speech.

Parameters

NameTypeDescription
paramsObject-
params.textstringText to play. SSML may be entered as a string wrapped in <speak> tags.
See our supported voices and languages documentation for usage and supported tags.
params.digits?CollectDigitsConfigConfiguration for collecting digits. You must either set this, or speech.
params.speech?CollectSpeechConfigConfiguration for collecting speech. You must either set this, or digits. Pass an empty object to use the default configuration.
params.gender?"male" | "female"Gender of the voice (male or female). Defaults to female.
params.initialTimeout?numberInitial timeout in seconds. Default is 4 seconds.
params.language?stringLanguage of the text in ISO 639-1 (language name) + ISO 3166 (country code). Defaults to en-US.
Supported languages can be found here
params.volume?numberVolume value between -40dB and +40dB where 0 is unchanged. Default is 0.
params.voice?stringVoice to use (takes precedence on gender).
Supported voices can be found here

Returns

Promise<CallPrompt> - See CallPrompt for more details.

Examples

Prompting for digits and waiting for a result:

1const prompt = await call.promptTTS({
2 text: "Please enter your PIN",
3 digits: {
4 max: 5,
5 digitTimeout: 2,
6 terminators: "#*",
7 },
8});
9const { type, digits, terminator } = await prompt.ended();

Prompting for speech and waiting for a result:

1const prompt = await call.promptTTS({
2 text: "Please enter your PIN",
3 speech: {
4 endSilenceTimeout: 1,
5 speechTimeout: 60,
6 language: "en-US",
7 hints: [],
8 },
9});
10const { type, text, terminator } = await prompt.ended();

Prompting for speech and listening for results using the events:

1call.on("prompt.started", (p) => {
2 console.log("prompt.started", p.id);
3});
4call.on("prompt.updated", (p) => {
5 console.log("prompt.updated", p.id);
6});
7call.on("prompt.failed", (p) => {
8 console.log("prompt.failed", p.id, p.reason);
9});
10call.on("prompt.ended", (p) => {
11 console.log(prompt.ended, p.id, p.text);
12});
13
14const prompt = await call.promptTTS({
15 text: "Please enter your PIN",
16 speech: {},
17});

Prompting for digits with SSML and waiting for a result:

1const prompt = await call.promptTTS({
2 text: `<speak>
3 Please enter your <say-as interpret-as="characters">UUID</say-as>.
4 It should be a <say-as interpret-as="cardinal">10</say-as> digit number.
5 </speak>`,
6 voice: "polly.Joey",
7 digits: {
8 max: 5,
9 digitTimeout: 2,
10 terminators: "#*",
11 },
12});
13const { type, speech, terminator } = await prompt.ended();