开发者社区> 问答> 正文

阿里云语音接口调用出现 java.lang.NoSuchFieldError: Companion异

  • 环境 jdk1.8 spring4.3
  • 新版sdk image.png
  • client创建
    public static Client createClient(String accessKeyId, String accessKeySecret, String regionId) {
        com.aliyun.tearpc.models.Config config = new com.aliyun.tearpc.models.Config();
        // AccessKey ID
        config.accessKeyId = accessKeyId;
        // AccessKey Secret
        config.accessKeySecret = accessKeySecret;
        // 可用区ID
        config.regionId = regionId;
        try {
            return new Client(config);
        } catch (Exception e) {
    

// logger.info("语音通知初始化失败"); e.printStackTrace(); } return null; }

- 发送语音

public static SingleCallByTtsResponse noticeByVoice(String telephone, String tstCode, String ttsParam) { try { Client client = createClient(accessKeyId, accessSecret, "cn-hangzhou"); if (client == null) { return null; } SingleCallByTtsRequest request = SingleCallByTtsRequest.build(TeaConverter.buildMap( // 被叫号码。仅支持中国内地号码。一次请求仅支持一个被叫号。 new TeaPair("calledNumber", telephone), // 显号(选择公共池的号码,该字段为空) new TeaPair("calledShowNumber", ""), // 语音文件的语音ID。 new TeaPair("ttsCode", tstCode), // 设置参数 new TeaPair("ttsParam", ttsParam), // 设置语速(-500~500) new TeaPair("speed", 10), // 设置播放次数 new TeaPair("playTimes", 2) )); SingleCallByTtsResponse response = client.singleCallByTts(request); return response; } catch (Exception e) { e.printStackTrace(); } return null; }

  
- main方法测试

public static void main(String[] args) { JsonObject json = new JsonObject(); json.addProperty("xxx", "xxx"); try {

        SingleCallByTtsResponse response = noticeByVoice("xx", "xxx", json.toString());
        System.out.println(response.callId);
        System.out.println(new Gson().toJson(response));
    } catch (Exception e) {
        e.printStackTrace();
    }
}  

- 调用保存
  ![image.png](https://ucc.alicdn.com/pic/developer-ecology/40d64a4299084b51ad05d77717274082.png)

展开
收起
游客bvxvcc66yhnfo 2020-10-09 09:26:53 2364 0
0 条回答
写回答
取消 提交回答
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载