文本转音频
//appId, keySecret, host 为讯飞相关配置项
try {
String result = upload(url, appId, keySecret, host);
String jsonStr = StringEscapeUtils.unescapeJavaScript(result);
String orderId = String.valueOf(JSONUtil.getByPath(JSONUtil.parse(jsonStr), "content.orderId"));
String convert = getResult(orderId, url);
return convert;
} catch (IOException | SignatureException | InterruptedException e) {
e.printStackTrace();
throw new CompletionException(e);
}
private String upload(String filePath, String appid, String keySecret, String host) throws IOException, SignatureException {
HashMap<String, Object> map = new HashMap<>(16);
HttpURLConnection urlConnection = FileReaderUtil.getUrlConnection(filePath);
String fileName = FileUtils.getName(filePath);
long fileSize = urlConnection.getContentLengthLong();
map.put("appId", appid);
map.put("fileSize", fileSize);
map.put("fileName", fileName);
map.put("duration", "200");
LfasrSignature lfasrSignature = new LfasrSignature(appid, keySecret);
map.put("signa", lfasrSignature.getSigna());
map.put("ts", lfasrSignature.getTs());
String paramString = XunfeiHttpUtil.parseMapToPathParam(map);
System.out.println("upload paramString:" + paramString);
String url = host + "/v2/api/upload" + "?" + paramString;
System.out.println("upload_url:" + url);
String response = XunfeiHttpUtil.iflyrecUpload(url, urlConnection.getInputStream());
return response;
}
private String getResult(String orderId, String fileName) throws SignatureException, InterruptedException, IOException {
HashMap<String, Object> map = new HashMap<>(16);
map.put("orderId", orderId);
LfasrSignature lfasrSignature = new LfasrSignature(appId, keySecret);
map.put("signa", lfasrSignature.getSigna());
map.put("ts", lfasrSignature.getTs());
map.put("appId", appId);
map.put("resultType",