点播语音信息提交接口

接口地址

https://as.dun.163yun.com/v3/audio/submit

接口描述

提交语音的URL进行语音内容检测

查看V1.0提交接口文档

音频文件限制

时长小于5小时,音频文件大小不超过550M

请求参数

公共参数已省略,详细见 请求公共参数,其他参数如下:

参数名称类型是否必选最大长度描述
urlStringY512语音文件url
versionStringY4接口版本号,可选值 v3.1
titleStringN512文件标题
ipStringN32用户IP地址
accountStringN128用户唯一标识,如果无需登录则为空
deviceIdStringN128用户设备 id
deviceTypeNumberN4用户设备类型,1:web, 2:wap, 3:android, 4:iphone, 5:ipad, 6:pc, 7:wp
callbackStringN2^16-1数据回调参数,调用方根据业务情况自行设计,当调用离线结果获取接口时,该接口会原样返回该字段,详细见音频离线检测结果获取。作为数据处理标识,因此该字段应该设计为能唯一定位到该次请求的数据结构,如对用户的昵称进行检测,dataId可设为用户标识(用户ID),用户修改多次,每次请求数据的dataId可能一致,但是callback参数可以设计成定位该次请求的数据结构,比如callback字段设计成json,包含dataId和请求的时间戳等信息,当然如果不想做区分,也可以直接把callback设置成dataId的值。
callbackUrlStringN256离线结果回调通知到客户的URL。主动回调数据接口超时时间设置为2s,为了保证顺利接收数据,需保证接收接口性能稳定并且保证幂等性。

响应结果

响应字段如下,响应通用字段已省略,详细见响应通用字段

result 数据结构

参数名称	类型	描述
taskId	String	本次请求数据标识,可以根据该标识查询数据最新结果
status	Number	请求结果,0成功,1失败

请求示例

/*
 * @(#) VideoSubmitAPIDemo.java 2016年8月23日
 *
 * Copyright 2010 NetEase.com, Inc. All rights reserved.
 */
package com.netease.is.antispam.demo.audio;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.netease.is.antispam.demo.utils.HttpClient4Utils;
import com.netease.is.antispam.demo.utils.SignatureUtils;
import org.apache.http.Consts;
import org.apache.http.client.HttpClient;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * 调用易盾反垃圾云服务音频信息提交接口API示例,该示例依赖以下jar包:
 * 1. httpclient,用于发送http请求
 * 2. commons-codec,使用md5算法生成签名信息,详细见SignatureUtils.java
 * 3. gson,用于做json解析
 *
 * @author hzhumin1
 * @version 2018年10月25日
 */
public class AudioSubmitAPIDemo {
    /**
     * 产品密钥ID,产品标识
     */
    private final static String SECRETID = "your_secret_id";
    /**
     * 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
     */
    private final static String SECRETKEY = "your_secret_key";
    /**
     * 业务ID,易盾根据产品业务特点分配
     */
    private final static String BUSINESSID = "your_business_id";
    /**
     * 易盾反垃圾云服务音频信息提交接口地址
     */
    private final static String API_URL = "https://as.dun.163yun.com/v3/audio/submit";
    /**
     * 实例化HttpClient,发送http请求使用,可根据需要自行调参
     */
    private static HttpClient httpClient = HttpClient4Utils.createHttpClient(100, 20, 1000, 1000, 1000);

    public static void main(String[] args) throws Exception {
        Map<String, String> params = new HashMap<String, String>();
        // 1.设置公共参数
        params.put("secretId", SECRETID);
        params.put("businessId", BUSINESSID);
        params.put("version", "v3.1");
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        params.put("nonce", String.valueOf(new Random().nextInt()));

        // 2.设置私有参数
        params.put("url", "http://xxx.xx");

        // 3.生成签名信息
        String signature = SignatureUtils.genSignature(SECRETKEY, params);
        params.put("signature", signature);

        // 4.发送HTTP请求,这里使用的是HttpClient工具包,产品可自行选择自己熟悉的工具包发送请求
        String response = HttpClient4Utils.sendPost(httpClient, API_URL, params, Consts.UTF_8);

        // 5.解析接口返回值
        JsonObject jObject = new JsonParser().parse(response).getAsJsonObject();
        int code = jObject.get("code").getAsInt();
        String msg = jObject.get("msg").getAsString();
        JsonObject result = jObject.get("result").getAsJsonObject();
        if (code == 200) {
            String taskId = result.get("taskId").getAsString();
            int status = result.get("status").getAsInt();
            if (status == 0) {
                System.out.println(String.format("SUBMIT SUCCESS: taskId=%s", taskId));
            } else {
                System.out.println(String.format("SUBMIT FAIL: taskId=%s, status=%s", taskId, status));
            }
        } else {
            System.out.println(String.format("ERROR: code=%s, msg=%s", code, msg));
        }
    }
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
易盾反垃圾云服务音频信息提交接口python示例代码
接口文档: http://dun.163.com/api.html
python版本:python3.7
运行:
    1. 修改 SECRET_ID,SECRET_KEY,BUSINESS_ID 为对应申请到的值
    2. $ python audio_submit.py
"""
__author__ = 'yidun-dev'
__date__ = '2019/11/27'
__version__ = '0.2-dev'

import hashlib
import time
import random
import urllib.request as urlrequest
import urllib.parse as urlparse
import json


class AudioSubmitAPIDemo(object):
    """音频信息提交接口示例代码"""

    API_URL = "https://as.dun.163yun.com/v3/audio/submit"
    VERSION = "v3.1"

    def __init__(self, secret_id, secret_key, business_id):
        """
        Args:
            secret_id (str) 产品密钥ID,产品标识
            secret_key (str) 产品私有密钥,服务端生成签名信息使用
            business_id (str) 业务ID,易盾根据产品业务特点分配
        """
        self.secret_id = secret_id
        self.secret_key = secret_key
        self.business_id = business_id

    def gen_signature(self, params=None):
        """生成签名信息
        Args:
            params (object) 请求参数
        Returns:
            参数签名md5值
        """
        buff = ""
        for k in sorted(params.keys()):
            buff += str(k) + str(params[k])
        buff += self.secret_key
        return hashlib.md5(buff.encode("utf8")).hexdigest()

    def check(self, params):
        """请求易盾接口
        Args:
            params (object) 请求参数
        Returns:
            请求结果,json格式
        """
        params["secretId"] = self.secret_id
        params["businessId"] = self.business_id
        params["version"] = self.VERSION
        params["timestamp"] = int(time.time() * 1000)
        params["nonce"] = int(random.random() * 100000000)
        params["signature"] = self.gen_signature(params)

        try:
            params = urlparse.urlencode(params).encode("utf8")
            request = urlrequest.Request(self.API_URL, params)
            content = urlrequest.urlopen(request, timeout=1).read()
            return json.loads(content)
        except Exception as ex:
            print("调用API接口失败:", str(ex))


if __name__ == "__main__":
    """示例代码入口"""
    SECRET_ID = "your_secret_id"  # 产品密钥ID,产品标识
    SECRET_KEY = "your_secret_key"  # 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
    BUSINESS_ID = "your_business_id"  # 业务ID,易盾根据产品业务特点分配
    api = AudioSubmitAPIDemo(SECRET_ID, SECRET_KEY, BUSINESS_ID)

    # 设置私有参数
    params = {
        "url": "http://xxx.xx"
    }

    ret = api.check(params)

    code: int = ret["code"]
    msg: str = ret["msg"]
    if code == 200:
        result: dict = ret["result"]
        taskId: str = result["taskId"]
        status: int = result["status"]
        if status == 0:
            print("SUBMIT SUCCESS: taskId=%s" % taskId)
        else:
            print("SUBMIT FAIL: taskId=%s, status=%s" % (taskId, status))
    else:
        print("ERROR: code=%s, msg=%s" % (ret["code"], ret["msg"]))
<?php
/** 音频提交检测接口 */
/** 产品密钥ID,产品标识 */
define("SECRETID", "your_secret_id");
/** 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露 */
define("SECRETKEY", "your_secret_key");
/** 业务ID,易盾根据产品业务特点分配 */
define("BUSINESSID", "your_business_id");
/** 易盾反垃圾云服务音频检测接口地址 */
define("API_URL", "https://as.dun.163yun.com/v3/audio/submit");
/** api version */
define("VERSION", "v3.1");
/** API timeout*/
define("API_TIMEOUT", 10);
/** php内部使用的字符串编码 */
define("INTERNAL_STRING_CHARSET", "auto");
/**
 * 计算参数签名
 * $params 请求参数
 * $secretKey secretKey
 */
function gen_signature($secretKey, $params){
	ksort($params);
	$buff="";
	foreach($params as $key=>$value){
	     if($value !== null) {
	        $buff .=$key;
		$buff .=$value;
    	     }
	}
	$buff .= $secretKey;
	return md5($buff);
}
/**
 * 将输入数据的编码统一转换成utf8
 * @params 输入的参数
 */
function toUtf8($params){
	$utf8s = array();
    foreach ($params as $key => $value) {
    	$utf8s[$key] = is_string($value) ? mb_convert_encoding($value, "utf8", INTERNAL_STRING_CHARSET) : $value;
    }
    return $utf8s;
}
/**
 * 反垃圾请求接口简单封装
 * $params 请求参数
 */
function check($params){
	$params["secretId"] = SECRETID;
	$params["businessId"] = BUSINESSID;
	$params["version"] = VERSION;
	$params["timestamp"] = time() * 1000;// time in milliseconds
	$params["nonce"] = sprintf("%d", rand()); // random int
	$params = toUtf8($params);
	$params["signature"] = gen_signature(SECRETKEY, $params);
	// var_dump($params);
	$options = array(
	    'http' => array(
	        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
	        'method'  => 'POST',
	        'timeout' => API_TIMEOUT, // read timeout in seconds
	        'content' => http_build_query($params),
	    ),
	);
	$context  = stream_context_create($options);
	$result = file_get_contents(API_URL, false, $context);
	if($result === FALSE){
		return array("code"=>500, "msg"=>"file_get_contents failed.");
	}else{
		return json_decode($result, true);	
	}
}
// 简单测试
function main(){
    echo "mb_internal_encoding=".mb_internal_encoding()."\n";
	$params = array(
		"url"=>"http://xxx.xxx.com/xxxx"
	);
	$ret = check($params);
	var_dump($ret);
	if ($ret["code"] == 200) {
		$result = $ret["result"];
        // status 0:成功,1:失败
        $status = $result["status"];
        $taskId = $result["taskId"];
        if($status === 0){
            echo "提交成功,taskId=".$taskId;
        }else{
            echo "提交失败,taskId=".$taskId;
        }
    }else{
    	var_dump($ret);
    }
}
main();
?>
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;

namespace Com.Netease.Is.Antispam.Demo
{
    class AudioSubmitApiDemo
    {

        public static void audioSubmit()
        {     
            /** 产品密钥ID,产品标识 */
            String secretId = "your_secret_id";
            /** 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露 */
            String secretKey = "your_secret_key";
            /** 业务ID,易盾根据产品业务特点分配 */
            String businessId = "your_business_id";
            /** 易盾反垃圾云服务音频信息提交接口地址  */
            String apiUrl = "https://as.dun.163yun.com/v3/audio/submit";
            Dictionary<String, String> parameters = new Dictionary<String, String>();

            long curr = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
            String time = curr.ToString();

            // 1.设置公共参数
            parameters.Add("secretId", secretId);
            parameters.Add("businessId", businessId);
            parameters.Add("version", "v3.1");
            parameters.Add("timestamp", time);
            parameters.Add("nonce", new Random().Next().ToString());

            // 2.设置私有参数
            parameters.Add("url", "http://xxx.xxx.com/xxxx");

            // 3.生成签名信息
            String signature = Utils.genSignature(secretKey, parameters);
            parameters.Add("signature", signature);

            // 4.发送HTTP请求
            HttpClient client = Utils.makeHttpClient();
            String result = Utils.doPost(client, apiUrl, parameters, 1000);
            if(result != null)
            {
                JObject ret = JObject.Parse(result);
                int code = ret.GetValue("code").ToObject<Int32>();
                String msg = ret.GetValue("msg").ToObject<String>();
                if (code == 200)
                {
                    JObject resultObject = (JObject)ret["result"];
                    String taskId = resultObject["taskId"].ToObject<String>();
                    int status = resultObject["status"].ToObject<Int32>();
                    if (status == 0) {
                        Console.WriteLine(String.Format("推送成功!taskId={0}", taskId));
                    } else {
                        Console.WriteLine(String.Format("推送失败!taskId={0}", taskId));
                    }
                }
                else
                {
                    Console.WriteLine(String.Format("ERROR: code={0}, msg={1}", code, msg));
                }
            }
            else
            {
                Console.WriteLine("Request failed!");
            }

        }      
    }
}
var utils=require("./utils");
//产品密钥ID,产品标识
var secretId="your_secret_id";
// 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
var secretKey="your_secret_key";
// 业务ID,易盾根据产品业务特点分配
var businessId="your_business_id";
// 易盾反垃圾云服务音频信息提交接口地址
var apiurl="https://as.dun.163yun.com/v3/audio/submit";
//请求参数
var post_data = {
    // 1.设置公有有参数
    secretId:secretId,
    businessId:businessId,
    version:"v3.1",
    timestamp:new Date().getTime(),
    nonce:utils.noncer(),
    // 2.设置私有参数
    url:"xxx"
};
var signature=utils.genSignature(secretKey,post_data);
post_data.signature=signature;
//http请求结果
var responseCallback=function(responseData){
    var data = JSON.parse(responseData);
    var code=data.code;
    var msg=data.msg;
    if(code==200){
        var result=data.result;
        var taskId=result.taskId;
        var status=result.status;
        if (status == 0) {
            console.log("SUBMIT SUCCESS!taskId="+taskId);
        } else {
            console.log("SUBMIT FAIL!taskId="+taskId+",status="+status);
        }
    }else{
        console.log('ERROR:code=' + code+',msg='+msg);
    }
}
utils.sendHttpRequest(apiurl,"POST",post_data,responseCallback);

响应示例

```json
{
    "code": 200,
    "msg": "ok",
    "result": {
			"taskId": "*****",
			"status": 0
		}
}
```
Online Chat Tel:95163223