fix xf oss read bug

This commit is contained in:
ran.shang
2025-08-15 14:17:10 +08:00
parent 8f44d802db
commit bff0f19500
2 changed files with 68 additions and 23 deletions

View File

@@ -33,18 +33,18 @@ public class XfUtils {
private static XfProperties xfProperties;
private static FileService fileService;
private static FileRecordService fileRecordService;
XfUtils(ConfigService configService, XfProperties xfProperties, FileService fileService, FileRecordService fileRecordService){
XfUtils.configService = configService;
XfUtils.xfProperties = xfProperties;
XfUtils.fileService = fileService;
XfUtils.fileRecordService = fileRecordService;
}
/**
* 生成面试问题
* @return InterviewContentDTO json
* @author sr on 2024-12-10
* @author sr on 2024-12-10
*/
public static String generateInterviewQuestion(InterviewContentDTO content) {
ChatReq req = ChatReq.builder()
@@ -58,11 +58,11 @@ public class XfUtils {
Assert.isTrue(result.getSuccess(), result.getMsg());
return result.getData();
}
/**
* 评分面试
* @return InterviewContentDTO json
* @author sr on 2024-12-10
* @author sr on 2024-12-10
*/
public static String gradeInterview(InterviewContentDTO content) {
ChatReq req = ChatReq.builder()
@@ -76,11 +76,11 @@ public class XfUtils {
Assert.isTrue(result.getSuccess(), result.getMsg());
return result.getData();
}
/**
* 生成简历
* @return
* @author sr on 2024-12-10
* @author sr on 2024-12-10
*/
public static String generateResume(String content) {
String key01 = configService.getConfigValue("ai_jianli_key01", CommonConstants.PLATFORM_ORG_ID, true);
@@ -98,28 +98,36 @@ public class XfUtils {
Assert.isTrue(result.getSuccess(), result.getMsg());
return result.getData();
}
/**
* 语音听写
* @param fileCode
* @return
* @author sr on 2025-01-09
* @author sr on 2025-01-09
*/
public static String iat(String fileCode) {
try (InputStream is = fileRecordService.getFile(fileCode)){
AlitaResult<String> result = WebIATWS.execute(is, xfProperties);
Assert.isTrue(result.getSuccess(), result.getMsg());
return result.getData();
try (InputStream fileis = fileRecordService.getFile(fileCode)){
File file = FileUtils.createTempFile("pcm");
try (InputStream is = FileUtils.copyToTempFile(fileis, file)) {
AlitaResult<String> result = WebIATWS.execute(is, xfProperties);
Assert.isTrue(result.getSuccess(), result.getMsg());
return result.getData();
} catch (Exception e) {
throw e;
} finally {
file.deleteOnExit();
}
} catch (Exception e) {
throw new BusinessException("语音听写异常:" + e.getMessage());
}
}
/**
* 语音合成
* @return
* @author sr on 2025-01-09
* @author sr on 2025-01-09
*/
public static String tts(String text) {
try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()){
@@ -258,11 +266,18 @@ public class XfUtils {
* @return
*/
public static String rtasr(RtasrReqDTO reqDTO) {
try (InputStream is = fileRecordService.getFile(reqDTO.getFileCode())){
AlitaResult<String> result = RtasrClientApp.execute(is, reqDTO.getFrom(), xfProperties);
Assert.isTrue(result.getSuccess(), result.getMsg());
return result.getData();
} catch (Exception e) {
try (InputStream fileis = fileRecordService.getFile(reqDTO.getFileCode())){
File file = FileUtils.createTempFile("pcm");
try (InputStream is = FileUtils.copyToTempFile(fileis, file)) {
AlitaResult<String> result = RtasrClientApp.execute(is, reqDTO.getFrom(), xfProperties);
Assert.isTrue(result.getSuccess(), result.getMsg());
return result.getData();
} catch (Exception e) {
throw e;
} finally {
file.deleteOnExit();
}
}catch (Exception e) {
throw new BusinessException("语音听写异常:" + e.getMessage());
}