# Audio Batch on ZeroGPU > Batch processing of audio on ZeroGPU: transcribe a folder of recordings in one batch with `whisper-tiny`, or speak a file of lines in one batch with `chatterbox-nano` (one audio file per line, optionally in a cloned voice), with the audio seconds and billed seconds for every line. Audio is billed per second. You need a ZeroGPU API key. The script below does the whole flow with Python's standard library; the exact API calls follow, so you can also write the integration into the user's own code. ## Steps 1. Ask the user what to run: **transcribe** (which audio files or folder) or **speak** (a text file with one line per audio file, and whether to clone a voice). 2. Ask the user for their ZeroGPU API key and pass it as the environment variable `ZEROGPU_API_KEY`. Never print the key, log it, write it to a file, or put it in code. 3. Download the script: `curl -O https://demos.zerogpu.ai/audio-batch/zerogpu_audio_batch.py` (Python 3.9+, no other packages). 4. Transcribe: `python3 zerogpu_audio_batch.py transcribe PATH... --language en --out transcripts.jsonl`. PATH is files or folders (searched recursively). Leave out `--language` to auto-detect it; add `--verbose` for timed segments. Start with a few files. 5. Speak: `python3 zerogpu_audio_batch.py speak lines.txt --out-dir speech` (add `--voice sample.wav` to clone a voice). Only clone the voice of someone who agreed to it, such as the user themselves. The sample must be 6–30 seconds of speech; use wav, mp3 or webm (an m4a voice sample failed twice in our tests). 6. Set expectations on time. Both models scale to zero, so the script warms each one up first (a cold start answered 503 for about 40 seconds, then took up to 2 minutes). In our tests on October 15, 2026, transcription batches of 3–22 clips finished in 11–162 seconds (8–10 clips: 22–26 seconds). Speech batches varied a lot with load, from about 10 seconds a line to about 80: 2 lines took 22 seconds, 5 lines 45 seconds and, an hour later, 6.5 minutes, and 7–8 lines 8–9 minutes. The batch keeps running on ZeroGPU even if the script stops; it prints the batch id. 7. Report back: the per-second table the script prints (audio seconds and billed seconds per line, with totals), the transcripts (`transcripts.jsonl`) or the audio files (`speech/`), and any failed lines with their error code. ## One call (no batch) For one clip or one line, call the model directly. The answer comes back in the response, and the `x-audio-duration-seconds` header has the audio's length in seconds (billed rounded up, 1-second minimum). ```bash curl -i https://api.zerogpu.ai/v1/audio/transcriptions -H "x-api-key: $ZEROGPU_API_KEY" \ -F model=whisper-tiny -F response_format=json -F language=en -F file=@nora.mp3 # x-audio-duration-seconds: 10.1 # {"text":"Hi Jordan, it's Nora at the front desk. A courier just dropped off a box of 40 rubber ducks addressed to you. Nobody will admit to ordering them. They're in the mail room. Call me back."} curl -D - https://api.zerogpu.ai/v1/audio/speech -H "x-api-key: $ZEROGPU_API_KEY" -H 'content-type: application/json' \ -d '{"model":"chatterbox-nano","input":"Hi Nora, thanks for the heads up. Thursday at ten works for me.","response_format":"mp3"}' -o reply.mp3 # content-type: audio/mpeg # x-audio-duration-seconds: 3.6 ``` Add `"voice_sample_file_id"` (a 6–30 second clip uploaded with `purpose=batch_audio`) to speak in that voice. On October 19, 2026, a transcription took about 2 seconds and a spoken line 3–5 seconds (in a cloned voice too) once the model was warm; a cold model answers `503` first. For many files, use a batch: it runs on its own, and you collect the results when it's done. ## How a batch works 1. Upload each audio clip with `POST /v1/files` and `purpose=batch_audio`. You get back a `file-…` id. 2. Write a JSONL job file with one line per job. Transcription lines point at a clip by `file_id`; speech lines carry the text in `input`. Audio never goes inside a line. 3. Upload the JSONL with `POST /v1/files` and `purpose=batch`. 4. Create the batch with `POST /v1/batches`, giving the JSONL file id and the endpoint. Each line's `url` must match it; one endpoint per batch. 5. Poll `GET /v1/batches/{id}` until `status` is `completed`, `failed`, `expired` or `cancelled`. 6. Download the results with `GET /v1/files/{id}/content`: the lines that worked are in the file named by `output_file_id`, the lines that failed in the one named by `error_file_id`. 7. Speech only: each result line holds an `audio_file_id`. Download it the same way. ## API Base URL `https://api.zerogpu.ai/v1`. Auth: header `x-api-key: $ZEROGPU_API_KEY` on every call. Don't use `Authorization: Bearer`: the Files and Batches APIs answer `401 Missing authentication headers`. With the OpenAI SDK, set `default_headers={"x-api-key": key}`. | Method and path | What it does | |---|---| | `POST /v1/files` (multipart form: `purpose`, `file`) | Uploads an audio clip (`purpose=batch_audio`) or a JSONL job file (`purpose=batch`) | | `GET /v1/files/{file_id}/content` | Downloads a file: output JSONL, error JSONL or generated audio | | `POST /v1/batches` (JSON) | Creates a batch | | `GET /v1/batches/{batch_id}` | A batch's status and line counts | | `POST /v1/batches/{batch_id}/cancel` | Cancels a running batch | | Endpoint | Model | Notes | |---|---|---| | `/v1/audio/transcriptions` | `whisper-tiny` | Clips up to 10 minutes and 25 MB: flac, m4a, mp3, mp4, mpeg, mpga, oga, ogg, wav, webm | | `/v1/audio/speech` | `chatterbox-nano` | English text up to 2,000 characters per line; at most 5,000 speech lines per batch | Don't use `/v1/audio/translations`: it always outputs English, and German and French audio came back as wrong English. `/v1/models` doesn't list the audio models; use the two ids above. `completion_window` must be `"24h"`. ### Upload a clip ```bash curl https://api.zerogpu.ai/v1/files -H "x-api-key: $ZEROGPU_API_KEY" -F purpose=batch_audio -F file=@call-001.mp3 ``` ```json {"id":"file-0611ba64e0584230a37fa2","object":"file","bytes":90668,"filename":"call-001.mp3","purpose":"batch_audio","status":"processed","expires_at":1794692214} ``` ### Transcription lines ```json {"custom_id":"call-001","method":"POST","url":"/v1/audio/transcriptions","body":{"model":"whisper-tiny","file_id":"file-0611ba64e0584230a37fa2","response_format":"json","language":"en"}} ``` `body` fields: `file_id` and `model` (required); `response_format` (`json` by default, or `verbose_json`, `text`, `srt`, `vtt`); `language` (ISO-639-1, auto-detected if left out); `prompt` (a vocabulary hint, up to 4,096 characters); `temperature` (0 to 1); `timestamp_granularities` (`["word"]`, `["segment"]` or both, with `verbose_json`). Use `json` or `verbose_json`: only they report the duration. Sending `file` instead of `file_id` is rejected. ### Speech lines ```json {"custom_id":"reply-001","method":"POST","url":"/v1/audio/speech","body":{"model":"chatterbox-nano","input":"Your order has shipped and will arrive on Thursday.","response_format":"mp3"}} {"custom_id":"reply-002","method":"POST","url":"/v1/audio/speech","body":{"model":"chatterbox-nano","input":"This line is spoken in the voice from the sample.","response_format":"mp3","voice_sample_file_id":"file-e1b8c57320d345fd805906"}} ``` `body` fields: `input` and `model` (required); `response_format` (`mp3` by default, or `wav`, `opus`, `aac`, `flac`, `pcm`; `pcm` is raw 24 kHz 16-bit mono with no header); `voice_sample_file_id` (a clip uploaded with `purpose=batch_audio`, 6–30 seconds and up to 10 MB); `seed` (an integer: the same seed and input give the same audio). `voice` names such as `alloy` are accepted but all give the same built-in voice. A `speed` other than 1.0, `instructions`, `exaggeration`, `cfg_weight` and `min_p` fail the line with a 400. ### Create the batch, and poll it ```bash curl https://api.zerogpu.ai/v1/batches -H "x-api-key: $ZEROGPU_API_KEY" -H 'content-type: application/json' \ -d '{"input_file_id":"file-6d0291cd437f43e78641cc","endpoint":"/v1/audio/transcriptions","completion_window":"24h"}' curl https://api.zerogpu.ai/v1/batches/batch_2fqYtLF1FhucacXxwUqaHGmD -H "x-api-key: $ZEROGPU_API_KEY" ``` ```json {"id":"batch_2fqYtLF1FhucacXxwUqaHGmD","object":"batch","endpoint":"/v1/audio/transcriptions","status":"in_progress","output_file_id":null,"error_file_id":null,"request_counts":{"total":10,"completed":3,"failed":0}} {"id":"batch_2fqYtLF1FhucacXxwUqaHGmD","object":"batch","endpoint":"/v1/audio/transcriptions","status":"completed","output_file_id":"file-…","error_file_id":null,"request_counts":{"total":10,"completed":10,"failed":0}} ``` An invalid line (a missing `file_id`, an unknown clip) makes the create call answer 400 and name the line (numbered from 0). ### Results A transcription output line is the usual transcription, plus `audio_duration_seconds` (the clip's length): ```json {"id":"batch_req_…","custom_id":"call-002","response":{"status_code":200,"request_id":"…","body":{"text":"Good morning. This is Dr. Pell's dental office, calling to confirm your cleaning on Thursday at 10.15.","audio_duration_seconds":10.37}}} ``` A speech output line points at the generated audio, with its length: ```json {"id":"batch_req_…","custom_id":"reply-001","response":{"status_code":200,"request_id":"…","body":{"object":"audio.speech","audio_file_id":"file-qz7dTwxMek9le5Zk8hGjEeF2","content_type":"audio/mpeg","bytes":104877,"audio_duration_seconds":6.48}}} ``` A failed line goes only to the error file; the batch still ends `completed`, with the line counted in `request_counts.failed`: ```json {"id":"batch_req_…","custom_id":"reply-007","error":{"code":"voice_sample_too_short","message":"[legacy:http_400] The voice sample is 1.126s long, but Chatterbox needs more than 6s of speech to clone a voice reliably. Upload a longer clip.","param":"voice_sample"},"response":null} ``` ## Known quirks 1. **Downloaded audio is labelled `content-type: application/jsonl`.** The bytes are real audio: use `content_type` from the result line. 2. **Cold starts.** Both models scale to zero. Send one normal call per model first and repeat until it answers 200 (a cold one answers `503 {"error":{"code":"model_unavailable","message":"Model is not loaded"}}`). Inside a batch, a line that meets a cold model retries about 4 times, 5 seconds apart, then fails with `internal_error` "retries_exhausted". A warm-up doesn't always carry over: on October 15, 2026, a speech batch created right after a direct call answered 200 still failed every line with `503 model_unavailable`. If every line fails that way, wait a minute and send the failed lines again (failed lines aren't billed). 3. **Failed lines are only in the error file.** If every line fails, `output_file_id` is `null`. Match lines by `custom_id`, not by order. 4. **No idempotency.** Every `POST /v1/batches` makes a new batch. 5. **Voice samples:** wav, mp3 and webm cloned well in our tests; an m4a sample failed twice with `internal_error`. Record or convert to wav. 6. **Retention:** uploaded inputs expire after 30 days. Batch outputs and generated audio don't expire. Don't send `DELETE`. ## Billing Audio is billed per second: the duration (`audio_duration_seconds`: the clip's length for a transcription, the generated audio's length for speech) rounded up to a whole second, with a 1-second minimum. Failed lines aren't billed. A single (non-batch) audio call returns the same number in the `x-audio-duration-seconds` response header. Ask your ZeroGPU contact for the per-second rate; volume pricing is available.