Voice Sentiment Analysis · Descriptions · 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-captioning/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.
audio: audio file; mode: sec (default, natural-language captions) or ser (label classification); language: result language hint, such as zh or en.
| Parameter | Type | Required | Description |
|---|---|---|---|
audio | file | Yes | PCM WAV audio to analyze, 80 ms–15 seconds, maximum 20 MiB. |
mode | string | No | sec (default, natural-language caption) or ser (label classification). |
language | string | No | Language hint, for example zh or en. |
Response fields
| Field | Type | Description |
|---|---|---|
status | string | succeeded on success. |
result | object | Final emotion captioning result. |
result.type | string? | final_emotion identifies an emotion result. |
result.mode | string | sec for natural-language captions; ser for label classification. |
result.text | string? | Emotion caption returned by the model. |
result.label | string? | Emotion label when returned; absence does not imply neutral. |
result.duration_sec | number | Processed duration in seconds. |
result.language | string? | Result language 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-captioning/sync' \
-H "Authorization: $FOURHZ_API_KEY" \
-F 'audio=@audio.wav' \
-F 'mode=sec' \
-F 'language=zh'# pip install requests
import os
import requests
from contextlib import ExitStack
url = "https://api.fourhz.ai/v1/emotion-captioning/sync"
headers = {"Authorization": os.environ["FOURHZ_API_KEY"]}
with ExitStack() as stack:
files = [
("audio", ("audio.wav", stack.enter_context(open("audio.wav", "rb"))))
]
fields = {"mode":"sec","language":"zh"}
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/emotion-captioning/sync";
const headers = {"Authorization": process.env.FOURHZ_API_KEY};
const body = new FormData();
body.append("audio", new Blob([await readFile("audio.wav")]), "audio.wav");
body.append("mode", "sec");
body.append("language", "zh");
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.
{
"status": "succeeded",
"result": {
"type": "final_emotion",
"mode": "sec",
"label": "Happy",
"text": "The speaker sounds excited and cheerful.",
"duration_sec": 2.68,
"language": "en"
}
}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.