Skip to content

Commit

Permalink
Merge pull request #52 from SWM-SMART/feat/#51
Browse files Browse the repository at this point in the history
STT 요청 수정
  • Loading branch information
noparamin authored Nov 12, 2023
2 parents c72e6ee + 7a2467f commit 7e517a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/smart/watchboard/dto/SttRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.smart.watchboard.dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class SttRequestDto {
private String audioUrl;

public SttRequestDto(String audioUrl) {
this.audioUrl = audioUrl;
}
}
26 changes: 8 additions & 18 deletions src/main/java/com/smart/watchboard/service/STTService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smart.watchboard.domain.SttData;
import com.smart.watchboard.dto.SttRequestDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -23,26 +24,18 @@
@RequiredArgsConstructor
@Slf4j
public class STTService {
@Value("${clova.stt.secret-key}")
private String secretKey;

@Value("${clova.stt.invoke-url}")
private String clovaInvokeURL;
@Value("${ai-url}")
private String aiUrl;

public ResponseEntity<String> getSTT(String path) throws JsonProcessingException {
String url = aiUrl + "/stt";
//
RestTemplate restTemplate = new RestTemplate();
String requestURL = clovaInvokeURL + "/recognizer/url";
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");
headers.set("X-CLOVASPEECH-API-KEY", secretKey);
String requestBody = "{" +
"\"url\": \"" + path + "\", " +
"\"language\": \"ko-KR\", " +
"\"completion\": \"sync\"" +
"}";
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
System.out.println(requestEntity.getBody());
ResponseEntity<String> responseEntity = restTemplate.exchange(requestURL, HttpMethod.POST, requestEntity, String.class);
SttRequestDto sttRequestDto = new SttRequestDto(path);
HttpEntity<SttRequestDto> requestEntity = new HttpEntity<>(sttRequestDto, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

return responseEntity;
}
Expand All @@ -62,9 +55,6 @@ public List<SttData> getSTTData(ResponseEntity<String> sttResponseEntity) throws
sttDatas.add(sttData);
}

//result.put("data", sttDatas);

//return result;
return sttDatas;
}

Expand Down

0 comments on commit 7e517a4

Please sign in to comment.