首页 智能对话分析 最佳实践 阿里云-云呼叫中心

阿里云-云呼叫中心

智能对话分析对接云呼叫中心。

自动对接

通过呼叫中心或其他途径产生的对话录音,需要通过 上传音频质检接口来上传到 智能对话分析,所以需要您拥有一定的程序开发能力,而且还需要将您的录音文件存放在一个可以公网访问的服务器上。

我们推荐您使用 阿里云-云呼叫中心阿里云-云呼叫中心智能对话分析 已经做了无缝对接,通过 云呼叫中心 产生的录音,会自动推送到智能对话分析进行质检分析,无需您自行对接。

如需进一步了解,请点击 了解更多

手动对接

若云呼叫中心自动推送的质检任务不符合您的要求,可以考虑通过接入SDK方式发起质检分析。

流程为:

  • 调用云呼SDK的GetUploadAudioDataParams接口,获取云呼音频信息

具体说明参考 GetUploadAudioDataParams接口文档

  • 组装入参信息jsonStr

具体说明参考上传音频质检

  • 调用智能对话分析的UploadAudioData接口,发起质检分析

以Java代码为例:

maven依赖,接入云呼和质检SDK,其中fastjson可选

        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>ccc20200701</artifactId>
            <version>2.6.7</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-qualitycheck</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.83_noneautotype</version>
        </dependency>

完整调用demo(入口为main方法)

// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.ccc20200701.models.GetUploadAudioDataParamsResponse;
import com.aliyun.tea.TeaException;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.qualitycheck.model.v20190115.UploadAudioDataRequest;
import com.aliyuncs.qualitycheck.model.v20190115.UploadAudioDataResponse;

/**
 * 从云呼获取音频信息到发起音频质检链路Demo
 * 需要准备内容
 * 1.云呼子用户的AkSk
 * 2.质检子账号的AkSk
 * 3.云呼音频对应的contactId和instanceId
 * 可选
 * 4.UploadAudioData的jsonStr中的其他参数,按需添加
 */
public class Sample {

    /**
     * 使用AK&SK初始化账号云呼Client
     * @param accessKeyId 云呼子账号的Ak
     * @param accessKeySecret 云呼子账号的Sk
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.ccc20200701.Client createCCClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "ccc.cn-shanghai.aliyuncs.com";
        return new com.aliyun.ccc20200701.Client(config);
    }

    /**
     * 使用AK&SK初始化账号质检Client
     * @param accessKeyId 质检子账号的Ak
     * @param accessKeySecret 质检子账号的Sk
     * @return Client
     * @throws Exception
     */
    public static IAcsClient createSCAClient(String accessKeyId, String accessKeySecret) throws Exception {

        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        //指定Endpoint,以下值为固定
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Qualitycheck", "qualitycheck.cn-hangzhou.aliyuncs.com");

        return new DefaultAcsClient(profile);
    }


    /**
     * 通过云呼SDK调用获取音频的相关参数
     * @param args_
     * @throws Exception
     */
    public static void main(String[] args_) throws Exception {

        /**
         * 1.调用云呼SDK发起获取音频信息
         * 具体以云呼文档为准,https://help.aliyun.com/document_detail/450651.html
         */
        String ccAudioStr = getParamStr("","");

        /**
         * 例-ccAudioStr返回值,其中validTimes,channels为必要数据,其他按需获取
         * {
         *     "autoSplit":1,
         *     "appKey":1**********1,
         *     "sampleRate":8,
         *     "callList":[
         *         {
         *             "callId":"job-2********8",
         *             "validTimes":[
         *                 {
         *                     "begin_time":0,
         *                     "end_time":67060,
         *                     "speaker_id":"xuan"
         *                 }
         *             ],
         *             "resolveType":"ali-ACC",
         *             "instance":"report-test-2",
         *             "callee":"1********2",
         *             "accUid":1********1,
         *             "callStartTime":1659444574225,
         *             "customerServiceName":"x****qi",
         *             "tid":"760427ac-fa3f-4785-8286-1cb2cf3104b9",
         *             "callType":1,
         *             "skillGroupUUID":"listTest@report-test-2",
         *             "caller":"0********8",
         *             "customerServicePhone":"8********7",
         *             "channels":[
         *                 {
         *                     "speaker_id":"x****o",
         *                     "channel_key":"ch-user-1********2-8********7-1********6-job-2********8"
         *                 }
         *             ],
         *             "sourceType":1,
         *             "channelKey":"ch-user-1********2-8********7-1********6-job-2********8",
         *             "skillGroupName":"listTest",
         *             "voiceFileUrl":"https://ccc-v2-staging.oss-cn-hangzhou.aliyuncs.com/ccc-record-mixed/report-test-2/2022/08/job-2********8.mkv?Expires=1663124613&OSSAccessKeyId=L********q&Signature=bxLnpftFnn4h1GU1FqPPrgvGrCk%3D#v2",
         *             "skillGroupId":0,
         *             "customerServiceId":2**********4
         *         }
         *     ]
         * }
         */

        /**
         * 2. 组装调用参数
         */
        String jsonStr = assemble(ccAudioStr);
        /**
         * 例-jsonStr返回值,其中validTimes,channels,voiceFileUrl,audioType为必要数据,其他按需获取
         * {
         *     "callList":[
         *         {
         *             "audioType":"ali-mkv",
         *             "validTimes":[
         *                 {
         *                     "begin_time":0,
         *                     "end_time":67060,
         *                     "speaker_id":"x****i"
         *                 }
         *             ],
         *             "channels":[
         *                 {
         *                     "speaker_id":"x****i",
         *                     "channel_key":"ch-user-1********2-8********7-1********6-job-2********8"
         *                 }
         *             ],
         *             "voiceFileUrl":"https://ccc-v2-staging.oss-cn-hangzhou.aliyuncs.com/ccc-record-mixed/report-test-2/2022/08/job-2********8.mkv?Expires=1663124613&OSSAccessKeyId=L********q&Signature=bxLnpftFnn4h1GU1FqPPrgvGrCk%3D#v2",
         *         }
         *     ]
         * }
         */
        /**
         * 3. 调用质检SDK发起音频质检任务
         * 详细文档以质检为准,https://help.aliyun.com/document_detail/139399.html
         */
        uploadAudioData(jsonStr);
    }

    /**
     * 获取音频信息,调用UploadAudioData是作为入参用
     * @param contactId 会话Id
     * @param instanceId 实例Id
     * @throws Exception
     */
    public static String getParamStr(String contactId,String instanceId) throws Exception {
        com.aliyun.ccc20200701.Client client = Sample.createCCClient("accessKeyId", "accessKeySecret");
        com.aliyun.ccc20200701.models.GetUploadAudioDataParamsRequest getUploadAudioDataParamsRequest = new com.aliyun.ccc20200701.models.GetUploadAudioDataParamsRequest();
        getUploadAudioDataParamsRequest.setContactId(contactId);
        getUploadAudioDataParamsRequest.setInstanceId(instanceId);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            GetUploadAudioDataParamsResponse uploadAudioDataParamsWithOptions = client.getUploadAudioDataParamsWithOptions(getUploadAudioDataParamsRequest, runtime);
            System.out.println(uploadAudioDataParamsWithOptions.getBody().getData().getParamsStr());
            return uploadAudioDataParamsWithOptions.getBody().getData().getParamsStr();
        } catch (TeaException error) {
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
        return null;
    }

    /**
     * 按需组装jsonStr,这里只展示必要条件
     * @param ccAudioStr
     * @return
     */
    public static String assemble(String ccAudioStr) {
        JSONObject jsonStrObject = new JSONObject();
        JSONObject ccStrObject = JSON.parseObject(ccAudioStr);

        JSONArray callList = ccStrObject.getJSONArray("callList");
        JSONArray jsonStrCallList = new JSONArray();
        callList.add(
                new JSONObject()
                        .fluentPut("validTimes",callList.getJSONObject(0).getJSONObject("validTimes"))
                        .fluentPut("channels",callList.getJSONObject(0).getJSONObject("channels"))
                        .fluentPut("voiceFileUrl",callList.getJSONObject(0).getString("voiceFileUrl"))
                        //注意! 需要额外传入参数audioType=ali-mkv
                        .fluentPut("audioType","ali-mkv")
        );
        jsonStrObject.put("callList",jsonStrCallList);
        System.out.println(jsonStrObject.toJSONString());
        return jsonStrObject.toJSONString();
    }

    public static void uploadAudioData(String ccAudioStr) {
        UploadAudioDataRequest req = new UploadAudioDataRequest();
        //可以在ccAudioStr的基础上添加其他参数
        req.setJsonStr(ccAudioStr);
        try {
            UploadAudioDataResponse response = createSCAClient("accessKeyId","accessKeySecret").getAcsResponse(req);
            // do something.
            System.out.println(response.getCode());
            System.out.println(response.getMessage());
            System.out.println(response.getData());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

阿里云首页 智能对话分析 相关技术圈