错误信息是InternalError-An internal error has occurred. Retry your request, but if the problem persists, contact us.
调用的代码如下,最大问题是官方没有给出“一句话识别”接口的调用demo代码(java sdk只有一个接口的demo,但不同接口参数格式区别很大),另外错误信息也完全无助于找出错误原因
String secretId = ApplicationProperties.getByKey("tencent.cloud.secretId").trim();
String secretKey = ApplicationProperties.getByKey("tencent.cloud.secretKey").trim();
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
Credential cred = new Credential(secretId, secretKey);
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setReqMethod("POST"); // post请求(默认为post请求)
httpProfile.setConnTimeout(30); // 请求连接超时时间,单位为秒(默认60秒)
httpProfile.setEndpoint("aai.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setSignMethod("HmacSHA256"); // 指定签名算法(默认为HmacSHA256)
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品(以cvm为例)的client对象
AaiClient client = new AaiClient(cred, "ap-guangzhou", clientProfile);
// 实例化一个请求对象
SentenceRecognitionRequest req = new SentenceRecognitionRequest();
req.setProjectId(0);
req.setSubServiceType(2);
req.setEngSerViceType("8k");
req.setSourceType(1);
req.setVoiceFormat("mp3");
req.setUsrAudioKey(UUID.randomUUID().toString());
// BASE64Encoder encoder = new BASE64Encoder();
FileInputStream inputFile = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length()];
inputFile.read(buffer);
inputFile.close();
String base64 = new BASE64Encoder().encode(buffer);
req.setData(base64);
req.setDataLen(base64.length());
// 通过client对象调用想要访问的接口,需要传入请求对象
SentenceRecognitionResponse resp = client.SentenceRecognition(req);
String ret = SentenceRecognitionRequest.toJsonString(resp);
相似问题