Skip to main content
Build a mobile app that lets users enter a script, select a voice, and listen to or save the generated audio. This example requires an existing integration with access to /api/text_to_speech on its assigned legacy API origin. A public v2 Text to Speech endpoint is planned. Ask the Backapp team about access if you are setting up a new app.

1. Set up the session

Use the assigned API origin without a trailing slash or /api. Obtain a legacy access token through Authentication and use the same user’s session to submit and read the task. Run the Bash, curl, and jq snippets in the same shell.

2. Choose the script and voice

Give the user a text field for the script and a voice picker with these IDs: alloy, echo, fable, onyx, nova, and shimmer. The legacy endpoint defaults to alloy when the voice is omitted. Trim the script and require nonblank text before enabling Generate.

3. Start generation

Send the text and selected voice as JSON. HTTP 202 returns a task_id. Save it so the user can return to the screen while the audio is being generated.
Disable duplicate submissions while the request is in flight. If the connection drops before you receive a task ID, another POST can create a second task.

4. Wait for the MP3 and play it

Read the task status with the saved ID. Repeat with a delay while status is pending or processing. Keep one status request in flight and stop on completed or failed.
On completion, pass the nonempty url to your app’s audio player as the MP3 source. Enable Play and Download once the URL is available. Older completed tasks can have an empty URL. On failure, read error_message and show the user a short message. See Text to Speech response examples.

5. Download the audio

Use the exact URL from the task response. Fetch it separately from the API calls without the legacy bearer token. Treat it as a shareable link and keep it out of logs.
Open voiceover.mp3 in a local player to preview it or offer it through your app’s export action. Download it while the result is available. If a saved URL later returns HTTP 404, show that the audio is unavailable and offer to generate a new copy.