Browse Source

chore: Audio Handle

master
wangxiang 2 years ago
parent
commit
4d2efc0d05
No known key found for this signature in database
GPG Key ID: 1BA7946AB6B232E4
  1. 5
      kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/config/OpenAiConfigProperties.java
  2. 6
      kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/ImContentServiceImpl.java

5
kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/config/OpenAiConfigProperties.java

@ -36,6 +36,9 @@ public class OpenAiConfigProperties { @@ -36,6 +36,9 @@ public class OpenAiConfigProperties {
private int timeout = 10;
/** OpenAI API Voice - <a href="https://platform.openai.com/docs/guides/text-to-speech/voice-options">...</a> */
private String voice;
private String voice = "alloy";
/** OpenAI API Speed - <a href="https://platform.openai.com/docs/api-reference/audio/createSpeech">...</a> */
private Double speed = 1.0;
}

6
kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/ImContentServiceImpl.java

@ -96,8 +96,8 @@ public class ImContentServiceImpl extends ServiceImpl<ImContentMapper, ImContent @@ -96,8 +96,8 @@ public class ImContentServiceImpl extends ServiceImpl<ImContentMapper, ImContent
fileService.save(sendOssOssFile);
imContent.setFiles(sendOssOssFile.getId());
File inputVoiceFile = File.createTempFile(sendFileName, StrUtil.DOT + FileUtil.extName(file.getOriginalFilename()));
File outputVoiceFile = File.createTempFile(sendFileName, StrUtil.DOT + FileUtil.extName(file.getOriginalFilename()));
File inputVoiceFile = File.createTempFile(FileUtil.getPrefix(file.getOriginalFilename()), StrUtil.DOT + FileUtil.extName(file.getOriginalFilename()));
File outputVoiceFile = File.createTempFile(FileUtil.getPrefix(speechName), StrUtil.DOT + FileUtil.extName(speechName));
ImContent receiveContent;
OssFile receiveOssOssFile;
try {
@ -121,7 +121,7 @@ public class ImContentServiceImpl extends ServiceImpl<ImContentMapper, ImContent @@ -121,7 +121,7 @@ public class ImContentServiceImpl extends ServiceImpl<ImContentMapper, ImContent
.input(receiveContent.getContent())
.voice(openAiConfigProperties.getVoice())
.responseFormat(FileUtil.extName(speechName))
.speed(1.0)
.speed(openAiConfigProperties.getSpeed())
.build();
ResponseBody responseBody = openAiService.createSpeech(createSpeechRequest);
FileUtil.writeBytes(responseBody.bytes(), outputVoiceFile);

Loading…
Cancel
Save