Combine reusable phrases with live speech
Search the library first, speak a library line instantly, and fall back to live generation for everything else.
The cheapest, fastest sentence is one that already exists as audio. This pattern checks the library first.
Python (requests)
import os, requests
H = {"x-api-key": os.environ["SPEAKVORA_KEY"]}
API = "https://speakvora.com/api/v1"
def speak(text, voice="af_heart"):
r = requests.post(f"{API}/speak", headers=H, json={"text": text, "voice": voice, "lang": "en"}, timeout=40)
if r.status_code == 429:
raise RuntimeError("slow down: retry in %s s" % r.json().get("retry_after_seconds"))
r.raise_for_status()
return r.json()["url"]
def search(q):
r = requests.get(f"{API}/search", headers=H, params={"q": q, "lang": "en", "limit": 5}, timeout=20)
r.raise_for_status()
return [x["text"] for x in r.json()["results"]]
print(search("waiting room")[:3])
print(speak("The wait is about fifteen minutes.")) # a library line: instant
print(speak("Dr. Rivera is running ten minutes late.")) # new text: generated live, takes secondsPrepare lines ahead of time
POST /v1/prepare with {"voice":"af_heart","lang":"en","texts":[...]} (up to 200 per call) generates new sentences in the background so the later /v1/speak is quick. Preparing is not billed; speaking is billed per character as usual.
Cost thinking
At the $0.70 per million catalog rate, a 40-character line costs about $0.000028 each time it is requested through the API, library or live. If you replay the same line thousands of times, downloading a pack or keeping your own copy avoids per-play charges.