Smart Conversation Analysis is integrated with Cloud Call Center. Two integration methods are available: automatic and manual.
Automatic integration
Recordings from Cloud Call Center are automatically pushed to Smart Conversation Analysis for quality inspection. For more information, see Quality inspection push management.
Manual integration
If automatic integration does not meet your requirements, you can initiate a quality inspection using the SDK.
The process is as follows:
Call the GetUploadAudioDataParams operation of the Cloud Call Center SDK to obtain audio information.
For more information, see GetUploadAudioDataParams.
Assemble the jsonStr input parameter.
For more information, see Upload audio data for quality inspection.
Call the UploadAudioData operation of Smart Conversation Analysis to initiate a quality inspection.
The following Java code provides an example:
The following are the Maven dependencies for integrating the Cloud Call Center and Smart Conversation Analysis SDKs. The fastjson dependency is optional.
<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>The following is a complete example. The entry point is the main method.
Before you call the operation, configure environment variables to read access credentials. For more information, see Java SDK - Instructions - Configure access credentials.
The environment variables for the AccessKey ID and AccessKey secret of Cloud Call Center are CC_AK_ENV and CC_SK_ENV.
The environment variables for the AccessKey ID and AccessKey secret of Smart Conversation Analysis are SCA_AK_ENV and SCA_SK_ENV.
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 for the process of obtaining audio information from Cloud Call Center and initiating an audio quality inspection.
* Prerequisites:
* 1. The contactId and instanceId that correspond to the audio file in Cloud Call Center.
* 2. (Optional) Other parameters in the jsonStr of UploadAudioData. Add them as needed.
*/
public class Sample {
/**
* Initializes the Cloud Call Center client by reading the AccessKey from environment variables.
* @return Client
* @throws Exception
*/
public static com.aliyun.ccc20200701.Client createCCClient() throws Exception {
// An AccessKey pair of an Alibaba Cloud account has permissions on all API operations. This poses a high security threat. We recommend that you create and use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
// In this example, the AccessKey ID and AccessKey secret are stored in environment variables. You can also store them in a configuration file as needed.
// We strongly recommend that you do not hard-code the AccessKey ID and AccessKey secret in your code. Otherwise, the AccessKey pair may be leaked.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(System.getenv("CC_AK_ENV"))
.setAccessKeySecret(System.getenv("CC_SK_ENV"));
// The service endpoint of Cloud Call Center. This example uses cn-shanghai.
config.endpoint = "ccc.cn-shanghai.aliyuncs.com";
return new com.aliyun.ccc20200701.Client(config);
}
/**
* Initializes the Smart Conversation Analysis client by reading the AccessKey from environment variables.
* @return Client
* @throws Exception
*/
public static IAcsClient createSCAClient() throws Exception {
// An AccessKey pair of an Alibaba Cloud account has permissions on all API operations. This poses a high security threat. We recommend that you create and use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
// In this example, the AccessKey ID and AccessKey secret are stored in environment variables. You can also store them in a configuration file as needed.
// We strongly recommend that you do not hard-code the AccessKey ID and AccessKey secret in your code. Otherwise, the AccessKey pair may be leaked.
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", System.getenv("SCA_AK_ENV"), System.getenv("SCA_SK_ENV"));
// Specify the service endpoint. The following value is fixed.
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Qualitycheck", "qualitycheck.cn-hangzhou.aliyuncs.com");
return new DefaultAcsClient(profile);
}
/**
* Calls the Cloud Call Center SDK to obtain audio parameters.
* @param args_
* @throws Exception
*/
public static void main(String[] args_) throws Exception {
/**
* 1. Call the Cloud Call Center SDK to obtain audio information.
* For a detailed example, see https://help.aliyun.com/document_detail/450651.html
* You can query the contactId and instanceId that correspond to the audio file in the Cloud Call Center console.
*/
String ccAudioStr = getParamStr("your_contact_id","your_instance_id");
/**
* Example of the ccAudioStr response. The validTimes and channels parameters are required. Obtain other parameters as needed.
* {
* "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. Assemble the request parameters.
*/
String jsonStr = assemble(ccAudioStr);
/**
* Example of the jsonStr response. The validTimes, channels, voiceFileUrl, and audioType parameters are required. Obtain other parameters as needed.
* {
* "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. Call the Smart Conversation Analysis SDK to initiate an audio quality inspection task.
* For more information, see the document at https://help.aliyun.com/document_detail/139399.html
*/
uploadAudioData(jsonStr);
}
/**
* Obtains audio information to be used as an input parameter for the UploadAudioData operation.
* You can query the contactId and instanceId that correspond to the audio file in the Cloud Call Center console.
* @param contactId The session ID.
* @param instanceId The instance ID.
* @throws Exception
*/
public static String getParamStr(String contactId,String instanceId) throws Exception {
com.aliyun.ccc20200701.Client client = Sample.createCCClient();
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 {
GetUploadAudioDataParamsResponse uploadAudioDataParamsWithOptions = client.getUploadAudioDataParamsWithOptions(getUploadAudioDataParamsRequest, runtime);
// You can add your own logic to record logs as needed.
System.out.println(uploadAudioDataParamsWithOptions.getBody().getData().getParamsStr());
return uploadAudioDataParamsWithOptions.getBody().getData().getParamsStr();
} catch (TeaException error) {
// You can add your own logic to record error logs as needed.
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// You can add your own logic to record error logs as needed.
com.aliyun.teautil.Common.assertAsString(error.message);
}
return null;
}
/**
* Assembles the jsonStr as needed. This example shows only the required parameters.
* @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"))
// The audioType parameter must be set to ali-mkv.
.fluentPut("audioType","ali-mkv")
);
jsonStrObject.put("callList",jsonStrCallList);
// You can add other parameters to implement custom business logic.
System.out.println(jsonStrObject.toJSONString());
return jsonStrObject.toJSONString();
}
public static void uploadAudioData(String ccAudioStr) {
UploadAudioDataRequest req = new UploadAudioDataRequest();
req.setJsonStr(ccAudioStr);
try {
UploadAudioDataResponse response = createSCAClient().getAcsResponse(req);
System.out.println(response.getCode());
System.out.println(response.getMessage());
System.out.println(response.getData());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}