Voice Sentiment Analysis · Labels · Synchronous
Sync accepts up to 15 seconds; use Pre-recorded for longer audio.
Service endpoints
Service URL: https://api.fourhz.ai
| Method / Protocol | Path | Content-Type / Frames | Auth |
|---|---|---|---|
| POST | /v1/emotion-recognition/sync | multipart/form-data | Authorization: <API Key> |
Request parameters
Returns the final result with HTTP 200, never a pending task_id. PCM WAV only, 80 ms–15 seconds, maximum 20 MiB. Server processing waits up to 120 seconds. A normal synchronous call returns its final result without polling. A timeout or disconnect does not prove cancellation; do not retry blindly. Keep any job_id or X-Job-Id for investigation, and query a task only when its ID is available.
file: audio file. Returns best_label, best_score, top_emotions and duration_seconds when reported.
| Parameter | Type | Required | Description |
|---|---|---|---|
file | file | Yes | PCM WAV audio to analyze, 80 ms–15 seconds, maximum 20 MiB. |
Response fields
| Field | Type | Description |
|---|---|---|
filename | string | Uploaded filename. |
duration_seconds | number | Processed audio duration in seconds. |
best_label | string | Best emotion label. |
best_score | number? | Model score when returned; not a calibrated probability. |
top_emotions[] | array? | Candidate emotions and scores when returned. |
Request examples
Python uses requests. JavaScript file examples use Node.js 22+. Long-lived keys are server-side only.
curl -X POST 'https://api.fourhz.ai/v1/emotion-recognition/sync' \
-H "Authorization: $FOURHZ_API_KEY" \
-F 'file=@audio.wav'# pip install requests
import os
import requests
from contextlib import ExitStack
url = "https://api.fourhz.ai/v1/emotion-recognition/sync"
headers = {"Authorization": os.environ["FOURHZ_API_KEY"]}
with ExitStack() as stack:
files = [
("file", ("audio.wav", stack.enter_context(open("audio.wav", "rb"))))
]
response = requests.request("POST", url, headers=headers, timeout=300, files=files)
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/emotion-recognition/sync";
const headers = {"Authorization": process.env.FOURHZ_API_KEY};
const body = new FormData();
body.append("file", new Blob([await readFile("audio.wav")]), "audio.wav");
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());Response examples
HTTP 200 returns the final result directly; no polling. Scores and text illustrate the response structure.
{
"filename": "audio.wav",
"best_label": "happy",
"best_score": 0.91,
"top_emotions": [
{
"label": "happy",
"score": 0.91
},
{
"label": "neutral",
"score": 0.07
}
],
"duration_seconds": 2.68
}Errors
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.
Common statuses: 400 invalid parameters or audio; 401 authentication failed; 402 insufficient balance; 413 file too large; 415 file content is not supported audio; 429 rate limit or capacity full (honor Retry-After); 503 service not configured or unavailable.