Transcribe a local file
Upload the file withPOST /v1/files (up to 1 GB), then create the transcript with its file_id. Audio that is already hosted needs no upload: pass audio_url instead. For larger files, use an upload URL.
# pip install requests
import os, sys, time, requests
API = "https://api.aircaps.com/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['AIRCAPS_API_KEY']}"}
def call(method, path, timeout=60, **kw):
r = requests.request(method, API + path, headers=HEADERS, timeout=timeout, **kw)
if r.status_code >= 400:
raise SystemExit(r.json()["error"]["message"])
return r.json()
with open(sys.argv[1], "rb") as f:
upload = call("POST", "/files", data=f, timeout=600)
job = call("POST", "/transcripts", json={"model": "a5s-async-v1", "file_id": upload["id"], "language_code": "en"})
while job["status"] in ("queued", "processing"):
time.sleep(3)
job = call("GET", f"/transcripts/{job['id']}")
if job["status"] == "error":
raise SystemExit(job["error"]["message"])
for u in job["utterances"]:
print(f"[{u['start']:8.1f}s] {u['speaker']}: {u['text']}")
// node transcribe.mjs meeting.mp3 (Node 18+)
import { readFile } from "node:fs/promises";
const API = "https://api.aircaps.com/v1";
const headers = { Authorization: `Bearer ${process.env.AIRCAPS_API_KEY}` };
async function call(method, path, body) {
const r = await fetch(API + path, {
method,
headers: body ? { ...headers, "Content-Type": "application/json" } : headers,
body: body ? JSON.stringify(body) : undefined,
});
const data = await r.json();
if (!r.ok) throw new Error(data.error.message);
return data;
}
const res = await fetch(API + "/files", { method: "POST", headers, body: await readFile(process.argv[2]) });
const upload = await res.json();
if (!res.ok) throw new Error(upload.error.message);
let job = await call("POST", "/transcripts", { model: "a5s-async-v1", file_id: upload.id, language_code: "en" });
while (job.status === "queued" || job.status === "processing") {
await new Promise((r) => setTimeout(r, 3000));
job = await call("GET", `/transcripts/${job.id}`);
}
if (job.status === "error") throw new Error(job.error.message);
for (const u of job.utterances) console.log(`[${u.start.toFixed(1)}s] ${u.speaker}: ${u.text}`);
# 1. upload the file (-L follows the 303 redirect a slow upload gets)
curl -L https://api.aircaps.com/v1/files -H "Authorization: Bearer $AIRCAPS_API_KEY" \
-H "Content-Type: application/octet-stream" --data-binary @meeting.mp3
# 2. transcribe with the returned id
curl https://api.aircaps.com/v1/transcripts -H "Authorization: Bearer $AIRCAPS_API_KEY" \
-H "Content-Type: application/json" -d '{"model": "a5s-async-v1", "file_id": "file_...", "language_code": "en"}'
Verify a webhook
# pip install flask standardwebhooks
import os
from flask import Flask, request
from standardwebhooks.webhooks import Webhook, WebhookVerificationError
app = Flask(__name__)
wh = Webhook(os.environ["AIRCAPS_WEBHOOK_SECRET"])
@app.post("/hooks/aircaps")
def hook():
try:
event = wh.verify(request.get_data(), dict(request.headers))
except WebhookVerificationError:
return "", 400
print(event["event"], event["id"]) # fetch the transcript with GET /v1/transcripts/{id}
return "", 204

