Introduction
In this tutorial, you will learn how to get a Text-To-Speech service on your calls using Voice API and TeXML.
Before starting, please ensure your Voice API or TeXML application is correctly configured.
Telnyx internal Text-to-Speech engine
Telnyx provides a high-quality, low-latency Text-to-Speech (TTS) engine, offering a seamless experience for integrating speech synthesis into your calls. The Telnyx TTS engine ensures a clear and natural-sounding voice, making it an excellent choice for real-time voice applications.
You can request Telnyx TTS for your calls using the Voice API. Below is an example of how to trigger speech synthesis with Telnyx TTS:
curl --location 'https://api.telnyx.com/v2/calls/v3:6MytEd1c56mFmXlAziof4tQd-eqOgwQqpFAvECu1gBRrvD5rmsclfg/actions/speak' \
--header 'Content-Type: application/json' \
--header 'Authorization: your_api_key' \
--data '{
"payload": "The text that should be said on the call",
"voice": "Telnyx.KokoroTTS.af"
}'
You can integrate Telnyx TTS into TeXML scripts using the following format:
<Response>
<Say voice="Telnyx.KokoroTTS.af">The text that should be said on the call!</Say>
</Response>
With its high-quality voices and low latency, Telnyx TTS is a great choice for users looking to integrate natural-sounding speech into their applications.
AWS Polly
Telnyx offers both levels of quality for AWS Polly Text-To-Speech services: neural and standard. The list of voices can be found under the link.
It can be requested on the call using the Voice API command similar to:
curl --location 'https://api.telnyx.com/v2/calls/v3:6MytEd1c56mFmXlAziof4tQd-eqOgwQqpFAvECu1gBRrvD5rmsclfg/actions/speak' \
--header 'Content-Type: application/json' \
--header 'Authorization: your_api_key' \
--data '{
"payload": "The text that should said on the call",
"voice": "Polly.Brian" || "Polly.Amy-Neural"
}'
It should be used in the following way from TeXML script:
<Response>
<Say voice="Polly.Amy-Neural">The text that should said on the call!</Say>
</Response>
The neural voice can be used by adding the prefix to the voice name - Polly.*-Neural
Before you use it, please take a look at the price list under the link.
Azure AI Speech
Telnyx supports Azure AI Speech as a text-to-speech provider as we. You can find the list of supported voices and languages at the following link.
To use Azure AI Speech, the process is the same as with AWS Polly. Voices should be specified using the following format: Azure.en-CA-ClaraNeural
.
Here’s an example of using the Telnyx Voice API to synthesize speech with Azure AI Speech:
curl --location 'https://api.telnyx.com/v2/calls/v3:6MytEd1c56mFmXlAziof4tQd-eqOgwQqpFAvECu1gBRrvD5rmsclfg/actions/speak' \
--header 'Content-Type: application/json' \
--header 'Authorization: your_api_key' \
--data '{
"payload": "The text that should said on the call",
"voice": "Azure.en-CA-ClaraNeural"
}'
The corresponding TeXML script would look like this:
<Response>
<Say voice="Azure.en-CA-ClaraNeural">The text that should said on the call!</Say>
</Response>
ElevenLabs
The ElevenLabs offers the best in class quality of the voices, however, the latency for the service is higher than in the case of AWS Polly or Azure AI Speech.
To use the integration, you must provide an API key to your ElevenLabs account.
Telnyx offers to store it in a secure storage. The API key can be saved in the following way:
curl --location 'https://api.telnyx.com/v2/integration_secrets' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
"identifier":"your_api_key_ref",
"value":"api_key"
}'
The speak
command should look as follows for the Voice API application:
curl --location 'https://api.telnyx.com/v2/calls/v3:6MytEd1c56mFmXlAziof4tQd-eqOgwQqpFAvECu1gBRrvD5rmsclfg/actions/speak' \
--header 'Content-Type: application/json' \
--header 'Authorization: your_api_key' \
--data '{
"payload": "The text that should said on the call",
"voice": "Elevenlabs.Default.cgSgspJ2msm6clMCkdW9",
"voice_settings": {"api_key_ref": "your_api_key_ref"}
}'
A similar effect can be achieved from TeXML using the following script:
<Response>
<Say voice="Elevenlabs.Default.cgSgspJ2msm6clMCkdW9" api_key_ref="your_api_key_ref">The text that should said on the call!</Say>
</Response>
Please note: only a premium ElevenLabs can be used for the integration. The freemium account is not supported
Basic support
Telnyx offers a free-of-charge option for Text-To-Speech as well. It is a perfect solution during the development cycle when some ideas must be tested, and reducing the service cost is important.
The basic support for Voice API can be requested in the following way:
curl --location 'https://api.telnyx.com/v2/calls/v3:6MytEd1c56mFmXlAziof4tQd-eqOgwQqpFAvECu1gBRrvD5rmsclfg/actions/speak' \
--header 'Content-Type: application/json' \
--header 'Authorization: your_api_key' \
--data '{
"payload": "The text that should said on the call",
"service_level": "basic",
"voice": "male"
}'
In a similar way, it can be used from TeXML:
<Response>
<Say voice="man">The text that should said on the call!</Say>
</Response>
}'
And that's it! If you have any questions about this tutorial or any of our products, reach out to our support team through the chat in the bottom right-hand corner.