Store and reuse generated audio without paying twice
Which audio links last and which expire, and a pattern that fetches a link once and serves your own copy, so you never pay to generate the same line twice.
Speakvora returns a link, not the audio bytes. What you do with the link decides your bill and your speed.
What lasts
| Audio | Link | Notes |
|---|---|---|
| Library clip (a checked phrase) | Stable public file | Same URL for the same phrase and voice while that recording is current |
| Live-generated catalog sentence | A file under /live/ | Generated once, then reused; fetch and keep your own copy if you depend on it |
| Your own voice | Signed link, expires in 300 seconds | The reply says expires_in_seconds: 300; download it right away |
The pattern
Ask for audio once per distinct sentence, download it, store it under a hash of the text and voice, and serve your copy afterwards. Each request through the API is billed by characters, including repeats, so your own cache is the cheapest repeat.
JavaScript (server)
import { createHash } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
export async function audioFor(text, voice = "af_heart") {
const id = createHash("sha256").update(voice + "|" + text).digest("hex").slice(0, 32);
const path = "audio-cache/" + id + ".audio";
try { return await readFile(path); } catch {} // your copy: no API call, no charge
const r = await fetch("https://speakvora.com/api/v1/speak", { method: "POST", headers: { "x-api-key": process.env.SPEAKVORA_KEY, "content-type": "application/json" }, body: JSON.stringify({ text, voice, lang: "en" }) });
if (!r.ok) throw new Error((await r.json()).error);
const bytes = Buffer.from(await (await fetch((await r.json()).url)).arrayBuffer());
await mkdir("audio-cache", { recursive: true }); await writeFile(path, bytes);
return bytes;
}Check before you store
Read the licence and terms for what you may keep. Library and generated audio are for your own apps and services; do not resell or redistribute the files. Do not store audio of sensitive personal information longer than you need to. Related: billing explained.
Which format you get
| Audio | Format | Where it comes from |
|---|---|---|
| Library phrases | M4A (AAC) | Stored public file, same URL while that recording is current |
| Live catalog sentences | MP3 | Generated on first request, then stored under /live/ |
| Your own voice | MP3 | Private, signed link that expires in 300 seconds |
Get lines ready before you need them
POST /v1/prepare asks Speakvora to have sentences ready ahead of time. Library phrases are already ready; for anything else, a paid account has the sentences generated in the background (free accounts get live_needs_card for new text). Preparing is not billed; speaking a prepared sentence later is billed as usual, and it comes back quickly. Send up to 200 texts per call.
cURL
curl -X POST https://speakvora.com/api/v1/prepare -H "x-api-key: $SPEAKVORA_KEY" -H "content-type: application/json" \
-d '{"voice":"af_heart","lang":"en","texts":["Your order has shipped.","Your table is ready."]}'
# 200 {"ready":0,"queued":2,"rejected":[],"note":"Queued sentences are ready in a few seconds; ..."}Design the cache key carefully
- Include everything that changes the audio: the exact text, the voice, the language and, for your own voice, the voice version (replacing the sample creates a new version, so old files should stop being used).
- Normalise the text first. Trim and collapse extra spaces so "Hello. " and "Hello." share one file.
- Keep the downloaded bytes, not the link. Links to your own voice expire in 300 seconds.
- Set an expiry of your own if the text contains anything personal, and delete those files when you no longer need them.
When a cache is worth it
At $3 per million characters, a 40-character line costs about $0.00012 per request, so one million plays of that line through the API would cost about $120. A cache turns that into one request plus storage. For lines you play a few times a day the saving is small and the simplest design is to call the API; for a phone menu or kiosk that repeats the same few hundred lines all day, store the files. If the same lines are the whole product, an offline voice pack is a one-time purchase with the files included.
Common questions
- Do repeats count against my free allowance? Yes. A repeat through the API is billed again; a repeat from your own copy costs nothing.
- Does Speakvora keep my private recordings? Your own-voice sentences are stored privately only after they have been requested twice and are deleted after 75 days without use; each reuse restarts the 75 days.
- Can I serve the files to my customers? Inside your own app, yes. Do not resell or redistribute the audio files themselves; the licence has the details.