Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STT 요청 수정 #52

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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