Rate this page:

Speech synthesis

You can synthesise speech to your interlocutor before and during an active call or conference.

To synthesize speech during an inbound call, first answer a call. You can use the startEarlyMedia method to broadcast speech before the call is answered to create a greeting or a voicemail prompt.

To synthesize speech, use the createTTSPlayer() method in your scenario. Pass the text string to synthesize in the first parameter and options in the second parameter. See the code example below to understand how it works:

Synthesize speech

Synthesize speech

You can choose the voice for speech synthesis from one of these lists: VoiceList.Amazon, VoiceList.Google, VoiceList.Tinkoff, VoiceList.Yandex. The default voice is VoiceList.Amazon.en_US_Joanna.

If you have a custom Yandex engine voice, please contact support to activate this feature for your account, then specify the voice folder ID to the yandexCustomModelName property.

You can also configure other speech synthesis options, such as pitch, rate and volume. To specify them, list them in the ttsOptions parameter of the createTTSPlayer() method. See the code example below:

Configure the voice options

Configure the voice options

The options have the following values:

  • pitch (voice pitch) with the following acceptable ranges: 1) the numbers followed by "Hz" from 0.5Hz to 2Hz 2) x-low, low, medium, high, x-high, default

  • rate (speech speed) with the following possible values: x-slow, slow, medium, fast, x-fast, default

  • volume (speech volume) with the possible values: silent, x-soft, soft, medium, loud, x-loud, default

If you want to set them for the whole text, you do not have to use the speak tag. If you want to use specific attributes for a part of the text, specify the speak tag manually.

Plaase note

The supported tag list depend on the language provider. You can find these lists on their official websites. If you use a not supported tag, the PlaybackFinished event is triggered with the 400 error.

For example, if we choose Amazon, we have to use the prosody tag to control volume, rate, or pitch of the selected text fragment. Here is how we make this fragment sound higher:

Amazon's prosody tag

Amazon's prosody tag

Here's another example of a specific Amazon's tag say-as:

Amazon's say-as tag

Amazon's say-as tag