Skip to content

Commit

Permalink
Merge pull request #55 from SWM-SMART/feat/#53
Browse files Browse the repository at this point in the history
STT 요청시 형식 수정
  • Loading branch information
noparamin authored Nov 13, 2023
2 parents 0e11ef1 + a4a2440 commit 1706fd6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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")
Expand Down Expand Up @@ -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<String> responseEntity = sttService.getSTT(path);
//System.out.println(responseEntity.getBody().toString());
List<SttData> 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);
Expand All @@ -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<SummaryDto> 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<SummaryDto> responseEntity = requestService.requestPdfSummary(path);
// System.out.println(responseEntity.getBody().getSummary());
return new ResponseEntity<>(responseEntity.getBody(), HttpStatus.OK);
}

}
6 changes: 3 additions & 3 deletions src/main/java/com/smart/watchboard/dto/SttRequestDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 4 additions & 2 deletions src/main/java/com/smart/watchboard/service/STTService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public class STTService {

public ResponseEntity<String> 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<SttRequestDto> requestEntity = new HttpEntity<>(sttRequestDto, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

Expand Down

0 comments on commit 1706fd6

Please sign in to comment.