mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 21:52:07 +08:00
生产工序代码-语音参数-代码修改
This commit is contained in:
+6
-2
@@ -28,17 +28,21 @@ public class VoiceController {
|
|||||||
private VoiceService voiceService;
|
private VoiceService voiceService;
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/")
|
@PostMapping()
|
||||||
@Operation(summary = "语音播报")
|
@Operation(summary = "语音播报")
|
||||||
@PreAuthorize("@ss.hasPermission('manage:voice:insert')")
|
@PreAuthorize("@ss.hasPermission('manage:voice:insert')")
|
||||||
public CommonResult<String> voiceAnnouncements(@Valid @RequestBody VoiceReqVO reqVO ) throws Exception {
|
public CommonResult<String> voiceAnnouncements(@Valid @RequestBody VoiceReqVO reqVO ) throws Exception {
|
||||||
|
|
||||||
String sourceFile = voiceService.voiceAnnouncements(reqVO.getText());
|
String sourceFile = voiceService.voiceAnnouncements(reqVO.getData());
|
||||||
|
|
||||||
String gzipFile = sourceFile+".zip";
|
String gzipFile = sourceFile+".zip";
|
||||||
|
|
||||||
|
// 压缩语音文件
|
||||||
voiceService.zipFiles(sourceFile, gzipFile);
|
voiceService.zipFiles(sourceFile, gzipFile);
|
||||||
|
|
||||||
|
// 删除生成的 mp3 文件
|
||||||
|
voiceService.deleteFiles(sourceFile);
|
||||||
|
|
||||||
return CommonResult.success(gzipFile);
|
return CommonResult.success(gzipFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -15,5 +15,6 @@ public class VoiceReqVO {
|
|||||||
|
|
||||||
|
|
||||||
@Schema(description = "语音数据", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "语音数据", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private String text;
|
private String data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -7,10 +7,11 @@ public interface VoiceService {
|
|||||||
|
|
||||||
|
|
||||||
// 生成音频文件
|
// 生成音频文件
|
||||||
String voiceAnnouncements(String text);
|
String voiceAnnouncements(String data);
|
||||||
|
|
||||||
|
|
||||||
// 把生成的音频文件进行压缩
|
// 把生成的音频文件进行压缩
|
||||||
void zipFiles(String sourceFile, String gzipFile) throws IOException;
|
void zipFiles(String sourceFile, String gzipFile) throws IOException;
|
||||||
|
|
||||||
|
void deleteFiles(String sourceFile);
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-3
@@ -33,11 +33,15 @@ public class VoiceServiceImpl implements VoiceService{
|
|||||||
private VocieParameters vocieParameters;
|
private VocieParameters vocieParameters;
|
||||||
|
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.loadLibrary("jacob-1.18-x64");
|
||||||
|
}
|
||||||
|
|
||||||
// 生成音频文件
|
// 生成音频文件
|
||||||
@Override
|
@Override
|
||||||
public String voiceAnnouncements(String text) {
|
public String voiceAnnouncements(String data) {
|
||||||
//
|
|
||||||
|
|
||||||
// 音频保存的路径
|
// 音频保存的路径
|
||||||
String path = vocieParameters.getPath();
|
String path = vocieParameters.getPath();
|
||||||
|
|
||||||
@@ -80,7 +84,7 @@ public class VoiceServiceImpl implements VoiceService{
|
|||||||
// 设置朗读速度 -10 ~ +10
|
// 设置朗读速度 -10 ~ +10
|
||||||
Dispatch.put(spVoice, "Rate", new Variant(readingSpeed));
|
Dispatch.put(spVoice, "Rate", new Variant(readingSpeed));
|
||||||
|
|
||||||
Dispatch.call(spVoice, "Speak", new Variant(text));
|
Dispatch.call(spVoice, "Speak", new Variant(data));
|
||||||
|
|
||||||
System.out.println("输出语音文件成功!");
|
System.out.println("输出语音文件成功!");
|
||||||
|
|
||||||
@@ -132,6 +136,7 @@ public class VoiceServiceImpl implements VoiceService{
|
|||||||
|
|
||||||
System.out.println("文件压缩成功");
|
System.out.println("文件压缩成功");
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("batchZipFiles error fileNames:");
|
log.error("batchZipFiles error fileNames:");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -142,9 +147,34 @@ public class VoiceServiceImpl implements VoiceService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 删除生成的 mp3 文件
|
||||||
|
@Override
|
||||||
|
public void deleteFiles(String sourceFile) {
|
||||||
|
|
||||||
|
// 检查文件路径是否为空
|
||||||
|
if (sourceFile == null || sourceFile.isEmpty()) {
|
||||||
|
System.out.println("文件路径为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(sourceFile);
|
||||||
|
|
||||||
|
// 检查文件是否存在
|
||||||
|
if (!file.exists()) {
|
||||||
|
System.out.println("文件不存在:" + sourceFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否是文件
|
||||||
|
if (!file.isFile()) {
|
||||||
|
System.out.println("路径指向的不是文件:" + sourceFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试删除文件
|
||||||
|
if (file.delete()) {
|
||||||
|
System.out.println("文件删除成功:" + sourceFile);
|
||||||
|
} else {
|
||||||
|
System.out.println("文件删除失败:" + sourceFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ spring:
|
|||||||
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
|
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
|
||||||
config:
|
config:
|
||||||
server-addr: 192.168.1.205:8848 # Nacos 服务器地址
|
server-addr: 192.168.1.205:8848 # Nacos 服务器地址
|
||||||
namespace: dev # 命名空间 dev 的ID,不能直接使用 dev 名称。创建命名空间的时候需要指定ID为 dev,这里使用 dev 开发环境
|
namespace: # 命名空间 dev 的ID,不能直接使用 dev 名称。创建命名空间的时候需要指定ID为 dev,这里使用 dev 开发环境
|
||||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||||
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
|
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
|
||||||
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
|
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ spring:
|
|||||||
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
|
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
|
||||||
config:
|
config:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||||
namespace: dev # 命名空间 dev 的ID,不能直接使用 dev 名称。创建命名空间的时候需要指定ID为 dev,这里使用 dev 开发环境
|
namespace: # 命名空间 dev 的ID,不能直接使用 dev 名称。创建命名空间的时候需要指定ID为 dev,这里使用 dev 开发环境
|
||||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||||
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
|
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
|
||||||
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
|
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
|
||||||
|
|||||||
Reference in New Issue
Block a user