前端-胡立永 1 month ago
parent
commit
18b226789a
8 changed files with 221 additions and 76 deletions
  1. +31
    -1
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiBooksController.java
  2. +2
    -5
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java
  3. +1
    -8
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java
  4. +46
    -31
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java
  5. +6
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiBooksService.java
  6. +2
    -2
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiTTService.java
  7. +18
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiBooksServiceImpl.java
  8. +115
    -29
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java

+ 31
- 1
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiBooksController.java View File

@ -12,6 +12,7 @@ import org.jeecg.modules.demo.appletBookStand.entity.AppletBookStand;
import org.jeecg.modules.demo.appletBooks.entity.AppletBooks;
import org.jeecg.modules.demo.appletCategorize.entity.AppletCategorize;
import org.jeecg.modules.demo.appletCourse.entity.AppletCourse;
import org.jeecg.modules.demo.appletLabel.entity.AppletLabel;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
@ -54,6 +55,35 @@ public class AppletApiBooksController {
return Result.OK(list);
}
/**
* 查询书籍标签
*
* @return 查询书籍标签
*/
@Operation(summary = "查询书籍标签", description = "查询书籍标签")
@GetMapping(value = "/label")
@IgnoreAuth
public Result<List<AppletLabel>> label() {
log.info("查询书籍标签");
List<AppletLabel> list = appletApiBooksService.getLabel();
return Result.OK(list);
}
/**
* 查询书籍分类
*
* @return 查询书籍分类
*/
@Operation(summary = "查询书籍分类", description = "查询书籍分类")
@GetMapping(value = "/category")
@IgnoreAuth
public Result<List<AppletCategorize>> category() {
log.info("查询书籍标签");
List<AppletCategorize> list = appletApiBooksService.category();
return Result.OK(list);
}
/**
* 查询书桌列表
@ -90,6 +120,7 @@ public class AppletApiBooksController {
*
* @return 删除书桌
*/
@IgnoreAuth
@Operation(summary = "删除书桌", description = "删除书桌,批量删除用,分割")
@PostMapping(value = "/delStand")
public Result<?> delStand(@Parameter(description = "书籍id") String id) {
@ -97,7 +128,6 @@ public class AppletApiBooksController {
return Result.OK();
}
//TODO 需删除 @IgnoreAuth
@IgnoreAuth
@Operation(summary = "获取课程列表", description = "根据书籍id获取课程列表")
@GetMapping(value = "/course")


+ 2
- 5
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java View File

@ -14,6 +14,7 @@ import org.jeecg.modules.demo.appletLink.entity.AppletLink;
import org.jeecg.modules.demo.appletRegistration.entity.AppletRegistration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -52,27 +53,23 @@ public class AppletApiIndexController {
@IgnoreAuth
@Operation(summary = "首页底部内容链接", description = "首页底部内容链接")
@GetMapping(value = "/link")
public Result<List<AppletLink>> link() {
log.info("查询首页底部内容链接");
List<AppletLink> list = appletApiIndexService.getLink();
return Result.OK(list);
}
@IgnoreAuth
@Operation(summary = "首页底部内容链接详情", description = "首页底部内容链接详情")
@GetMapping(value = "/linkDetails")
public Result<AppletLink> linkDetails(@Parameter(description = "链接id") String id) {
log.info("查询首页底部内容链接详情");
AppletLink deta = appletApiIndexService.linkDetails(id);
return Result.OK(deta);
}
@Operation(summary = "首页底部内容添加报名", description = "首页底部内容添加报名")
@GetMapping(value = "/linkSignup")
@PostMapping(value = "/linkSignup")
public Result<AppletRegistration> linkSignup(AppletRegistration appletRegistration) {
log.info("首页底部内容添加报名");
appletApiIndexService.linkSignup(appletRegistration);


+ 1
- 8
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java View File

@ -9,10 +9,8 @@ import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.applet.service.AppletApiCouponService;
import org.jeecg.modules.applet.service.AppletApiVipService;
import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon;
import org.jeecg.modules.demo.appletCoupon.service.IAppletCouponService;
import org.jeecg.modules.demo.appletMemberOrder.entity.AppletMemberOrder;
import org.jeecg.modules.demo.appletVip.entity.AppletVip;
import org.jeecg.modules.demo.appletVip.service.IAppletVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -49,18 +47,13 @@ public class AppletApiMemberController {
}
@IgnoreAuth
@PostMapping("/payNotify")
public Object payNotify(@RequestBody String requestBody) {
//1添加流水
//2修改订单状态已支付
return appletApiVipService.payNotify(requestBody);
}
@IgnoreAuth
@Operation(summary = "获取优惠劵", description = "获取优惠劵")
@GetMapping(value = "/coupon")
public Result<List<AppletCoupon>> coupon(AppletCoupon appletCoupon) {


+ 46
- 31
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java View File

@ -35,7 +35,49 @@ public class AppletApiTTSController {
@Operation(summary = "文字转语音", description = "文字转语音")
@PostMapping(value = "/textToVoice")
@IgnoreAuth
public ResponseEntity<byte[]> textToVoice(
// public ResponseEntity<byte[]> textToVoice(
// @Parameter(description = "要转换的文本内容", required = true) String text,
// @Parameter(description = "语速,范围:[-2,6],默认为0-2代表0.6倍\n" +
// "-1代表0.8倍\n" +
// "0代表1.0倍(默认)\n" +
// "1代表1.2倍\n" +
// "2代表1.5倍\n" +
// "6代表2.5倍") Float speed,
// @Parameter(description = "音色ID,默认为0") Integer voiceType,
// @Parameter(description = "音量大小,范围[-10,10],默认为0") Float volume,
// @Parameter(description = "返回音频格式,可取值:wav(默认),mp3,pcm") String codec) {
//
// try {
// byte[] audioData = appletApiTTService.textToVoice(text, speed, voiceType, volume, codec, null);
//
// if (audioData == null || audioData.length == 0) {
// return ResponseEntity.noContent().build();
// }
//
// // 根据codec设置对应的Content-Type
// MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
// if ("wav".equalsIgnoreCase(codec)) {
// mediaType = MediaType.parseMediaType("audio/wav");
// } else if ("mp3".equalsIgnoreCase(codec)) {
// mediaType = MediaType.parseMediaType("audio/mpeg");
// } else if ("pcm".equalsIgnoreCase(codec)) {
// mediaType = MediaType.parseMediaType("audio/pcm");
// }
//
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(mediaType);
// headers.setContentLength(audioData.length);
//
// return ResponseEntity.ok()
// .headers(headers)
// .body(audioData);
//
// } catch (Exception e) {
// log.error("文字转语音失败: {}", e.getMessage(), e);
// return ResponseEntity.internalServerError().build();
// }
// }
public Result textToVoice(
@Parameter(description = "要转换的文本内容", required = true) String text,
@Parameter(description = "语速,范围:[-2,6],默认为0-2代表0.6倍\n" +
"-1代表0.8倍\n" +
@ -46,36 +88,9 @@ public class AppletApiTTSController {
@Parameter(description = "音色ID,默认为0") Integer voiceType,
@Parameter(description = "音量大小,范围[-10,10],默认为0") Float volume,
@Parameter(description = "返回音频格式,可取值:wav(默认),mp3,pcm") String codec) {
try {
byte[] audioData = appletApiTTService.textToVoice(text, speed, voiceType, volume, codec, null);
if (audioData == null || audioData.length == 0) {
return ResponseEntity.noContent().build();
}
// 根据codec设置对应的Content-Type
MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
if ("wav".equalsIgnoreCase(codec)) {
mediaType = MediaType.parseMediaType("audio/wav");
} else if ("mp3".equalsIgnoreCase(codec)) {
mediaType = MediaType.parseMediaType("audio/mpeg");
} else if ("pcm".equalsIgnoreCase(codec)) {
mediaType = MediaType.parseMediaType("audio/pcm");
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(mediaType);
headers.setContentLength(audioData.length);
return ResponseEntity.ok()
.headers(headers)
.body(audioData);
} catch (Exception e) {
log.error("文字转语音失败: {}", e.getMessage(), e);
return ResponseEntity.internalServerError().build();
}
String audioData = appletApiTTService.textToVoice(text, speed, voiceType, volume, codec);
return Result.ok(audioData);
}
}

+ 6
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiBooksService.java View File

@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.appletBookStand.entity.AppletBookStand;
import org.jeecg.modules.demo.appletBooks.entity.AppletBooks;
import org.jeecg.modules.demo.appletCategorize.entity.AppletCategorize;
import org.jeecg.modules.demo.appletCourse.entity.AppletCourse;
import org.jeecg.modules.demo.appletLabel.entity.AppletLabel;
import java.util.List;
@ -44,4 +46,8 @@ public interface AppletApiBooksService {
* @return
*/
IPage<AppletCourse> getCourses(Page<AppletCourse> coursePage, String id);
List<AppletLabel> getLabel();
List<AppletCategorize> category();
}

+ 2
- 2
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiTTService.java View File

@ -14,7 +14,7 @@ public interface AppletApiTTService {
* @param codec 返回音频格式可取值wav默认mp3pcm
* @return 音频二进制数据
*/
byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec);
String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec);
/**
* 文字转语音带用户ID记录日志
@ -26,7 +26,7 @@ public interface AppletApiTTService {
* @param userId 用户ID用于记录日志
* @return 音频二进制数据
*/
byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId);
String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId);
List<AppletTtsTimbre> list();
}

+ 18
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiBooksServiceImpl.java View File

@ -13,8 +13,12 @@ import org.jeecg.modules.demo.appletBookStand.entity.AppletBookStand;
import org.jeecg.modules.demo.appletBookStand.service.IAppletBookStandService;
import org.jeecg.modules.demo.appletBooks.entity.AppletBooks;
import org.jeecg.modules.demo.appletBooks.service.IAppletBooksService;
import org.jeecg.modules.demo.appletCategorize.entity.AppletCategorize;
import org.jeecg.modules.demo.appletCategorize.service.IAppletCategorizeService;
import org.jeecg.modules.demo.appletCourse.entity.AppletCourse;
import org.jeecg.modules.demo.appletCourse.service.IAppletCourseService;
import org.jeecg.modules.demo.appletLabel.entity.AppletLabel;
import org.jeecg.modules.demo.appletLabel.service.IAppletLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -31,6 +35,10 @@ public class AppletApiBooksServiceImpl implements AppletApiBooksService {
private IAppletBookStandService appletBookStandService;
@Autowired
private IAppletCourseService appletCourseService;
@Autowired
private IAppletLabelService appletLabelService;
@Autowired
private IAppletCategorizeService appletCategorizeService;
/**
* 查询书籍列表
@ -139,4 +147,14 @@ public class AppletApiBooksServiceImpl implements AppletApiBooksService {
return pageResult;
}
@Override
public List<AppletLabel> getLabel() {
return appletLabelService.list();
}
@Override
public List<AppletCategorize> category() {
return appletCategorizeService.list();
}
}

+ 115
- 29
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java View File

@ -34,35 +34,124 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
private IAppletTtsPlayLogService appletTtsPlayLogService;
@Override
public byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec) {
public String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec) {
return textToVoice(text, speed, voiceType, volume, codec, null);
}
public byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId) {
// public byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId) {
// long startTime = System.currentTimeMillis();
//
// try {
// // 创建认证对象
// Credential cred = new Credential(secretId, secretKey);
//
// // 实例化一个http选项可选的没有特殊需求可以跳过
// HttpProfile httpProfile = new HttpProfile();
// httpProfile.setEndpoint("tts.tencentcloudapi.com");
//
// // 实例化一个client选项可选的没有特殊需求可以跳过
// ClientProfile clientProfile = new ClientProfile();
// clientProfile.setHttpProfile(httpProfile);
//
// // 实例化要请求产品的client对象
// TtsClient client = new TtsClient(cred, "", clientProfile);
//
// // 实例化一个请求对象
// TextToVoiceRequest req = new TextToVoiceRequest();
//
// // 设置必填参数
// req.setText(text);
// req.setSessionId(UUID.randomUUID().toString());
//
// // 设置可选参数
// if (speed != null) {
// req.setSpeed(speed);
// }
// if (voiceType != null) {
// req.setVoiceType(voiceType.longValue());
// }
// if (volume != null) {
// req.setVolume(volume);
// }
// if (codec != null && !codec.isEmpty()) {
// req.setCodec(codec);
// } else {
// req.setCodec("wav"); // 默认wav格式
// }
//
// // 设置其他默认参数
// req.setModelType(1L); // 默认模型
// req.setPrimaryLanguage(2L); // 中文
// req.setSampleRate(16000L); // 16k采样率
//
// // 返回的resp是一个TextToVoiceResponse的实例与请求对象对应
// TextToVoiceResponse resp = client.TextToVoice(req);
//
// // 计算耗时
// long endTime = System.currentTimeMillis();
// double elapsedTime = (endTime - startTime) / 1000.0;
//
// // 获取base64编码的音频数据并解码为二进制
// String audioBase64 = resp.getAudio();
// byte[] audioData = null;
//
// if (audioBase64 != null && !audioBase64.isEmpty()) {
// audioData = java.util.Base64.getDecoder().decode(audioBase64);
//
// // 记录成功的TTS调用日志
// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
// speed != null ? speed.doubleValue() : null, elapsedTime, true);
//
// log.info("TTS调用成功,文本长度: {}, 耗时: {}秒", text != null ? text.length() : 0, elapsedTime);
// return audioData;
// } else {
// // 记录失败的TTS调用日志
// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
// speed != null ? speed.doubleValue() : null, elapsedTime, false);
//
// log.warn("TTS返回的音频数据为空");
// return null;
// }
//
// } catch (Exception e) {
// // 计算耗时
// long endTime = System.currentTimeMillis();
// double elapsedTime = (endTime - startTime) / 1000.0;
//
// // 记录失败的TTS调用日志
// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
// speed != null ? speed.doubleValue() : null, elapsedTime, false);
//
// log.error("调用腾讯云TTS接口失败: {}", e.getMessage(), e);
// return null;
// }
// }
public String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId) {
long startTime = System.currentTimeMillis();
try {
// 创建认证对象
Credential cred = new Credential(secretId, secretKey);
// 实例化一个http选项可选的没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("tts.tencentcloudapi.com");
// 实例化一个client选项可选的没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象
TtsClient client = new TtsClient(cred, "", clientProfile);
// 实例化一个请求对象
TextToVoiceRequest req = new TextToVoiceRequest();
// 设置必填参数
req.setText(text);
req.setSessionId(UUID.randomUUID().toString());
// 设置可选参数
if (speed != null) {
req.setSpeed(speed);
@ -78,50 +167,47 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
} else {
req.setCodec("wav"); // 默认wav格式
}
// 设置其他默认参数
req.setModelType(1L); // 默认模型
req.setPrimaryLanguage(2L); // 中文
req.setSampleRate(16000L); // 16k采样率
// 返回的resp是一个TextToVoiceResponse的实例与请求对象对应
TextToVoiceResponse resp = client.TextToVoice(req);
// 计算耗时
long endTime = System.currentTimeMillis();
double elapsedTime = (endTime - startTime) / 1000.0;
// 获取base64编码的音频数据并解码为二进制
String audioBase64 = resp.getAudio();
byte[] audioData = null;
if (audioBase64 != null && !audioBase64.isEmpty()) {
audioData = java.util.Base64.getDecoder().decode(audioBase64);
// 记录成功的TTS调用日志
savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
speed != null ? speed.doubleValue() : null, elapsedTime, true);
savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
speed != null ? speed.doubleValue() : null, elapsedTime, true);
log.info("TTS调用成功,文本长度: {}, 耗时: {}秒", text != null ? text.length() : 0, elapsedTime);
return audioData;
return audioBase64;
} else {
// 记录失败的TTS调用日志
savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
speed != null ? speed.doubleValue() : null, elapsedTime, false);
savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
speed != null ? speed.doubleValue() : null, elapsedTime, false);
log.warn("TTS返回的音频数据为空");
return null;
}
} catch (Exception e) {
// 计算耗时
long endTime = System.currentTimeMillis();
double elapsedTime = (endTime - startTime) / 1000.0;
// 记录失败的TTS调用日志
savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
speed != null ? speed.doubleValue() : null, elapsedTime, false);
savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
speed != null ? speed.doubleValue() : null, elapsedTime, false);
log.error("调用腾讯云TTS接口失败: {}", e.getMessage(), e);
return null;
}


Loading…
Cancel
Save