4Hz / fourhz-spectrum
Speech-to-Text API · Synchronous · SYNC
Turn speech into accurate text for analytics and real-time voice AI.
Realtime · RTT · Pre-recorded · PRE · Synchronous · SYNC
Sync accepts up to 30 seconds; use the Pre-recorded API for longer audio.
Service endpoints
Service URL: https://api.fourhz.ai
| Method / Protocol | Path | Content-Type / Frames | Auth |
|---|---|---|---|
| POST | /v1/asr/sync | multipart/form-data | Authorization: <API Key> |
Authentication
Use the raw API key without Bearer. Put it in the HTTP Authorization header; keep long-lived keys on the server.
Authorization: $FOURHZ_API_KEY
Request parameters
| Field | Type | Description |
|---|---|---|
audio | file | Required audio file, 80 ms–30 s, up to 40 MB. |
config | JSON object | Optional multipart config JSON containing the fields below; model defaults to fourhz-spectrum. |
model | string | fourhz-spectrum |
sample_rate / channels | integer | Required for raw PCM only; channels must be 1. |
language_codes | string[] | Optional ["zh"] or ["en"]; omit for auto-detection. |
keyterms_prompt | string[] | Up to 100 direct keyterms, 64 characters each. word_boost is an alias; send only one. |
cleanup_level | string | off (default), light or standard. Standard removes clear filler words and adjacent repetitions. |
translate_mode | boolean | Defaults to false. When combined with cleanup, translates the cleaned source. |
target_language | string | Required when translate_mode=true; e.g. en or zh. |
text_emotion | boolean | Defaults to false, independently of cleanup and translation. Returns emotion results and status. |
hotword_pool_id | string | Reference a complete enabled pool of up to 1,000 words; the 100-term direct realtime/sync limit does not apply. Create and manage pools → |
reject_background_speech | boolean | Background-speech rejection. Optional; defaults to true (enabled). Set to false to disable. multipart/form-data field; also accepted inside the config JSON. |
Response fields
| Field | Type | Meaning and availability |
|---|---|---|
text | string | Full transcript; target mode contains the target speaker’s output. |
audio_duration_ms | number | SYNC processed audio duration in milliseconds. |
session_id | string | SYNC task/correlation ID. |
request_time_ms | number | SYNC server processing time in milliseconds. |
error_code | string | Stable error code on failure. |
message | string | Human-readable error message. |
Independent enhancement results
Cleanup, translation and emotion may be enabled independently or together. Realtime fields arrive in FourHzPostprocessing events; Turn retains the raw transcript. Sync/pre-recorded text prefers translation, then cleanup or keyterm correction, while preserving the independent result fields.
| Field | Type | Description |
|---|---|---|
cleaned_text | string | Cleaned or keyterm-corrected source-language text. |
translated_text | string | Target-language translation, using the cleaned source when combined. |
cleanup_status / translation_status | string | completed indicates success; degraded_raw_only/degraded_partial indicates fallback or incomplete processing. |
emotion_status | string | completed or degraded. Failure is not silently reported as success. |
emotions | object[] | Sync/pre-recorded emotion results with mode, label and text; realtime uses emotion.bucket events. |
Request examples
Code samples
curl -X POST 'https://api.fourhz.ai/v1/asr/sync' \
-H "Authorization: $FOURHZ_API_KEY" \
-F 'audio=@sample.wav' \
-F 'model=fourhz-spectrum'# pip install requests
import os
import requests
from contextlib import ExitStack
url = "https://api.fourhz.ai/v1/asr/sync"
headers = {"Authorization": os.environ["FOURHZ_API_KEY"]}
with ExitStack() as stack:
files = [
("audio", ("sample.wav", stack.enter_context(open("sample.wav", "rb"))))
]
fields = {"model":"fourhz-spectrum"}
response = requests.request("POST", url, headers=headers, timeout=300, files=files, data=fields)
response.raise_for_status()
print(response.json() if response.content else {"status": response.status_code})// Node.js 22+
import {readFile} from 'node:fs/promises';
const url = "https://api.fourhz.ai/v1/asr/sync";
const headers = {"Authorization": process.env.FOURHZ_API_KEY};
const body = new FormData();
body.append("audio", new Blob([await readFile("sample.wav")]), "sample.wav");
body.append("model", "fourhz-spectrum");
const response = await fetch(url, {method: "POST", headers, body, signal: AbortSignal.timeout(300000)});
if (!response.ok) throw new Error(await response.text());
console.log(response.status === 204 ? {status: 204} : await response.json());Sending and receiving
Response and results
{
"text": "Hello world.",
"audio_duration_ms": 4200,
"session_id": "task-example",
"request_time_ms": 1834.6
}Error codes
Every HTTP error body contains error_code (machine-readable) and message (human-readable). Legacy fields such as detail, code/msg or an upstream error object are kept and status codes are unchanged. Clients should read error_code and message first.
HTTP values are status codes. Except for detail responses such as 401/402, the body uses {"error_code":"…","message":"…"}. These codes apply to the synchronous API.
| HTTP | Response code | Meaning |
|---|---|---|
| HTTP 400 | bad_audio / audio_too_short / invalid_candidates | Audio cannot be decoded, is too short, or the candidate voiceprint set is invalid. |
| HTTP 401 | detail | Missing or invalid API key. |
| HTTP 402 | detail | Insufficient balance. |
| HTTP 413 | audio_too_large | Decoded audio exceeds the duration limit. |
| HTTP 415 | unsupported_media_type | Unsupported container format, or the file content is not audio (for example a text file renamed to .mp3). |
| HTTP 422 | unsupported_capability / enrollment_* | The selected model/capability is unavailable, or enrollment constraints are not met. |
| HTTP 429 | capacity_exceeded | Capacity is currently exhausted; follow Retry-After. |
| HTTP 500/504 | inference_error / inference_timeout | Upstream inference failed or exceeded the wait budget. |
| HTTP 503 | service_unavailable | The selected backend is unavailable. |