Synchronous, How to Use Typecast APIs

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.

If you have any additional inquiries concerning sample code, feel free to leave comments on the GitHub link provided above.