Skip to content
VelosyllOpen studio

Transcribe a file with curl

Submit an English recording over HTTP, wait for the job to finish, print the reviewed text and save SubRip captions.

Before you start

  • Start the local studio, sign in and select a project with test credits.
  • Install Bash, curl with --fail-with-body, and jq. Work in a new directory.

1. Set your project credential

Open the developer console in the local studio, create a project API key and copy it when shown. Start Bash, then run the following commands. Paste the key at the prompt. Run the later commands in that shell.

Set the local address and project key · Bash
export VELOSYLL_URL=http://127.0.0.1:8464
read -rsp 'Project API key: ' VELOSYLL_API_KEY
printf '\n'
export VELOSYLL_API_KEY

2. Get the sample recording

Use the English recording included in the local studio, or substitute a short recording of your own. The language hint in this example is English.

Download the sample · Bash
curl -fsS "$VELOSYLL_URL/assets/speech-sample.wav" -o speech-sample.wav

3. Submit, poll and export

Save the script in your working directory. The upload returns a job ID. Polling and exporting with that ID let you resume after an interruption without submitting the audio again.

Transcription and captions · BashDownload transcribe.sh
#!/usr/bin/env bash
set -euo pipefail
: "${VELOSYLL_API_KEY:?Set a project API key first}"
base=${VELOSYLL_URL:-http://127.0.0.1:8464}
base=${base%/}
api=(curl --fail-with-body --silent --show-error --max-time 60 -H "Authorization: Bearer $VELOSYLL_API_KEY")

if [[ ${1:-} == --job ]]; then
  job=${2:?Pass the saved job ID after --job}
else
  input=${1:?Pass the path to an English recording, or --job JOB_ID}
  response=$("${api[@]}" -F "file=@$input" -F language=en "$base/v1/transcriptions")
  job=$(jq -er '.id' <<< "$response")
fi
[[ "$job" =~ ^[a-zA-Z0-9_-]+$ ]] || { echo 'Invalid job ID' >&2; exit 1; }
printf 'Job ID: %s\n' "$job"

deadline=$((SECONDS + 600))
while (( SECONDS < deadline )); do
  response=$("${api[@]}" "$base/v1/transcriptions/$job")
  case $(jq -er '.status' <<< "$response") in
    completed)
      "${api[@]}" "$base/v1/transcriptions/$job/transcript" | jq -r '.text'
      "${api[@]}" "$base/v1/transcriptions/$job/export?format=srt" -o "$job.srt"
      printf 'Saved %s.srt\n' "$job"
      exit 0 ;;
    failed) jq -r '.error // "Transcription failed"' <<< "$response" >&2; exit 1 ;;
    queued|processing) sleep 1 ;;
    *) echo 'Unrecognized job status' >&2; exit 1 ;;
  esac
done
printf 'Timed out. Resume with: bash transcribe.sh --job %s\n' "$job" >&2
exit 1
Run the sample · Bash
bash transcribe.sh speech-sample.wav

4. Read the caption file

Open the .srt file named after the job ID. Each cue has an index, a start and end time, and caption text. A recording with no recognized speech can have an empty transcript.

Expected result

The terminal prints the job ID and recognized text. A non-silent recording with recognized segments produces a matching .srt file with timed cues.

Troubleshooting

The wait reaches ten minutes.
Run bash transcribe.sh --job JOB_ID using the printed ID to continue waiting.
The request returns 401 or the job fails.
For 401, set a valid project API key in the same shell. For a failed job, read its error and check the source media, test balance and engine status before submitting again.

Explore further