Complete speech generation and transcription
Handle binary speech, asynchronous speech tasks, and multipart transcription correctly.Speech synthesis workflow
Submit exactly one of input or prompt, plus any model-specific fields. Save audio/* responses directly; for application/json, read the task ID and poll it.
curl
Python
Node.js
curl
#!/usr/bin/env bash
set -euo pipefail
headers=$(mktemp)
body=$(mktemp)
trap 'rm -f "$headers" "$body"' EXIT
curl -fsS -D "$headers" -o "$body" https://api.noxgate.net/v1/audio/speech \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"model":"YOUR_MODEL_ID","input":"Hello from NoxGate","voice":"YOUR_VOICE_ID"}'
content_type=$(awk -F': *' 'tolower($1) == "content-type" {print tolower($2)}' "$headers" | tail -1 | tr -d '\r')
if [[ "$content_type" != application/json* ]]; then
mv "$body" speech.mp3
echo "Saved speech.mp3"
exit 0
fi
response=$(cat "$body")
task_id=$(printf '%s' "$response" | jq -r '.id // empty')
status=$(printf '%s' "$response" | jq -r '.status // empty')
deadline=$((SECONDS + 300))
delay=2
while [[ -n "$task_id" && "$status" != "succeeded" ]]; do
case "$status" in failed|canceled|cancelled) printf '%s\n' "$response" >&2; exit 1 ;; esac
[[ $SECONDS -ge $deadline ]] && { echo "Speech generation timed out" >&2; exit 1; }
sleep "$delay"
response=$(curl -fsS "https://api.noxgate.net/v1/audio/speech/$task_id" \
-H "Authorization: Bearer sk-your-api-key")
status=$(printf '%s' "$response" | jq -r '.status // empty')
(( delay < 10 )) && delay=$((delay + 2))
done
result_url=$(printf '%s' "$response" | jq -r '.url // empty')
[[ -n "$result_url" ]] || { printf '%s\n' "$response" >&2; exit 1; }
if [[ "$result_url" == /* ]]; then result_url="https://api.noxgate.net$result_url"; fi
curl -fL "$result_url" -o speech.mp3
echo "Saved speech.mp3"Audio transcription workflow
Transcription requires a real multipart/form-data upload; a local path inside JSON is not a file upload.
curl
Python
Node.js
curl
curl https://api.noxgate.net/v1/audio/transcriptions \
-H "Authorization: Bearer sk-your-api-key" \
-F "model=YOUR_MODEL_ID" \
-F "file=@./audio.mp3"Results and errors
- Voice, format, file type, and optional parameters depend on the model.
- Async clients must handle failed, canceled, and cancelled, with a total timeout.
- Download an async result URL promptly; do not assume it remains valid forever.