Synchronous, How to Use Typecast APIs¶
Caution
This feature is not available to all customers. Please contact our sales team for eligibility details.
You can receive audio with a single request. While the existing API uses polling or webhook-based asynchronous methods, this approach allows you to receive the requested audio more quickly.
Using cURL¶
Example Request:
curl \
--request POST \
--url https://typecast.ai/api/text-to-speech \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $API_TOKEN" \
--data '{
"text": "My name is Typecast.",
"lang": "auto",
"actor_id": "${24-letters-your_actor_id}",
"xapi_hd": true,
"model_version": "latest"
}'
In the example above, make sure to replace ${24-letters-your_actor_id}
with your actual actor ID. You can obtain a list of available actor IDs by making a GET
request to /api/actor
. For more information about the API, see full API reference.
If you need more details about the parameters and options for the POST /api/text-to-speech
API, please refer to the full API reference.
Example Response:
Upon success, you will receive a binary file containing the synthesized audio.
Python Sample Code¶
For your convenience, here’s a sample Python code. This code demonstrates how to make requests for speech synthesis synchronously.
import requests | |
API_TOKEN = {{your token here}} | |
HEADERS = {'Authorization': f'Bearer {API_TOKEN}'} | |
# get my actor | |
r = requests.get('https://typecast.ai/api/actor', headers=HEADERS) | |
my_actors = r.json()['result'] | |
my_first_actor = my_actors[0] | |
my_first_actor_id = my_first_actor['actor_id'] | |
# request speech synthesis | |
r = requests.post('https://typecast.ai/api/text-to-speech', headers=HEADERS, json={ | |
'text': 'hello typecast', | |
'lang': 'auto', | |
'actor_id': my_first_actor_id, | |
'xapi_hd': True, | |
'model_version': 'latest' | |
}) | |
with open('test.wav', 'wb') as f: | |
f.write(r.content) |
If you have any additional inquiries concerning sample code, feel free to leave comments on the GitHub link provided above.