From 3457aea28a17698c5412a8094a05315b0efcb093 Mon Sep 17 00:00:00 2001 From: kms Date: Mon, 13 Nov 2023 12:33:38 +0900 Subject: [PATCH 1/2] :hammer: fix: change audioUrl key #53 --- src/main/java/com/smart/watchboard/dto/SttRequestDto.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/smart/watchboard/dto/SttRequestDto.java b/src/main/java/com/smart/watchboard/dto/SttRequestDto.java index 6bc936a..6b71540 100644 --- a/src/main/java/com/smart/watchboard/dto/SttRequestDto.java +++ b/src/main/java/com/smart/watchboard/dto/SttRequestDto.java @@ -6,9 +6,9 @@ @Getter @Setter public class SttRequestDto { - private String audioUrl; + private String key; - public SttRequestDto(String audioUrl) { - this.audioUrl = audioUrl; + public SttRequestDto(String key) { + this.key = key; } } From a4a24408a686f7181bc795325c9bb7125a9aa8a2 Mon Sep 17 00:00:00 2001 From: kms Date: Mon, 13 Nov 2023 12:34:10 +0900 Subject: [PATCH 2/2] :hammer: fix: change path file name #53 --- .../controller/AudioFileController.java | 23 +++++++++---------- .../smart/watchboard/service/STTService.java | 6 +++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/smart/watchboard/controller/AudioFileController.java b/src/main/java/com/smart/watchboard/controller/AudioFileController.java index 78b01f9..4a67212 100644 --- a/src/main/java/com/smart/watchboard/controller/AudioFileController.java +++ b/src/main/java/com/smart/watchboard/controller/AudioFileController.java @@ -3,9 +3,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.itextpdf.text.DocumentException; import com.smart.watchboard.common.support.AwsS3Uploader; -import com.smart.watchboard.domain.Document; -import com.smart.watchboard.domain.LectureNote; -import com.smart.watchboard.domain.Note; import com.smart.watchboard.domain.SttData; import com.smart.watchboard.dto.*; import com.smart.watchboard.service.*; @@ -14,19 +11,14 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.sound.sampled.UnsupportedAudioFileException; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.Optional; -import static com.smart.watchboard.common.support.PdfConverter.convertStringToPdf; @RestController @RequestMapping("/documents") @@ -102,6 +94,12 @@ public ResponseEntity test(@RequestHeader("Authorization") String accessToken String body = """ {"keywords":["eatssss","food","today"]} """; + String path = "https://watchboard-record-bucket.s3.ap-northeast-2.amazonaws.com/audio/mp4/26.1.m4a"; + ResponseEntity responseEntity = sttService.getSTT(path); + //System.out.println(responseEntity.getBody().toString()); + List sttData = sttService.getSTTData(responseEntity); + String text = sttService.getText(responseEntity); + System.out.println(text); // String sttResult = "안녕하세요 Hello!!!!"; // String sttFileName = "sttResult.pdf"; // File textPdfFile = convertStringToPdf(sttResult, sttFileName); @@ -115,10 +113,11 @@ public ResponseEntity test(@RequestHeader("Authorization") String accessToken // S3Dto s3Dto = new S3Dto(multipartFile, 26L); // String path = awsS3Uploader.uploadTextPdfFile(s3Dto); // System.out.println(path); - String path = "https://s3.ap-northeast-2.amazonaws.com/watchboard-record-bucket/application/pdf/감정분류.pdf"; - ResponseEntity responseEntity = requestService.requestPdfSummary(path); - System.out.println(responseEntity.getBody().getSummary()); - return new ResponseEntity<>(HttpStatus.OK); + +// String path = "https://s3.ap-northeast-2.amazonaws.com/watchboard-record-bucket/application/pdf/감정분류.pdf"; +// ResponseEntity responseEntity = requestService.requestPdfSummary(path); +// System.out.println(responseEntity.getBody().getSummary()); + return new ResponseEntity<>(responseEntity.getBody(), HttpStatus.OK); } } diff --git a/src/main/java/com/smart/watchboard/service/STTService.java b/src/main/java/com/smart/watchboard/service/STTService.java index dc25fd5..afee1c7 100644 --- a/src/main/java/com/smart/watchboard/service/STTService.java +++ b/src/main/java/com/smart/watchboard/service/STTService.java @@ -29,11 +29,13 @@ public class STTService { public ResponseEntity getSTT(String path) throws JsonProcessingException { String url = aiUrl + "/stt"; - // + int startIndex = path.indexOf("audio/mp3/") + "audio/mp3/".length(); + String fileName = path.substring(startIndex); + RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "application/json"); - SttRequestDto sttRequestDto = new SttRequestDto(path); + SttRequestDto sttRequestDto = new SttRequestDto(fileName); HttpEntity requestEntity = new HttpEntity<>(sttRequestDto, headers); ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);