김수민

오디오 수정

...@@ -57,7 +57,8 @@ ...@@ -57,7 +57,8 @@
57 <workItem from="1574071758382" duration="6285000" /> 57 <workItem from="1574071758382" duration="6285000" />
58 <workItem from="1574323490142" duration="15840000" /> 58 <workItem from="1574323490142" duration="15840000" />
59 <workItem from="1574342689824" duration="11000" /> 59 <workItem from="1574342689824" duration="11000" />
60 - <workItem from="1574396813813" duration="6958000" /> 60 + <workItem from="1574396813813" duration="10012000" />
61 + <workItem from="1574494473410" duration="2577000" />
61 </task> 62 </task>
62 <servers /> 63 <servers />
63 </component> 64 </component>
......
...@@ -7,7 +7,7 @@ require("dotenv").config({path : '.env'}); ...@@ -7,7 +7,7 @@ require("dotenv").config({path : '.env'});
7 var express = require('express'); 7 var express = require('express');
8 var app = express(); 8 var app = express();
9 const line = require('@line/bot-sdk'); 9 const line = require('@line/bot-sdk');
10 -app.use(express.static('public')); 10 +
11 //papago api 11 //papago api
12 var request = require('request'); 12 var request = require('request');
13 13
...@@ -45,6 +45,7 @@ const for_audio_client=LineClient.connect({ ...@@ -45,6 +45,7 @@ const for_audio_client=LineClient.connect({
45 45
46 // register a webhook handler with middleware 46 // register a webhook handler with middleware
47 // about the middleware, please refer to doc 47 // about the middleware, please refer to doc
48 +app.use(express.static('public'));
48 app.post('/webhook', line.middleware(config), (req, res) => { 49 app.post('/webhook', line.middleware(config), (req, res) => {
49 Promise 50 Promise
50 .all(req.body.events.map(handleEvent)) 51 .all(req.body.events.map(handleEvent))
...@@ -77,21 +78,18 @@ function handleEvent(event) { ...@@ -77,21 +78,18 @@ function handleEvent(event) {
77 var source = ''; 78 var source = '';
78 var target = ''; 79 var target = '';
79 var result = { type: 'text', text:''}; 80 var result = { type: 'text', text:''};
80 - var audio_sys = {
81 - "type": "audio",
82 - "originalContentUrl": "https://panguin.ml/speech.m4a",
83 - "duration": 24000
84 - };
85 //언어 감지가 제대로 됐는지 확인 81 //언어 감지가 제대로 됐는지 확인
86 console.log(detect_body.langCode); 82 console.log(detect_body.langCode);
87 if(detect_options.form.query=='음성'){ 83 if(detect_options.form.query=='음성'){
88 console.log('audio streaming'); 84 console.log('audio streaming');
89 - 85 + if (!error && response.statusCode == 200){
86 + console.log(response.statusCode);
90 for_audio_client.replyAudio(event.replyToken,{ 87 for_audio_client.replyAudio(event.replyToken,{
91 - "originalContentUrl": "https://panguin.ml/public/speech.m4a", 88 + "originalContentUrl": "https://panguin.ml/speech.m4a",
92 "duration": 24000 89 "duration": 24000
93 }).then(resolve).catch(reject); 90 }).then(resolve).catch(reject);
94 } 91 }
92 + }
95 //번역은 한국어->영어 / 영어->한국어만 지원 93 //번역은 한국어->영어 / 영어->한국어만 지원
96 else if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){ 94 else if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){
97 source = detect_body.langCode == 'ko' ? 'ko':'en'; 95 source = detect_body.langCode == 'ko' ? 'ko':'en';
...@@ -110,14 +108,9 @@ function handleEvent(event) { ...@@ -110,14 +108,9 @@ function handleEvent(event) {
110 if(!error && response.statusCode == 200){ 108 if(!error && response.statusCode == 200){
111 // JSON 109 // JSON
112 var objBody = JSON.parse(response.body); 110 var objBody = JSON.parse(response.body);
113 - // Message 잘 찍히는지 확인
114 -
115 result.text = objBody.message.result.translatedText; 111 result.text = objBody.message.result.translatedText;
116 - console.log(result.text); 112 + //번역된 문자 audio로 저장
117 - //번역된 문장 보내기
118 - client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
119 let audio_options={ 113 let audio_options={
120 -
121 'Text': result.text, 114 'Text': result.text,
122 'OutputFormat': 'mp3', 115 'OutputFormat': 'mp3',
123 'VoiceId':'Amy' 116 'VoiceId':'Amy'
...@@ -137,12 +130,12 @@ function handleEvent(event) { ...@@ -137,12 +130,12 @@ function handleEvent(event) {
137 } 130 }
138 } 131 }
139 }); 132 });
140 - 133 + // Message 잘 찍히는지 확인
134 + console.log(result.text);
135 + //번역된 문장 보내기
136 + client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
141 } 137 }
142 }); 138 });
143 -
144 -
145 -
146 } 139 }
147 // 메시지의 언어가 영어 또는 한국어가 아닐 경우 140 // 메시지의 언어가 영어 또는 한국어가 아닐 경우
148 else{ 141 else{
......