AI 音频检测接口
检测一段音频是否由 AI 生成(TTS、语音克隆等),返回检测结论与置信度评分。
接口信息
- 接口路径:
/v1/audio/ai-detect - 请求方式:
POST - 认证方式: Header 中的
X-API-Key - 响应格式: JSON;请通过
succeed判断检测是否成功,通过error_code和error_message查看失败原因 - HTTP 状态码: 检测成功或失败均返回
200,请同时检查succeed;请求体过大或请求方法不匹配时,可能返回413、405,且不使用下文的 JSON 响应结构
请求头
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| X-API-Key | string | 是 | 应用密钥 |
音频输入方式(二选一)
方式一:传入 URL
以 application/json 发送请求,在请求体中提供音频的公开访问地址。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| audio_url | string | 是 | 音频文件的 HTTP/HTTPS 地址,支持 .wav / .mp3 |
方式二:上传文件
以 multipart/form-data 发送请求,将音频文件作为表单字段上传。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| audio | file | 是 | 音频文件,支持 .wav / .mp3,大小不超过 50MB |
响应参数
通用响应结构
| 字段 | 类型 | 说明 |
|---|---|---|
| error_code | number | 错误码;成功为 0 |
| error_message | string | 错误信息;成功时为空 |
| succeed | boolean | 检测是否成功 |
| data | object | null | 成功时为检测结果;失败时为 null |
data 字段
| 字段 | 类型 | 说明 |
|---|---|---|
| prediction | string | 预测类别:Fake(AI 生成)或 Real(真实人声)。主要凭此字段判断结果。 |
| confidence | string | 对 prediction 这一类别的置信度,范围 0.50 ~ 1.00,保留 4 位小数。prediction=Fake, confidence=0.97 → 97% 确信是 AI;prediction=Real, confidence=0.97 → 97% 确信是真人。注意:不是「是 AI 的概率」,请结合 prediction 一起判断 |
| descriptor | string | 置信描述:Definitely(confidence > 0.90) / Likely(0.70 ~ 0.90) / Unsure, but leaning(0.50 ~ 0.70) |
响应示例
判定为 AI(confidence 表示「确信是 AI」的程度):
{
"error_code": 0,
"error_message": "",
"succeed": true,
"data": {
"prediction": "Fake",
"confidence": "0.9971",
"descriptor": "Definitely"
}
}
判定为真人(confidence 表示「确信是真人」的程度):
{
"error_code": 0,
"error_message": "",
"succeed": true,
"data": {
"prediction": "Real",
"confidence": "0.8865",
"descriptor": "Likely"
}
}
请求示例
URL 方式
curl -X POST "https://api.vuilabs.cn/v1/audio/ai-detect" \
-H "X-API-Key: your-secret-key-here" \
-H "Content-Type: application/json" \
-d '{
"audio_url": "https://example.com/sample.wav"
}'
文件上传方式
curl -X POST "https://api.vuilabs.cn/v1/audio/ai-detect" \
-H "X-API-Key: your-secret-key-here" \
-F "audio=@/path/to/sample.wav"
各语言示例
URL 方式
Python
import requests
response = requests.post(
"https://api.vuilabs.cn/v1/audio/ai-detect",
headers={"X-API-Key": "your-secret-key-here"},
json={"audio_url": "https://example.com/sample.wav"}
)
result = response.json()
if not result["succeed"]:
raise RuntimeError(f"{result['error_code']}: {result['error_message']}")
data = result["data"]
print(f"预测类别: {data['prediction']}")
print(f"置信度: {data['confidence']}")
print(f"置信描述: {data['descriptor']}")
is_ai = data["prediction"] == "Fake"
print(f"是否 AI 生成: {is_ai}")
Node.js
const response = await fetch("https://api.vuilabs.cn/v1/audio/ai-detect", {
method: "POST",
headers: {
"X-API-Key": "your-secret-key-here",
"Content-Type": "application/json",
},
body: JSON.stringify({ audio_url: "https://example.com/sample.wav" }),
});
const result = await response.json();
if (!result.succeed) {
throw new Error(`${result.error_code}: ${result.error_message}`);
}
const data = result.data;
console.log("预测类别:", data.prediction);
console.log("置信度:", data.confidence);
console.log("置信描述:", data.descriptor);
const isAI = data.prediction === "Fake";
console.log("是否 AI 生成:", isAI);
文件上传方式
Python
import requests
with open("/path/to/sample.wav", "rb") as f:
response = requests.post(
"https://api.vuilabs.cn/v1/audio/ai-detect",
headers={"X-API-Key": "your-secret-key-here"},
files={"audio": f}
)
result = response.json()
if not result["succeed"]:
raise RuntimeError(f"{result['error_code']}: {result['error_message']}")
data = result["data"]
print(f"预测类别: {data['prediction']}")
print(f"置信度: {data['confidence']}")
print(f"置信描述: {data['descriptor']}")
is_ai = data["prediction"] == "Fake"
print(f"是否 AI 生成: {is_ai}")
Node.js
const fs = require("fs");
const FormData = require("form-data");
const form = new FormData();
form.append("audio", fs.createReadStream("/path/to/sample.wav"));
const response = await fetch("https://api.vuilabs.cn/v1/audio/ai-detect", {
method: "POST",
headers: {
"X-API-Key": "your-secret-key-here",
...form.getHeaders(),
},
body: form,
});
const result = await response.json();
if (!result.succeed) {
throw new Error(`${result.error_code}: ${result.error_message}`);
}
const data = result.data;
console.log("预测类别:", data.prediction);
console.log("置信度:", data.confidence);
console.log("置信描述:", data.descriptor);
const isAI = data.prediction === "Fake";
console.log("是否 AI 生成:", isAI);
错误响应
检测失败时,HTTP 状态码仍为 200,请通过 JSON 响应中的 succeed 和错误信息判断结果:
{
"error_code": 10001,
"error_message": "参数错误",
"succeed": false,
"data": null
}
错误码说明
| error_code | error_message | 说明 |
|---|---|---|
| 10001 | 参数错误 | 未提供音频、audio_url 非 HTTP/HTTPS、URL 不可下载、文件字段名不是 audio、文件格式不支持(仅支持 .wav / .mp3)、音频无法解析等 |
| 10003 | 未授权 | Header 中缺少 X-API-Key,或 API Key 无效、未授权 |
| 20003 | 余额不足 | 免费时长已用完且账户余额不足 |
| 10000 | 服务器内部错误 | 检测处理失败,请查看 error_message;如提示繁忙或超时,可稍后重试,持续失败请联系支持 |
请求体过大时,可能返回 HTTP
413;请求方法不匹配时,可能返回 HTTP405。这类响应不使用上述 JSON 结构,请先检查 HTTP 状态码,再解析响应内容。
计费说明
具体计费规则、价格和免费额度请参见 产品计费。
使用建议
- 判断结果以
prediction为准:prediction === "Fake"即视为 AI 生成。 - 结合
confidence阈值与业务规则使用:descriptor=Unsure, but leaning(0.50 ~ 0.70)意味着模型自身不太确定,建议在此区间引入二次人工核验或更严格的业务策略;Definitely(> 0.90)和Likely(0.70 ~ 0.90)可作为更可靠的决策依据。 - 不要把
confidence当成「是 AI 的概率」直接比较。它表示对prediction这一类别的置信度,请结合prediction字段一起判断。 - 音频质量与时长:建议输入 ≥ 3 秒、采样率不低于 16 kHz 的清晰录音;过短或被严重降噪/变调/剪辑处理的音频可能影响识别结果。
- 大批量场景建议错峰调用;若返回
error_code=10000且提示繁忙,可稍等片刻后重试。