|
|
@@ -28,6 +28,7 @@ import org.ruoyi.common.core.utils.DateUtils;
|
|
|
import org.ruoyi.common.core.utils.StringUtils;
|
|
|
import org.ruoyi.common.core.utils.file.FileUtils;
|
|
|
import org.ruoyi.common.core.utils.file.MimeTypeUtils;
|
|
|
+import com.github.houbb.opencc4j.util.ZhConverterUtil;
|
|
|
import org.ruoyi.common.satoken.utils.LoginHelper;
|
|
|
import org.ruoyi.common.core.service.ConfigService;
|
|
|
import org.ruoyi.core.page.PageQuery;
|
|
|
@@ -111,7 +112,7 @@ public class SseServiceImpl implements ISseService {
|
|
|
|
|
|
private String rerankModelName = "bge-reranker-v2-m3";
|
|
|
|
|
|
- private static final String DEFAULT_TTS_PROXY_URL = "http://1.13.255.120:7899/v1/audio/speech";
|
|
|
+ private static final String DEFAULT_TTS_PROXY_URL = "http://8.136.61.90:7899/v1/audio/speech";
|
|
|
private static final String DEFAULT_TTS_VOICE = "zh-CN-XiaoxiaoNeural";
|
|
|
|
|
|
@Override
|
|
|
@@ -460,8 +461,26 @@ public class SseServiceImpl implements ISseService {
|
|
|
}
|
|
|
Transcriptions transcriptions = Transcriptions.builder()
|
|
|
.model(resolveAudioModel())
|
|
|
+ .language(resolveAudioLanguage())
|
|
|
+ .prompt(resolveAudioPrompt())
|
|
|
.build();
|
|
|
- return openAiStreamClient.speechToTextTranscriptions(fileA, transcriptions);
|
|
|
+
|
|
|
+ log.info("语音转文本API调用参数 - 模型: {}, 语言: {}, 提示词: {}",
|
|
|
+ transcriptions.getModel(), transcriptions.getLanguage(), transcriptions.getPrompt());
|
|
|
+
|
|
|
+ WhisperResponse response = openAiStreamClient.speechToTextTranscriptions(fileA, transcriptions);
|
|
|
+
|
|
|
+ // 转换繁体为简体
|
|
|
+ if (response != null && response.getText() != null) {
|
|
|
+ String originalText = response.getText();
|
|
|
+ String convertedText = convertToSimplifiedChinese(originalText);
|
|
|
+ if (!convertedText.equals(originalText)) {
|
|
|
+ log.info("语音转文本检测到繁体中文,已转换为简体 - 原文本: {}, 转换后: {}", originalText, convertedText);
|
|
|
+ response.setText(convertedText);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
private String resolveAudioModel() {
|
|
|
@@ -477,6 +496,31 @@ public class SseServiceImpl implements ISseService {
|
|
|
return defaultModel;
|
|
|
}
|
|
|
|
|
|
+ private String resolveAudioLanguage() {
|
|
|
+ String defaultLanguage = "mandarin"; // 使用API支持的语言名称
|
|
|
+ try {
|
|
|
+ String audioLanguage = configService.getConfigValue("chat", "audioLanguage");
|
|
|
+ if (StringUtils.isNotBlank(audioLanguage)) {
|
|
|
+ return audioLanguage;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("音频语言配置获取失败,使用默认语言 {} :{}", defaultLanguage, e.getMessage());
|
|
|
+ }
|
|
|
+ return defaultLanguage;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String resolveAudioPrompt() {
|
|
|
+ String defaultPrompt = "请将语音转换为简体中文。使用现代标准汉语,避免繁体字。"; // 引导输出简体中文
|
|
|
+ try {
|
|
|
+ String audioPrompt = configService.getConfigValue("chat", "audioPrompt");
|
|
|
+ if (StringUtils.isNotBlank(audioPrompt)) {
|
|
|
+ return audioPrompt;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("音频提示词配置获取失败,使用默认提示词:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ return defaultPrompt;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public UploadFileResponse upload(MultipartFile file) {
|
|
|
@@ -759,4 +803,24 @@ public class SseServiceImpl implements ISseService {
|
|
|
return thinkProjectMapper.insertProject(map);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将繁体中文转换为简体中文
|
|
|
+ * 使用opencc4j库进行专业的简繁转换
|
|
|
+ * @param text 输入文本
|
|
|
+ * @return 转换后的简体中文文本
|
|
|
+ */
|
|
|
+ private String convertToSimplifiedChinese(String text) {
|
|
|
+ if (text == null || text.isEmpty()) {
|
|
|
+ return text;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用opencc4j进行繁体到简体的转换
|
|
|
+ return ZhConverterUtil.toSimple(text);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("语音转文本简繁转换失败,使用原文: {}", e.getMessage());
|
|
|
+ return text;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|