https://api.ncloud-docs.com/docs/ai-application-service-clovaspeech-longsentence
→ 우리는 S3에서 가져오기 때문에
clova speech 도메인 설정
빌더 실행 → 설정에 들어가면
CLOVASPEECH_ENDPOINT
, CLOVASPEECH_API_KEY
발급 받아서 적용
async transcribeAudio(remoteFileName: string) {
const speechEndpoint = this.configService.get<string>('CLOVASPEECH_ENDPOINT');
const body = {
dataKey: remoteFileName, // object storage 저장 위치
params: { enable: true },
language: 'ko-KR',
completion: 'sync', // sync인 경우 json으로 받고, async인 경우에는 s3로 올라감
fulltext: true,
};
try {
const response = await fetch(speechEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CLOVASPEECH-API-KEY': this.configService.get<string>('CLOVASPEECH_API_KEY'),
},
body: JSON.stringify(body),
});
const data = await response.json();
return data.text; //스크립트 텍스트만 가져오기
} catch (error) {
console.error('Failed to transcribe audio:', error);
throw new InternalServerErrorException(ErrorMessage.FAILED_TO_TRANSCRIBE_AUDIO);
}
}
https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary
clova studio 시작하기
문장요약 테스트 앱 실행하면 바로 CLOVASTUDIO_ENDPOINT
, CLOVASTUDIO_API_KEY
, CLOVASTUDIO_APIGW_API_KEY
발급 가능
async summaryAudio(text: string) {
const studioEndpoint = this.configService.get<string>('CLOVASTUDIO_ENDPOINT');
const body = {
texts: [text],//텍스트로 변환한 내용을 배열로 전달
segMinSize: 300,
includeAiFilters: true,
autoSentenceSplitter: true,
segCount: -1,
segMaxSize: 1000,
};
try {
const response = await fetch(studioEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-NCP-CLOVASTUDIO-API-KEY': this.configService.get<string>('CLOVASTUDIO_API_KEY'),
'X-NCP-APIGW-API-KEY': this.configService.get<string>('CLOVASTUDIO_APIGW_API_KEY'),
},
body: JSON.stringify(body),
});
if (!response.ok) {
const errorText = await response.text();
console.error('Error response:', errorText);
throw new Error(`API error: ${response.status} - ${response.statusText}`);
}
const data = await response.json();
return data.result.text; //바로 텍스트를 추출해서 db에 저장
} catch (error) {
console.error('Failed to summarize audio:', error);
throw new InternalServerErrorException(ErrorMessage.FAILED_TO_SUMMARY_AUDIO);
}
}