김수민

오디오 수정

......@@ -57,7 +57,8 @@
<workItem from="1574071758382" duration="6285000" />
<workItem from="1574323490142" duration="15840000" />
<workItem from="1574342689824" duration="11000" />
<workItem from="1574396813813" duration="6958000" />
<workItem from="1574396813813" duration="10012000" />
<workItem from="1574494473410" duration="2577000" />
</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');
......@@ -45,6 +45,7 @@ const for_audio_client=LineClient.connect({
// register a webhook handler with middleware
// about the middleware, please refer to doc
app.use(express.static('public'));
app.post('/webhook', line.middleware(config), (req, res) => {
Promise
.all(req.body.events.map(handleEvent))
......@@ -77,21 +78,18 @@ function handleEvent(event) {
var source = '';
var target = '';
var result = { type: 'text', text:''};
var audio_sys = {
"type": "audio",
"originalContentUrl": "https://panguin.ml/speech.m4a",
"duration": 24000
};
//언어 감지가 제대로 됐는지 확인
console.log(detect_body.langCode);
if(detect_options.form.query=='음성'){
console.log('audio streaming');
if (!error && response.statusCode == 200){
console.log(response.statusCode);
for_audio_client.replyAudio(event.replyToken,{
"originalContentUrl": "https://panguin.ml/public/speech.m4a",
"originalContentUrl": "https://panguin.ml/speech.m4a",
"duration": 24000
}).then(resolve).catch(reject);
}
}
//번역은 한국어->영어 / 영어->한국어만 지원
else if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){
source = detect_body.langCode == 'ko' ? 'ko':'en';
......@@ -110,14 +108,9 @@ function handleEvent(event) {
if(!error && response.statusCode == 200){
// JSON
var objBody = JSON.parse(response.body);
// Message 잘 찍히는지 확인
result.text = objBody.message.result.translatedText;
console.log(result.text);
//번역된 문장 보내기
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
//번역된 문자 audio로 저장
let audio_options={
'Text': result.text,
'OutputFormat': 'mp3',
'VoiceId':'Amy'
......@@ -137,12 +130,12 @@ function handleEvent(event) {
}
}
});
// Message 잘 찍히는지 확인
console.log(result.text);
//번역된 문장 보내기
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
}
});
}
// 메시지의 언어가 영어 또는 한국어가 아닐 경우
else{
......