|
@@ -1,5 +1,6 @@
|
|
|
package com.slibra.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.aliyuncs.CommonRequest;
|
|
|
import com.aliyuncs.CommonResponse;
|
|
@@ -24,6 +25,7 @@ public class File2Text {
|
|
|
public static final String KEY_FILE_LINK = "file_link";
|
|
|
public static final String KEY_VERSION = "version";
|
|
|
public static final String KEY_ENABLE_WORDS = "enable_words";
|
|
|
+ public static final String AUTO_SPLIT = "auto_split";
|
|
|
// 响应参数
|
|
|
public static final String KEY_TASK = "Task";
|
|
|
public static final String KEY_TASK_ID = "TaskId";
|
|
@@ -71,6 +73,7 @@ public class File2Text {
|
|
|
taskObject.put(KEY_VERSION, "4.0");
|
|
|
// 设置是否输出词信息,默认为false,开启时需要设置version为4.0及以上。
|
|
|
taskObject.put(KEY_ENABLE_WORDS, true);
|
|
|
+ taskObject.put(AUTO_SPLIT, true);
|
|
|
String task = taskObject.toJSONString();
|
|
|
System.out.println(task);
|
|
|
// 设置以上JSON字符串为Body参数。
|
|
@@ -157,7 +160,8 @@ public class File2Text {
|
|
|
final String accessKeyId = "LTAI5tQ2HmiHCygZkt5BYrYR";
|
|
|
final String accessKeySecret = "KhmxTd14SUcXafpFk5yofA43FoeM99";
|
|
|
final String appKey = "OKt6jogp6fRjHQVp";
|
|
|
- String fileLink = "https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav";
|
|
|
+// String fileLink = "https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav";
|
|
|
+ String fileLink = "https://static.fuxicarbon.com/test/234527-I-0168-15765398611-S.wav";
|
|
|
// String fileLink = "https://www.w3school.com.cn/i/audio/song.mp3";
|
|
|
File2Text demo = new File2Text(accessKeyId, accessKeySecret);
|
|
|
// 第一步:提交录音文件识别请求,获取任务ID用于后续的识别结果轮询。
|
|
@@ -173,6 +177,8 @@ public class File2Text {
|
|
|
String result = demo.getFileTransResult(taskId);
|
|
|
if (result != null) {
|
|
|
System.out.println("录音文件识别结果查询成功:" + result);
|
|
|
+ String sentences = JSON.parseObject(result).get("Sentences").toString();
|
|
|
+ System.out.println(sentences);
|
|
|
}
|
|
|
else {
|
|
|
System.out.println("录音文件识别结果查询失败!");
|