Text-To-Speech API Reference

This page covers all steps to integrate text-to-speech (TTS) API into your system.

Good to know: A quick start guide can be good to help folks get up and running with your API in a few steps. Some people prefer diving in with the basics rather than meticulously reading every page of documentation!

Get your API keys

Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.

You can generate an API key from your user dashboard in Miragic website anytime.

Authentication

All requests must include the X-API-Key header containing your assigned API key.

How To Create Image Generation Task

POST /api/v1/text-to-speech/generate

This API starts the TTS process by creating a task that generates an audio file containing speech.

Processing Information

  • Tasks are processed asynchronously in the background

  • Progress can be monitored using the Get Task Status API

  • The final result will be a high-quality audio

Request

Parameter
Type
Required
Description

text

String

Yes

Input text to generate audio.

voice

String

Yes

This value can be set to alloy, amuch, ash, ballad, dan, echo, onyx, verse, coral, elan, fable, nova, sage, shimmer, etc.

Request Example

Response

Response Field

Field
Type
Description

jobId

String

A unique identifier used to track task status and retrieve results.

status

String

The initial status will be PENDING. Use the Get Task Status API to track progress.

success

Logic

true or false to indicate whether task is successful or not.

message

String

To indicate the status of task

How To Get Task Status

GET /api/v1/text-to-speech/jobs/:jobId

This API lets you check the status of a TTS task and retrieve the final result. Because the TTS process runs asynchronously, you’ll need to poll this endpoint until the task is finished.

Task Status:

Status
Description
Progress
Next Action

PENDING

Task is currently being processed.

0~99%

Continue polling

COMPLETED

Task has finished successfully.

100%

Download result using download_signed_url

FAILED

Task processing failed.

N/A

Check error details and retry if needed

Progress Tracking:

  • The progress field indicates the percentage of task completion (0-100)

  • Progress updates are available in real-time during the PENDING state

  • Progress increases as the AI processes different stages of the try-on task

Polling Guidelines:

  • Start polling immediately after creating the task

  • Implement exponential backoff to avoid rate limiting

  • The download_signed_url is temporary and should be used promptly

  • Consider implementing a timeout after extended polling

Request:

URL Parameters

Parameter
Type
Required
Description

JobId

String

Yes

This value indicates task ID assigned by requesting TTS process API

Request Example

Response Example

Completed Status (200):

Response Fields

Field
Type
Description

id

String

Unique identifier of the task

status

String

Current status of the task (PENDING/COMPLETED/FAILED)

audio_link

String

URL to result audio file.

createdAt

Number

Unix timestamp when processing is created

Full Code Example

The following code lines are quick example to use our API in multiple languages.

Last updated