6. 语种识别
6.1 需要依赖
<!-- 统一版本管理中-->
<tencentcloud.version>3.1.317</tencentcloud.version>
<!--腾讯通用-->
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>${tencentcloud.version}</version>
</dependency>
<!--然后在需要用到的地方引入这个-->
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
</dependency>
6.2 使用
package com.smart.hnj.common.utils;
import com.smart.hnj.common.model.TencentSecret;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.tmt.v20180321.TmtClient;
import com.tencentcloudapi.tmt.v20180321.models.*;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TellLanguageUtils {
public static String tellLanguage(String content) {
try {
String secretId = TencentSecret.SECRET_ID;
String secretKey = TencentSecret.SECRET_KEY;
Credential cred = new Credential(secretId, secretKey);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("tmt.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
TmtClient client = new TmtClient(cred, "ap-shanghai", clientProfile);
LanguageDetectRequest req = new LanguageDetectRequest();
req.setText("how to go to beijin");
req.setProjectId(0L);
LanguageDetectResponse resp = client.LanguageDetect(req);
return resp.getLang();
} catch (TencentCloudSDKException e) {
log.info("腾讯云接口请求错误,错误信息:{}", e.toString());
return null;
}
}
}
6.3 参考api地址
https://console.cloud.tencent.com/api/explorer?Product=tmt&Version=2018-03-21&Action=LanguageDetect&SignVersion=
版权声明:本文为weixin_43329956原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。