Extract 16 kHz mono audio from a video for transcription

A Python script that detaches speech-ready 16 kHz mono wav from a Sume-hosted video, then polls the job. Costs $0.01 per detach before the STT minute.

3 min readSume
All posts

To prepare a video for transcription, detach its audio as 16 kHz mono wav: format: "wav", sample_rate: 16000, channels: "mono". That is the shape the Audio detach page names as the STT shape, and it costs $0.01 per job. Speech to text then costs $0.01 per audio minute.

The script

The source must be a media.sume.com video in your workspace. The script submits with mode: "sync", which waits up to 30 seconds and returns 200, or 202 with a job to poll.

import os, time, requests

BASE = "https://api.sume.com"
H = {"Authorization": "Bearer " + os.environ["SUME_API_KEY"],
     "Idempotency-Key": "detach-16k-001"}

r = requests.post(BASE + "/v1/audio-detach", headers=H, json={
    "video_url": "https://media.sume.com/artifacts/artf_demo/talk.mp4",
    "format": "wav", "sample_rate": 16000, "channels": "mono",
    "mode": "sync",
})
r.raise_for_status()
job = r.json()
jid = job.get("data", job)["request_id"]
while True:
    s = requests.get(BASE + f"/v1/jobs/{jid}/status", headers=H).json()
    s = s.get("data", s)
    if s["terminal"]:
        break
    time.sleep(s.get("next_poll_after_seconds") or 2)
if not s["result_ready"]:
    raise SystemExit("detach did not complete: " + str(s))
res = requests.get(BASE + f"/v1/jobs/{jid}/result", headers=H).json()
print(res.get("data", res))

What comes back

A finished result has kind: audio_detach with an audio_url (a new artf_ artifact), duration_seconds, format, channels, sample_rate, and source_duration_seconds. Pass audio_url to the next step.

Budget for an hour of audio

Output is capped at 900 seconds per job and STT at 10 minutes per request, so the cheapest plan for an hour is to detach in 15-minute ranges and transcribe in 10-minute slices.

Sume list price
StepJobs for 60 minCost
Detach, 900 s ranges4$0.04
STT, 60 audio minutes6 (10 min each)$0.60
Total$0.64

Sources

Related posts

More in Developers

All Developers posts

Written by Sume