首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用java sdk 3调用“一句话识别”接口不成功,报错InternalError 。。。?

用java sdk 3调用“一句话识别”接口不成功,报错InternalError 。。。?

提问于 2018-08-16 10:55:23
回答 2关注 1查看 1.5K

错误信息是InternalError-An internal error has occurred. Retry your request, but if the problem persists, contact us.

调用的代码如下,最大问题是官方没有给出“一句话识别”接口的调用demo代码(java sdk只有一个接口的demo,但不同接口参数格式区别很大),另外错误信息也完全无助于找出错误原因

代码语言:java
复制
        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);

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档