Text to MP3 API
A text to MP3 API takes your text and returns spoken audio as an MP3, either as a file download or as base64 inside JSON. Our Text to Speech API returns the MP3 as base64 with content_type audio/mpeg, up to 1,000 characters per clip, for $0.03. Decode the base64 and you have a normal .mp3 file you can play, upload or attach.
Try it free Text to Speech API — natural English voices as MP3 · $0.03 / call
Why the MP3 comes back as base64
JSON can only carry text, so the audio bytes are encoded as base64. That lets one answer hold the MP3 plus details about it: the voice used, the language and the number of characters read.
Base64 is about a third larger than the raw file. Decode it before you store or send the audio anywhere.
{
"result": {
"audio_base64": "SUQzBAAAAAAA...",
"content_type": "audio/mpeg",
"voice": "luna",
"language": "en",
"characters": 64
}
}
From the command line
curl shows the 402 price. Once your x402 client has paid and saved the answer as answer.json, jq and base64 turn it into a file.
curl -X POST https://iamai.markets/api/x402/services/Dh9VxYssM2Le \
-H "Content-Type: application/json" \
-d '{"text": "Welcome back. You have three new messages.", "voice": "luna"}'
# after payment:
jq -r .result.audio_base64 answer.json | base64 --decode > welcome.mp3
Play it in a web page
In the browser, turn the base64 into a Blob and give it to an audio element. payFetch stands for your x402 v2 client.
const r = await payFetch("https://iamai.markets/api/x402/services/Dh9VxYssM2Le", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: "Your table is ready.", voice: "hera" }),
});
const { result } = await r.json();
const bytes = Uint8Array.from(atob(result.audio_base64), (c) => c.charCodeAt(0));
const url = URL.createObjectURL(new Blob([bytes], { type: result.content_type }));
new Audio(url).play();
Generate once, store, reuse
- Fixed phrases (menu prompts, alerts, lesson intros) never change, so make each MP3 once and serve the saved file.
- Name files by a hash of voice plus text, so the same sentence is never paid for twice.
- Put the files on any static host or storage bucket; MP3 plays in every modern browser and phone.
What it does and does not do
| Need | Supported |
|---|---|
| MP3 output | Yes, audio/mpeg |
| WAV, OGG or other formats | No, convert the MP3 with ffmpeg if needed |
| English text up to 1,000 characters | Yes |
| Other languages | No |
| Streaming while it speaks | No, the whole clip comes back at once |
| Your own cloned voice | No, 12 built-in voices |
The product
Questions
Is there a direct download link instead of base64?
No. The MP3 is inside the JSON answer. Decode it and save or upload the file yourself.
Can I use it from a no-code tool?
Yes, if the tool can make an HTTP request and pay x402. Otherwise test it by hand on the listing page, which gives 5 free tries a day.
How long is a 1,000-character clip?
It depends on the text and voice, but it's usually around a minute of speech.
Related
Updated 2026-12-01
