김수민

audio error correction

......@@ -57,6 +57,7 @@
<workItem from="1574071758382" duration="6285000" />
<workItem from="1574323490142" duration="15840000" />
<workItem from="1574342689824" duration="11000" />
<workItem from="1574396813813" duration="6958000" />
</task>
<servers />
</component>
......
......@@ -7,7 +7,7 @@ require("dotenv").config({path : '.env'});
var express = require('express');
var app = express();
const line = require('@line/bot-sdk');
app.use(express.static('public'));
//papago api
var request = require('request');
......@@ -62,13 +62,13 @@ function handleEvent(event) {
return Promise.resolve(null);
}
return new Promise(function(resolve, reject) {
//언어 감지 option
var detect_options = {
url : languagedetect_api_url,
form : {'query': event.message.text},
headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret}
};
//papago 언어 감지
request.post(detect_options,function(error,response,body){
console.log(response.statusCode);
......@@ -80,14 +80,20 @@ function handleEvent(event) {
var audio_sys = {
"type": "audio",
"originalContentUrl": "https://panguin.ml/speech.m4a",
"duration": 60000
"duration": 24000
};
//언어 감지가 제대로 됐는지 확인
console.log(detect_body.langCode);
if(detect_options.form.query=='음성'){
console.log('audio streaming');
for_audio_client.replyAudio(event.replyToken,{
"originalContentUrl": "https://panguin.ml/public/speech.m4a",
"duration": 24000
}).then(resolve).catch(reject);
}
//번역은 한국어->영어 / 영어->한국어만 지원
if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){
else if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){
source = detect_body.langCode == 'ko' ? 'ko':'en';
target = source == 'ko' ? 'en':'ko';
//papago 번역 option
......@@ -111,9 +117,10 @@ function handleEvent(event) {
//번역된 문장 보내기
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
let audio_options={
'Text': result.text,
'OutputFormat': 'mp3',
'VoiceId':'Seoyeon'
'VoiceId':'Amy'
};
Polly.synthesizeSpeech(audio_options, (err, data) => {
console.log("check");
......@@ -126,21 +133,12 @@ function handleEvent(event) {
return console.log(err);
}
console.log("The file was saved!");
if(!error && response.statusCode == 200){
console.log('audio streaming');
for_audio_client.replyAudio(event.replyToken,audio_sys).then(resolve).catch(reject);
}
});
}
}
});
}
});
......