mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 05:42:06 +08:00
优化生产权限修改,新增空小板Bug修改
This commit is contained in:
+21
-5
@@ -4,8 +4,12 @@ package com.cf.imes.module.manage.controller.admin.voice;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.module.manage.controller.admin.voice.vo.VoiceReqVO;
|
||||
import com.cf.imes.module.manage.service.voice.VoiceService;
|
||||
import com.jacob.com.Dispatch;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -15,6 +19,8 @@ import javax.validation.Valid;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.sql.Blob;
|
||||
|
||||
|
||||
@Tag(name = "管理后台 - 语音播报")
|
||||
@@ -31,19 +37,29 @@ public class VoiceController {
|
||||
@PostMapping()
|
||||
@Operation(summary = "语音播报")
|
||||
@PreAuthorize("@ss.hasPermission('manage:voice:insert')")
|
||||
public CommonResult<String> voiceAnnouncements(@Valid @RequestBody VoiceReqVO reqVO ) throws Exception {
|
||||
public CommonResult<ResponseEntity<byte[]>> voiceAnnouncements(@Valid @RequestBody VoiceReqVO reqVO ) throws Exception {
|
||||
|
||||
|
||||
String sourceFile = voiceService.voiceAnnouncements(reqVO.getData());
|
||||
|
||||
String gzipFile = sourceFile+".zip";
|
||||
|
||||
// 压缩语音文件
|
||||
voiceService.zipFiles(sourceFile, gzipFile);
|
||||
ResponseEntity<byte[]> voice = voiceService.getVoice(sourceFile);
|
||||
|
||||
|
||||
// 删除生成的 mp3 文件
|
||||
voiceService.deleteFiles(sourceFile);
|
||||
|
||||
return CommonResult.success(gzipFile);
|
||||
|
||||
return CommonResult.success(voice);
|
||||
|
||||
// String gzipFile = sourceFile+".zip";
|
||||
//
|
||||
// // 压缩语音文件
|
||||
// voiceService.zipFiles(sourceFile, gzipFile);
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -1,17 +1,29 @@
|
||||
package com.cf.imes.module.manage.service.voice;
|
||||
|
||||
|
||||
import com.jacob.com.Dispatch;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Blob;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface VoiceService {
|
||||
|
||||
|
||||
// 生成音频文件
|
||||
String voiceAnnouncements(String data);
|
||||
|
||||
String voiceAnnouncements(String data) throws IOException, SQLException;
|
||||
|
||||
|
||||
// 把生成的音频文件进行压缩
|
||||
void zipFiles(String sourceFile, String gzipFile) throws IOException;
|
||||
|
||||
void deleteFiles(String sourceFile);
|
||||
|
||||
ResponseEntity<byte[]> getVoice(String sourceFile);
|
||||
|
||||
}
|
||||
|
||||
+70
-3
@@ -3,16 +3,36 @@ package com.cf.imes.module.manage.service.voice;
|
||||
|
||||
import com.cf.imes.module.manage.config.VocieParameters;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
import javax.sql.rowset.serial.SerialBlob;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Blob;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
@@ -23,6 +43,8 @@ import java.util.Random;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static org.aspectj.weaver.tools.cache.SimpleCacheFactory.path;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class VoiceServiceImpl implements VoiceService{
|
||||
@@ -31,11 +53,13 @@ public class VoiceServiceImpl implements VoiceService{
|
||||
private VocieParameters vocieParameters;
|
||||
|
||||
|
||||
|
||||
|
||||
// static {
|
||||
// System.loadLibrary("jacob-1.18-x64");
|
||||
// }
|
||||
|
||||
// 生成音频文件
|
||||
//生成音频文件
|
||||
@Override
|
||||
public String voiceAnnouncements(String data) {
|
||||
|
||||
@@ -106,6 +130,48 @@ public class VoiceServiceImpl implements VoiceService{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<byte[]> getVoice( String fileName) {
|
||||
try {
|
||||
File audioFile = new File(fileName);
|
||||
if (!audioFile.exists()) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||
}
|
||||
|
||||
// 读取文件到字节数组
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
try (FileInputStream fileInputStream = new FileInputStream(audioFile)) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
|
||||
byteArrayOutputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] audioBytes = byteArrayOutputStream.toByteArray();
|
||||
ByteArrayResource byteArrayResource = new ByteArrayResource(audioBytes);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.parseMediaType("audio/mpeg"));
|
||||
headers.setContentLength(audioBytes.length);
|
||||
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
||||
|
||||
return new ResponseEntity<>(audioBytes, headers, HttpStatus.OK);
|
||||
|
||||
} catch (IOException e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 把生成的音频文件进行压缩
|
||||
* @param fileNames 需要压缩的文件名称列表(包含相对路径)
|
||||
@@ -175,4 +241,5 @@ public class VoiceServiceImpl implements VoiceService{
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user