新增喊话模块,更新shp文件入库,对图片返回做去重处理
| | |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileEntity> MediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type) { |
| | | // 创建分页对象 |
| | | Page<MediaFileEntity> pageObj = new Page<>(page, pageSize); |
| | | |
| | | // 创建查询条件对象 |
| | | LambdaQueryWrapper<MediaFileEntity> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | |
| | | |
| | | if (jobName != null && !jobName.isEmpty()) { |
| | | List<String> jobIds = waylineJobService.getJobIds(jobName); |
| | | // 检查 jobIds 列表是否为空 |
| | | if (jobIds.isEmpty()) { |
| | | // 如果为空,则直接返回空的分页数据 |
| | | return new PaginationData<>(Collections.emptyList(), new Pagination(pageObj)); |
| | | return new PaginationData<>(Collections.emptyList(), new Pagination(new Page<>(page, pageSize))); |
| | | } |
| | | |
| | | queryWrapper.in(MediaFileEntity::getJobId, jobIds); |
| | | } |
| | | |
| | | if (type != null && !type.isEmpty()) { |
| | | if ("图片".equals(type)) { |
| | | queryWrapper.likeLeft(MediaFileEntity::getFileName, ".jpeg"); |
| | |
| | | queryWrapper.likeLeft(MediaFileEntity::getFileName, ".mp4"); |
| | | } |
| | | } |
| | | queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC"); |
| | | // 执行分页查询 |
| | | Page<MediaFileEntity> resultPage = mapper.selectPage(pageObj, queryWrapper); |
| | | |
| | | // 处理查询结果并去重 |
| | | queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC"); |
| | | |
| | | // 执行查询获取所有结果 |
| | | List<MediaFileEntity> allResults = mapper.selectList(queryWrapper); |
| | | |
| | | // 处理结果去重并设置任务名称 |
| | | Map<String, MediaFileEntity> uniqueFileMap = new LinkedHashMap<>(); |
| | | List<MediaFileEntity> records = resultPage.getRecords() |
| | | .stream() |
| | | List<MediaFileEntity> uniqueResults = allResults.stream() |
| | | .peek(mediaFile -> { |
| | | // 获取任务名称并设置到fileId |
| | | String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); |
| | | mediaFile.setJobName(taskNameResult); |
| | | }) |
| | | .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 计算分页信息 |
| | | int total = uniqueResults.size(); |
| | | int start = (page - 1) * pageSize; |
| | | int end = Math.min(start + pageSize, total); |
| | | |
| | | // 获取当前页的结果 |
| | | List<MediaFileEntity> pageResults = uniqueResults.subList(start, end); |
| | | |
| | | // 创建临时的 Page 对象 |
| | | Page<MediaFileEntity> resultPage = new Page<>(page, pageSize); |
| | | resultPage.setRecords(pageResults); |
| | | resultPage.setTotal(total); |
| | | |
| | | // 返回分页数据 |
| | | return new PaginationData<>(records, new Pagination(resultPage)); |
| | | return new PaginationData<>(pageResults, new Pagination(resultPage)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<MediaFileEntity> listMediaFileEntity(String workspaceId, String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | |
| | | @RequestParam Double airportLat, |
| | | @RequestParam Double airportLon) { |
| | | List<LotInfo> lotInfos = getPatchesService.getLotInfosByIds(list); |
| | | System.out.println(lotInfos); |
| | | System.out.println(lotInfos); |
| | | System.out.println(lotInfos); |
| | | System.out.println(lotInfos); |
| | | System.out.println(lotInfos); |
| | | System.out.println(lotInfos); |
| | | return GeoToolsUtil.getRoutePointOrder(lotInfos, airportLat, airportLon); |
| | | } |
| | | |
| | |
| | | int statue = lotInfo.getIsPush(); |
| | | |
| | | if (statue == 1) { |
| | | Page<MediaFileMarkEntity> page = markMapper.selectPage( |
| | | new Page<MediaFileMarkEntity>(param.getPage(), param.getPageSize()), |
| | | List<MediaFileMarkEntity> allResults = markMapper.selectList( |
| | | new LambdaQueryWrapper<MediaFileMarkEntity>().like(MediaFileMarkEntity::getFileName, "%" + dkbh + "~" + "%")); |
| | | |
| | | // 去重处理 |
| | | Map<String, MediaFileMarkEntity> uniqueFileMap = new LinkedHashMap<>(); |
| | | List<MediaFileMarkEntity> records = page.getRecords() |
| | | .stream() |
| | | List<MediaFileMarkEntity> uniqueResults = allResults.stream() |
| | | .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return new PaginationData<MediaFileMarkEntity>(records, new Pagination(page)); |
| | | // 计算分页信息 |
| | | int total = uniqueResults.size(); |
| | | int start = (param.getPage() - 1) * param.getPageSize(); |
| | | int end = Math.min(start + param.getPageSize(), total); |
| | | |
| | | // 获取当前页的结果 |
| | | List<MediaFileMarkEntity> pageResults = uniqueResults.subList(start, end); |
| | | |
| | | // 创建临时的 Page 对象 |
| | | Page<MediaFileMarkEntity> resultPage = new Page<>(param.getPage(), param.getPageSize()); |
| | | resultPage.setRecords(pageResults); |
| | | resultPage.setTotal(total); |
| | | |
| | | // 返回分页数据 |
| | | return new PaginationData<>(pageResults, new Pagination(resultPage)); |
| | | } else { |
| | | Page<MediaFileEntity> page = fileMapper.selectPage( |
| | | new Page<MediaFileEntity>(param.getPage(), param.getPageSize()), |
| | | List<MediaFileEntity> allResults = fileMapper.selectList( |
| | | new LambdaQueryWrapper<MediaFileEntity>().like(MediaFileEntity::getFileName, "%" + dkbh + "~" + "%")); |
| | | |
| | | // 去重处理 |
| | | Map<String, MediaFileEntity> uniqueFileMap = new LinkedHashMap<>(); |
| | | List<MediaFileEntity> records = page.getRecords() |
| | | .stream() |
| | | List<MediaFileEntity> uniqueResults = allResults.stream() |
| | | .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return new PaginationData<MediaFileEntity>(records, new Pagination(page)); |
| | | // 计算分页信息 |
| | | int total = uniqueResults.size(); |
| | | int start = (param.getPage() - 1) * param.getPageSize(); |
| | | int end = Math.min(start + param.getPageSize(), total); |
| | | |
| | | // 获取当前页的结果 |
| | | List<MediaFileEntity> pageResults = uniqueResults.subList(start, end); |
| | | |
| | | // 创建临时的 Page 对象 |
| | | Page<MediaFileEntity> resultPage = new Page<>(param.getPage(), param.getPageSize()); |
| | | resultPage.setRecords(pageResults); |
| | | resultPage.setTotal(total); |
| | | |
| | | // 返回分页数据 |
| | | return new PaginationData<>(pageResults, new Pagination(resultPage)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public List<MediaFileEntity> listPohto(String dkbh, String workspaceId) { |
| | | return fileMapper.selectList(new LambdaQueryWrapper<MediaFileEntity>().like(MediaFileEntity::getFileName, "%" + dkbh + "%") |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | |
| | | List<LotInfo> list = new ArrayList<>(); |
| | | File file1 = MultipartFileTOFileUtil.multipartFile2File(file, patchesConfigPojo.getUnzip()); |
| | | List<ShpDTO> shpData = ShapeFileUtil.shpToGeoJson(file1); |
| | | String s=null; |
| | | for (int i = 0; i < shpData.size(); i++) { |
| | | String[] arr1 = FormatConversionUtil.formatConversion(Collections.singletonList(s)); |
| | | for (ShpDTO shpDatum : shpData) { |
| | | LotInfo lotInfo = new LotInfo(); |
| | | String temp = arr1[i].trim(); |
| | | temp = FormatConversionUtil.modifySpacesAndCommas(temp); |
| | | json = head + temp; |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String bsm = uuid.replaceAll("-", ""); |
| | | lotInfo.setBsm(bsm); |
| | | lotInfo.setWorkspaceId(workspaceId); |
| | | lotInfo.setDkfw(json); |
| | | lotInfo.setDkbh("dkbh" + i); |
| | | lotInfo.setDkfw(poylonCGCStoWGS(convertToWKT(shpDatum.getDKFW()))); |
| | | lotInfo.setDkbh(shpDatum.getDKBH()); |
| | | lotInfo.setXzb(shpDatum.getXZB()); |
| | | lotInfo.setYzb(shpDatum.getYZB()); |
| | | lotInfo.setXzqdm(shpDatum.getXZQDM()); |
| | | lotInfo.setXmc(DistrictCodeUtils.codeToName(lotInfo.getXzqdm())); |
| | | list.add(lotInfo); |
| | | String strs = getCentros(list); |
| | | String end = strs.replaceAll("\\(", "").replaceAll(", NaN\\)", ""); |
| | | String[] points = end.split(","); |
| | | lotInfo.setXzb(Double.valueOf(points[0])); |
| | | lotInfo.setYzb(Double.valueOf(points[1])); |
| | | shpToDataSourceMapper.insert(lotInfo); |
| | | } |
| | | List<PointPO> coordinates = GeoToolsUtil.getRoutePointOrder(list, airportLat, airportLon); |
| | |
| | | public List<LotInfo> getNoPlan(){ |
| | | return shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getIsPlan,0)); |
| | | } |
| | | public static String convertToWKT(String coordinates) { |
| | | // Remove outermost square brackets and split by comma |
| | | String cleanedCoordinates = coordinates.substring(4, coordinates.length() - 4); |
| | | String[] polygons = cleanedCoordinates.split("\\]\\],\\[\\["); |
| | | StringBuilder wkt = new StringBuilder("MULTIPOLYGON("); |
| | | |
| | | for (String polygon : polygons) { |
| | | wkt.append("(("); |
| | | String[] points = polygon.split("\\],\\["); |
| | | for (String point : points) { |
| | | String[] coords = point.split(","); |
| | | double x = Double.parseDouble(coords[0]); |
| | | double y = Double.parseDouble(coords[1]); |
| | | wkt.append(x).append(" ").append(y).append(", "); |
| | | } |
| | | // Remove the last comma and space |
| | | wkt.setLength(wkt.length() - 2); |
| | | wkt.append(")), "); |
| | | } |
| | | // Remove the last comma and space, and close the polygon |
| | | wkt.setLength(wkt.length() - 2); |
| | | wkt.append(")"); |
| | | |
| | | return wkt.toString(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.dji.sample.patches.model.dto.ShpDTO; |
| | | import com.dji.sample.territory.utils.CoordinateSystemUtil; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.DataStoreFinder; |
| | | import org.geotools.data.FeatureSource; |
| | | import org.geotools.feature.FeatureCollection; |
| | | import org.geotools.feature.FeatureIterator; |
| | | import org.geotools.geojson.feature.FeatureJSON; |
| | | import org.locationtech.jts.geom.Geometry; |
| | | import org.locationtech.jts.geom.Point; |
| | | import org.locationtech.jts.io.ParseException; |
| | | import org.opengis.feature.simple.SimpleFeature; |
| | | import org.opengis.feature.simple.SimpleFeatureType; |
| | | import org.opengis.filter.Filter; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.StringWriter; |
| | |
| | | * @description 通过shp压缩文件,将其转换为GeoJson格式 |
| | | */ |
| | | //将解压后的文件转换成GeoJson格式 |
| | | public static List<ShpDTO> shpToGeoJson(File zipFile) throws IOException { |
| | | ShpDTO shpDTO=new ShpDTO(); |
| | | List<ShpDTO> dtoList= new ArrayList<>(); |
| | | public static List<ShpDTO> shpToGeoJson(File zipFile) throws IOException, ParseException { |
| | | List<ShpDTO> dtoList = new ArrayList<>(); |
| | | FeatureJSON fjson = new FeatureJSON(); |
| | | JSONObject geoJsonObject = new JSONObject(); |
| | | geoJsonObject.put("type", "FeatureCollection"); |
| | | List<String> strings = new ArrayList<>(); |
| | | try { |
| | | // 获取FeatureCollection |
| | | FeatureCollection collection = getFeatureCollectionByShpFile(zipFile); |
| | | |
| | | FeatureIterator iterator = collection.features(); |
| | | List<JSONObject> array = new ArrayList<JSONObject>(); |
| | | //遍历feature转为json对象 |
| | | while (iterator.hasNext()) { |
| | | ShpDTO shpDTO = new ShpDTO(); |
| | | SimpleFeature feature = (SimpleFeature) iterator.next(); |
| | | StringWriter writer = new StringWriter(); |
| | | fjson.writeFeature(feature, writer); |
| | |
| | | shpDTO.setDKFW(json.getJSONObject("geometry").get("coordinates").toString()); |
| | | shpDTO.setGEO(json.getJSONObject("geometry").get("type").toString()); |
| | | shpDTO.setXZQDM(json.getJSONObject("properties").get("XZQDM").toString()); |
| | | shpDTO.setXZB( json.getJSONObject("properties").getDouble("XZB")); |
| | | shpDTO.setYZB( json.getJSONObject("properties").getDouble("YZB")); |
| | | shpDTO.setDKBH(json.getJSONObject("properties").get("JCBH").toString()); |
| | | double[] xy = getLongitudeLatitude(CoordinateSystemUtil.pointCGCStoWGS( |
| | | json.getJSONObject("properties").getDouble("XZB"), |
| | | json.getJSONObject("properties").getDouble("YZB"))); |
| | | shpDTO.setXZB(xy[0]); |
| | | shpDTO.setYZB(xy[1]); |
| | | shpDTO.setDKBH(json.getJSONObject("properties").getString("JCBH")); |
| | | shpDTO.setJCMJ(json.getJSONObject("properties").getDouble("JCMC")); |
| | | shpDTO.setTBLX(json.getJSONObject("properties").getString("TBLX")); |
| | | shpDTO.setDDTC(json.getJSONObject("properties").getString("DDTC")); |
| | | shpDTO.setHSX(json.getJSONObject("properties").getString("HSX")); |
| | | shpDTO.setJCLX(json.getJSONObject("properties").getString("JCLX")); |
| | | dtoList.add(shpDTO); |
| | | String str2 = json.getJSONObject("geometry").get("coordinates").toString(); |
| | | strings.add(str2); |
| | | array.add(json); |
| | | } |
| | | iterator.close(); |
| | | //添加到geojsonObject |
| | | geoJsonObject.put("features", array); |
| | | iterator.close(); |
| | | |
| | | } catch (Exception e) { |
| | | throw e; |
| | | } |
| | | return dtoList; |
| | | } |
| | | |
| | | public static void main(String[] args) throws IOException, ParseException { |
| | | File file = new File("D:\\ceshi\\ceshi.zip"); |
| | | shpToGeoJson(file); |
| | | } |
| | | |
| | | public static double[] getLongitudeLatitude(Geometry wktPoint) throws ParseException { |
| | | Geometry geometry = wktPoint; |
| | | if (geometry instanceof Point) { |
| | | Point point = (Point) geometry; |
| | | double longitude = point.getX(); |
| | | double latitude = point.getY(); |
| | | return new double[]{longitude, latitude}; |
| | | } else { |
| | | throw new IllegalArgumentException("The geometry is not a point."); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.speak.model.dto.SpeakTtsContextDto; |
| | | import com.dji.sample.speak.model.dto.SpeakTtsFileDto; |
| | | import com.dji.sample.speak.model.dto.SpeakTtsStartDto; |
| | | import com.dji.sample.speak.service.SpeakTtsService; |
| | | import com.dji.sample.speak.util.MD5Util; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | @RestController |
| | | @RequestMapping("${url.speak.prefix}${url.speak.version}") |
| | |
| | | private SpeakTtsService ttsService; |
| | | |
| | | @PostMapping("/sendContext") |
| | | public ResponseResult sendContext(@RequestBody SpeakTtsContextDto dto) { |
| | | return ResponseResult.success(ttsService.sendTtsContext(dto)); |
| | | public ResponseResult sendContext(@RequestParam String sn, @RequestParam String value,@RequestParam Integer psdk_index) { |
| | | SpeakTtsContextDto dto=new SpeakTtsContextDto(); |
| | | dto.setValue(value); |
| | | dto.setPsdk_index(psdk_index); |
| | | return ResponseResult.success(ttsService.sendTtsContext(sn,dto)); |
| | | } |
| | | @PostMapping("/startTts") |
| | | public ResponseResult ttxStart(SpeakTtsStartDto dto){ |
| | | return ResponseResult.success(ttsService.speakTtxStart(dto)); |
| | | public ResponseResult ttxStart(@RequestParam String sn,@RequestParam Integer psdk_index,@RequestBody SpeakTtsFileDto fileDto){ |
| | | SpeakTtsStartDto dto= new SpeakTtsStartDto(); |
| | | dto.setPsdk_index(psdk_index); |
| | | fileDto.setMd5(MD5Util.getMD5Checksum(fileDto.getText())); |
| | | dto.setTts(fileDto); |
| | | return ResponseResult.success(ttsService.speakTtxStart(sn,dto)); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.component.mqtt.service.IMessageSenderService; |
| | | import com.dji.sample.patches.utils.MultipartFileTOFileUtil; |
| | | import com.dji.sample.speak.model.dto.PsdkModelDto; |
| | | import com.dji.sample.speak.model.dto.SpeakVoiceStartDto; |
| | | import com.dji.sample.speak.model.dto.SpeakVolumeDto; |
| | | import com.dji.sample.speak.model.enums.FormatEnum; |
| | | import com.dji.sample.speak.model.param.SpeakVoiceStartParam; |
| | | import com.dji.sample.speak.service.SpeakVoiceService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | |
| | |
| | | private SpeakVoiceService voiceServicel; |
| | | |
| | | @PostMapping("/startVoice") |
| | | public ResponseResult takeVoice(String sn , SpeakVoiceStartParam param) { |
| | | return ResponseResult.success(voiceServicel.takeVoice(sn,param)); |
| | | public ResponseResult takeVoice(@RequestParam String sn, |
| | | @RequestParam int psdk_index, |
| | | @RequestParam String name, |
| | | @RequestParam MultipartFile file) { |
| | | File file1=MultipartFileTOFileUtil.multipartFile2File(file,"src/main/resources/tmp/20240614"); |
| | | return ResponseResult.success(voiceServicel.takeVoice(sn, psdk_index,name,file1)); |
| | | } |
| | | |
| | | @PostMapping("/stopVoice") |
| | | public ResponseResult stopVoice() { |
| | | return ResponseResult.success(voiceServicel.stopVoice()); |
| | | public ResponseResult stopVoice(@RequestParam int psdk_index, @RequestParam String sn) { |
| | | return ResponseResult.success(voiceServicel.stopVoice(sn, psdk_index)); |
| | | } |
| | | |
| | | @PostMapping("/voiceVolumn") |
| | | public ResponseResult voiceVolumn(SpeakVolumeDto dto) { |
| | | return ResponseResult.success(voiceServicel.setVoiceVolume(dto)); |
| | | public ResponseResult voiceVolumn(@RequestBody SpeakVolumeDto dto, @RequestParam String sn) { |
| | | return ResponseResult.success(voiceServicel.setVoiceVolume(dto, sn)); |
| | | } |
| | | |
| | | @PostMapping("/voiceMode") |
| | | public ResponseResult restartVoice(PsdkModelDto dto) { |
| | | return ResponseResult.success(voiceServicel.setVoiceMode(dto)); |
| | | public ResponseResult restartVoice(@RequestBody PsdkModelDto dto, @RequestParam String sn) { |
| | | return ResponseResult.success(voiceServicel.setVoiceMode(sn, dto)); |
| | | } |
| | | |
| | | @PostMapping("/restartVoice") |
| | | public ResponseResult restartVoice() { |
| | | return ResponseResult.success(voiceServicel.restartVoice()); |
| | | public ResponseResult restartVoice(@RequestParam int psdkIndex, @RequestParam String sn) { |
| | | return ResponseResult.success(voiceServicel.restartVoice(sn, psdkIndex)); |
| | | } |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class PsdkFloatDto { |
| | | private Integer psdkIndex; |
| | | private Integer psdk_index; |
| | | private String value; |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class PsdkModelDto { |
| | | private Integer psdkIndex; |
| | | private Integer psdk_index; |
| | | private PsdkModelEnum play_mode; |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class SpeakTtsContextDto { |
| | | private Integer psdkIndex; |
| | | private Integer psdk_index; |
| | | private String value; |
| | | } |
| | |
| | | @AllArgsConstructor |
| | | public class SpeakTtsFileDto { |
| | | private String name; |
| | | private String url; |
| | | private String text; |
| | | private String md5; |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class SpeakTtsStartDto { |
| | | private Integer psdkIndex; |
| | | private Integer psdk_index; |
| | | private SpeakTtsFileDto tts; |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class SpeakVoiceStartDto { |
| | | private Integer psdkIndex; |
| | | private Integer psdk_index; |
| | | private SpeakVoiceFileDto file; |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class SpeakVolumeDto { |
| | | private Integer psdkIndex; |
| | | private Integer psdk_index; |
| | | private Integer play_volume; |
| | | } |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class SpeakVoiceStartParam { |
| | | private Integer psdkIndex; |
| | | private Integer psdk_index; |
| | | private String name; |
| | | private File file; |
| | | private FormatEnum format; |
| | |
| | | import com.dji.sample.speak.model.dto.SpeakTtsStartDto; |
| | | |
| | | public interface SpeakTtsService { |
| | | int sendTtsContext(SpeakTtsContextDto dto); |
| | | int sendTtsContext(String sn,SpeakTtsContextDto dto); |
| | | |
| | | int speakTtxStart(SpeakTtsStartDto dto); |
| | | |
| | | int speakTtxStart(String sn,SpeakTtsStartDto dto); |
| | | } |
| | |
| | | import com.dji.sample.speak.model.dto.PsdkModelDto; |
| | | import com.dji.sample.speak.model.dto.SpeakVoiceStartDto; |
| | | import com.dji.sample.speak.model.dto.SpeakVolumeDto; |
| | | import com.dji.sample.speak.model.enums.FormatEnum; |
| | | import com.dji.sample.speak.model.param.SpeakVoiceStartParam; |
| | | |
| | | import java.io.File; |
| | | |
| | | public interface SpeakVoiceService { |
| | | int takeVoice(String sn , SpeakVoiceStartParam param); |
| | | int takeVoice(String sn , Integer psdk_index, String name, File file); |
| | | |
| | | int restartVoice(); |
| | | int restartVoice(String sn ,Integer psdk_index); |
| | | |
| | | int stopVoice(); |
| | | int stopVoice(String sn,Integer psdk_index); |
| | | |
| | | int setVoiceMode(PsdkModelDto dto); |
| | | int setVoiceMode(String sn,PsdkModelDto dto); |
| | | |
| | | int setVoiceVolume(SpeakVolumeDto dto); |
| | | int setVoiceVolume(SpeakVolumeDto dto,String sn); |
| | | } |
| | |
| | | package com.dji.sample.speak.service.serviceImpl; |
| | | |
| | | import com.dji.sample.component.mqtt.service.IMessageSenderService; |
| | | import com.dji.sample.speak.model.dto.SpeakTtsContextDto; |
| | | import com.dji.sample.speak.model.dto.SpeakTtsStartDto; |
| | | import com.dji.sample.speak.model.enums.VoiceEnums; |
| | | import com.dji.sample.speak.service.SpeakTtsService; |
| | | import lombok.extern.log4j.Log4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service |
| | | |
| | | public class SpeakTtsServiceImpl implements SpeakTtsService { |
| | | @Autowired |
| | | private IMessageSenderService messageSenderService; |
| | | |
| | | @Override |
| | | public int sendTtsContext(SpeakTtsContextDto dto) { |
| | | return 0; |
| | | public int sendTtsContext(String sn, SpeakTtsContextDto dto) { |
| | | return messageSenderService.publishServicesTopic(sn, VoiceEnums.PSDK_INPUT_BOX_TEXT_SET.getMethod(), dto).getResult(); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int speakTtxStart(SpeakTtsStartDto dto) { |
| | | return 0; |
| | | public int speakTtxStart(String sn, SpeakTtsStartDto dto) { |
| | | return messageSenderService.publishServicesTopic(sn, VoiceEnums.SPEAKER_TTS_PLAY_START.getMethod(), dto).getResult(); |
| | | |
| | | } |
| | | } |
| | |
| | | import com.dji.sample.speak.model.dto.SpeakVoiceFileDto; |
| | | import com.dji.sample.speak.model.dto.SpeakVoiceStartDto; |
| | | import com.dji.sample.speak.model.dto.SpeakVolumeDto; |
| | | import com.dji.sample.speak.model.enums.FormatEnum; |
| | | import com.dji.sample.speak.model.enums.PsdkModelEnum; |
| | | import com.dji.sample.speak.model.enums.VoiceEnums; |
| | | import com.dji.sample.speak.model.param.SpeakVoiceStartParam; |
| | | import com.dji.sample.speak.service.SpeakVoiceService; |
| | |
| | | private IMessageSenderService messageSenderService; |
| | | @Autowired |
| | | private MinioPojo pojo; |
| | | |
| | | @Override |
| | | public int takeVoice(String sn, SpeakVoiceStartParam param) { |
| | | SpeakVoiceStartDto dto=new SpeakVoiceStartDto(); |
| | | SpeakVoiceFileDto fileDto=new SpeakVoiceFileDto(); |
| | | String url=upMinio(param.getFile(),param.getName()); |
| | | public int takeVoice( String sn , Integer psdk_index, String name, File file) { |
| | | SpeakVoiceStartDto dto = new SpeakVoiceStartDto(); |
| | | SpeakVoiceFileDto fileDto = new SpeakVoiceFileDto(); |
| | | String url = upMinio(file, name); |
| | | fileDto.setUrl(url); |
| | | fileDto.setMd5(MD5Util.getMD5Checksum(param.getFile())); |
| | | fileDto.setFormat(param.getFormat()); |
| | | fileDto.setName(param.getName()); |
| | | dto.setPsdkIndex(param.getPsdkIndex()); |
| | | return messageSenderService.publishServicesTopic(sn, VoiceEnums.SPEAKER_AUDIO_PLAY_START.getMethod(),param).getResult(); |
| | | fileDto.setMd5(MD5Util.getMD5Checksum(file)); |
| | | fileDto.setFormat(FormatEnum.PCM); |
| | | fileDto.setName(name); |
| | | dto.setPsdk_index(psdk_index); |
| | | dto.setFile(fileDto); |
| | | return messageSenderService.publishServicesTopic(sn, VoiceEnums.SPEAKER_AUDIO_PLAY_START.getMethod(), dto).getResult(); |
| | | } |
| | | |
| | | @Override |
| | | public int restartVoice() { |
| | | return 0; |
| | | public int restartVoice(String sn, Integer psdk_index) { |
| | | return messageSenderService.publishServicesTopic(sn, VoiceEnums.SPEAKER_REPLAY.getMethod(), psdk_index).getResult(); |
| | | } |
| | | |
| | | @Override |
| | | public int stopVoice() { |
| | | return 0; |
| | | public int stopVoice(String sn, Integer psdk_index) { |
| | | return messageSenderService.publishServicesTopic(sn,VoiceEnums.SPEAKER_PLAY_STOP.getMethod(), psdk_index).getResult(); |
| | | } |
| | | |
| | | @Override |
| | | public int setVoiceMode(PsdkModelDto dto) { |
| | | return 0; |
| | | public int setVoiceMode(String sn,PsdkModelDto dto) { |
| | | return messageSenderService.publishServicesTopic(sn,VoiceEnums.SPEAKER_PLAY_MODE_SET.getMethod(), dto).getResult(); |
| | | } |
| | | |
| | | @Override |
| | | public int setVoiceVolume(SpeakVolumeDto dto) { |
| | | return 0; |
| | | public int setVoiceVolume(SpeakVolumeDto dto, String sn) { |
| | | return messageSenderService.publishServicesTopic(sn,VoiceEnums.SPEAKER_PLAY_VOLUME_SET.getMethod(), dto).getResult(); |
| | | } |
| | | |
| | | public String upMinio(File file,String fileName){ |
| | | public String upMinio(File file, String fileName) { |
| | | String endpoint = pojo.getEndpoint(); |
| | | String accessKey = pojo.getAccessKey(); |
| | | String secretKey = pojo.getSecretKey(); |
| | | String bucketName = pojo.getBucket(); |
| | | String objectName="/"+fileName+getNowTimeName(); |
| | | FileServiceImpl.uploadFile(endpoint,accessKey,secretKey,bucketName,objectName,file,"audio/mpeg"); |
| | | return endpoint+"/"+bucketName+objectName; |
| | | String objectName = "/" + fileName + getNowTimeName(); |
| | | FileServiceImpl.uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, file, "audio/mpeg"); |
| | | return endpoint + "/" + bucketName + objectName; |
| | | } |
| | | |
| | | public static String getNowTimeName() { |
| | | LocalDateTime currentTime = LocalDateTime.now(); |
| | | // 格式化时间,生成当前时间 |
| | |
| | | return null; |
| | | } |
| | | } |
| | | public static String getMD5Checksum(String input) { |
| | | try { |
| | | MessageDigest md = MessageDigest.getInstance("MD5"); |
| | | byte[] bytes = input.getBytes(); |
| | | md.update(bytes); |
| | | |
| | | byte[] digest = md.digest(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (byte b : digest) { |
| | | sb.append(String.format("%02x", b)); |
| | | } |
| | | return sb.toString(); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | } |