|
@@ -263,5 +263,43 @@ public class CertificateManagementInfoServiceImpl implements ICertificateManagem
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DistinguishView speechRecognition(String voiceMessage) throws ServiceException {
|
|
|
+ String host = "https://audio.market.alicloudapi.com";
|
|
|
+ String path = "/audioshort";
|
|
|
+ String method = "POST";
|
|
|
+ String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
|
|
+ headers.put("Authorization", "APPCODE " + appcode);
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
+ Map<String, String> querys = new HashMap<String, String>();
|
|
|
+ Map<String, String> bodys = new HashMap<String, String>();
|
|
|
+ bodys.put("format", "m4a");
|
|
|
+ bodys.put("src", voiceMessage);
|
|
|
+ bodys.put("type", "zh-fast");
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
|
|
+ String body = EntityUtils.toString(response.getEntity());
|
|
|
+ System.out.println(body);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("msg");
|
|
|
+ DistinguishView distinguishView = new DistinguishView();
|
|
|
+ if(jsonArray!= null && jsonArray.size() >0){
|
|
|
+ String text = jsonArray.getString(0).replace("。","");
|
|
|
+ distinguishView.setText(text);
|
|
|
+ System.out.println(text);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ distinguishView.setText("未识别成功!");
|
|
|
+ }
|
|
|
+ return distinguishView;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|