Store and reuse generated audio without paying twice
Which links last, which expire, and a pattern that fetches an audio link once and serves your own copy.
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 |
| Styled voice (preview) | Signed link, 5 minutes | Not enabled in production |
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.