반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
05-19 00:03
관리 메뉴

ImJay

[VMap] 기능 추가, 코드 리팩토링, 버그 수정, 본문

개인 프로젝트

[VMap] 기능 추가, 코드 리팩토링, 버그 수정,

ImJay 2023. 3. 23. 15:47
반응형

1. TranscriptionController  에서 변환된 텍스트를 노션으로 바로 작성할 수 있도록 기능을 추가해야했다.

 

- 현재 STT는 서버에서 테스트용으로 구현한 것이므로, 크게 리팩토링할 필요 없이 테스트만 정상적으로 구동하면 됐다.

 

- 따라서 Notion에 Json을 쏴주는 코드를 MVC 패턴으로 분리후, 로직(Service)에 해당하는 메소드를 호출해주기로 회의를 통해 결정했다.

 

- 세희가 해당 작업을 수행하였다.

 

 

2. 현재 STT API를 사용하기 위해선 여러 과정을 거쳐야했는데, 이를 한번에 진행하기 위해 여러 객체로 분리하여 한 객체에 wav 파일만 수정하면 되도록 작성되어있다.

 

- 그러나, 정확한 원인은 모르지만 해당 STT API 의 서버 통신이 느린 것인지 너무 다이렉트로 쏴주면 not found 에러가 종종 발생했다. 인증과정이나 사운드에 문제가 있는 것은 아니었지만 두번에 한번꼴로는 not found 가 출력되었다.

 

- 해당 오류는 서비스에서는 크리티컬 했지만 현재 서버단은 테스트 용도였기 때문에 크게 수정할 필요성을 느끼지 못했다.

- 그러나 출력 결과물로 not found 가 계속 출력되는건 여전히 불편하게 느껴졌고, TranscriptionController 를 리팩토링 하는 겸 해당 코드를 수정하기로 결심했다.

 

package ParkLab.VMap.model.Service.stt;

import org.springframework.stereotype.Service;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class TranscribeSample {
    public TranscribeSample() {
    }

    public String Transcribe() throws Exception {
        String transcription;
        do {
            transcription = "";

            AuthSample authSample = new AuthSample();
            String auth = authSample.getAuth();

            File file = new File("./audio/output.wav");

            PostTranscribeSample postTranscribeSample = new PostTranscribeSample(auth, file);
            String id = postTranscribeSample.getId();

            GetTranscribeSample getTranscribeSample = new GetTranscribeSample(auth, id);
            String result = getTranscribeSample.getResult();

            System.out.println(result);

            Pattern pattern = Pattern.compile("\"msg\":\"(.*?)\"}");
            Matcher matcher = pattern.matcher(result);

            while (matcher.find()) {
                System.out.println("Match: " + matcher.group(1));
                transcription += matcher.group(1);
            }
        } while(transcription.equalsIgnoreCase("not found"));
        return transcription;
    }
}

- 우선 TranscriptionController 에 API를 연결시키는 부분을 Service 로 이동하였다.

- 또한, do while, equalsIgnoreCase 문을 통해 STT 변환 값이 "not found" 일 경우 API를 재호출하도록 로직을 설계했다.

 

- 예상 설계대로 STT가 변환에 실패하여 "not found"를 반환할 경우 정상적으로 변환된 값을 출력될 때까지 API를 재호출하여 원하는 값을 Notion 에 바로 작성하는 것을 성공했다.

 

 

반응형
Comments