Voice Sentiment Analysis · Labels · Pre-recorded
Service endpoints
Service URL: https://api.fourhz.ai
| Method / Protocol | Path | Content-Type / Frames | Auth |
|---|---|---|---|
| POST | /v1/emotion-recognition/pre-recorded | multipart/form-data | Authorization: <API Key> |
| GET | /v1/tasks/{task_id} | — | Authorization: <API Key> |
Request parameters
Submission returns HTTP 202 with task_id, status=pending and task_type. Poll GET /v1/tasks/{task_id} using an API key from the same account, about once per second. States: pending, running, succeeded, failed, cancelled. Read result on success; read error and stop polling on failure. Maximum audio duration: one hour; upload limit: 20 MiB. Duration is enforced by the executor. Returns 503 when the task service is unavailable; never falls back to a synchronous result.
file: audio file.
| Parameter | Type | Required | Description |
|---|---|---|---|
file | file | Yes | PCM WAV audio to analyze, up to one hour, maximum 20 MiB. |
Response fields
| Field | Type | Description |
|---|---|---|
task_id | string | Task ID from submission; query with GET /v1/tasks/{task_id}. |
task_type | string | e2v for emotion labels; emotion for captioning. |
status | string | pending on submission; pending / running / succeeded / failed / cancelled when queried. |
result | object? | Analysis result after successful completion; may be absent before completion. |
error | object? | Error details on task failure; stop polling after failure. |
usage | object? | Usage reported by the server. |
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/pre-recorded' \
-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/pre-recorded"
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/pre-recorded";
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());curl -X GET 'https://api.fourhz.ai/v1/tasks/TASK_ID' \
-H "Authorization: $FOURHZ_API_KEY"# pip install requests
import os
import requests
from contextlib import ExitStack
url = "https://api.fourhz.ai/v1/tasks/TASK_ID"
headers = {"Authorization": os.environ["FOURHZ_API_KEY"]}
with ExitStack() as stack:
response = requests.request("GET", url, headers=headers, timeout=300)
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/tasks/TASK_ID";
const headers = {"Authorization": process.env.FOURHZ_API_KEY};
const response = await fetch(url, {method: "GET", headers, 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
Submission response: HTTP 202, accepted but not yet analyzed.
{
"task_id": "task_example",
"status": "pending",
"task_type": "e2v"
}Poll GET /v1/tasks/task_example with credentials from the same account. Example HTTP 200 response after completion:
{
"task_id": "task_example",
"task_type": "e2v",
"status": "succeeded",
"result": {
"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.