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.
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.
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.
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>
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.