Showing
2 changed files
with
14 additions
and
15 deletions
| ... | @@ -57,6 +57,7 @@ | ... | @@ -57,6 +57,7 @@ |
| 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 | </task> | 61 | </task> |
| 61 | <servers /> | 62 | <servers /> |
| 62 | </component> | 63 | </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 | - | 10 | +app.use(express.static('public')); |
| 11 | //papago api | 11 | //papago api |
| 12 | var request = require('request'); | 12 | var request = require('request'); |
| 13 | 13 | ||
| ... | @@ -62,13 +62,13 @@ function handleEvent(event) { | ... | @@ -62,13 +62,13 @@ function handleEvent(event) { |
| 62 | return Promise.resolve(null); | 62 | return Promise.resolve(null); |
| 63 | } | 63 | } |
| 64 | return new Promise(function(resolve, reject) { | 64 | return new Promise(function(resolve, reject) { |
| 65 | + | ||
| 65 | //언어 감지 option | 66 | //언어 감지 option |
| 66 | var detect_options = { | 67 | var detect_options = { |
| 67 | url : languagedetect_api_url, | 68 | url : languagedetect_api_url, |
| 68 | form : {'query': event.message.text}, | 69 | form : {'query': event.message.text}, |
| 69 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} | 70 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} |
| 70 | }; | 71 | }; |
| 71 | - | ||
| 72 | //papago 언어 감지 | 72 | //papago 언어 감지 |
| 73 | request.post(detect_options,function(error,response,body){ | 73 | request.post(detect_options,function(error,response,body){ |
| 74 | console.log(response.statusCode); | 74 | console.log(response.statusCode); |
| ... | @@ -80,14 +80,20 @@ function handleEvent(event) { | ... | @@ -80,14 +80,20 @@ function handleEvent(event) { |
| 80 | var audio_sys = { | 80 | var audio_sys = { |
| 81 | "type": "audio", | 81 | "type": "audio", |
| 82 | "originalContentUrl": "https://panguin.ml/speech.m4a", | 82 | "originalContentUrl": "https://panguin.ml/speech.m4a", |
| 83 | - "duration": 60000 | 83 | + "duration": 24000 |
| 84 | }; | 84 | }; |
| 85 | //언어 감지가 제대로 됐는지 확인 | 85 | //언어 감지가 제대로 됐는지 확인 |
| 86 | console.log(detect_body.langCode); | 86 | console.log(detect_body.langCode); |
| 87 | + if(detect_options.form.query=='음성'){ | ||
| 88 | + console.log('audio streaming'); | ||
| 87 | 89 | ||
| 88 | - | 90 | + for_audio_client.replyAudio(event.replyToken,{ |
| 91 | + "originalContentUrl": "https://panguin.ml/public/speech.m4a", | ||
| 92 | + "duration": 24000 | ||
| 93 | + }).then(resolve).catch(reject); | ||
| 94 | + } | ||
| 89 | //번역은 한국어->영어 / 영어->한국어만 지원 | 95 | //번역은 한국어->영어 / 영어->한국어만 지원 |
| 90 | - if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){ | 96 | + else if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){ |
| 91 | source = detect_body.langCode == 'ko' ? 'ko':'en'; | 97 | source = detect_body.langCode == 'ko' ? 'ko':'en'; |
| 92 | target = source == 'ko' ? 'en':'ko'; | 98 | target = source == 'ko' ? 'en':'ko'; |
| 93 | //papago 번역 option | 99 | //papago 번역 option |
| ... | @@ -111,9 +117,10 @@ function handleEvent(event) { | ... | @@ -111,9 +117,10 @@ function handleEvent(event) { |
| 111 | //번역된 문장 보내기 | 117 | //번역된 문장 보내기 |
| 112 | client.replyMessage(event.replyToken,result).then(resolve).catch(reject); | 118 | client.replyMessage(event.replyToken,result).then(resolve).catch(reject); |
| 113 | let audio_options={ | 119 | let audio_options={ |
| 120 | + | ||
| 114 | 'Text': result.text, | 121 | 'Text': result.text, |
| 115 | 'OutputFormat': 'mp3', | 122 | 'OutputFormat': 'mp3', |
| 116 | - 'VoiceId':'Seoyeon' | 123 | + 'VoiceId':'Amy' |
| 117 | }; | 124 | }; |
| 118 | Polly.synthesizeSpeech(audio_options, (err, data) => { | 125 | Polly.synthesizeSpeech(audio_options, (err, data) => { |
| 119 | console.log("check"); | 126 | console.log("check"); |
| ... | @@ -126,21 +133,12 @@ function handleEvent(event) { | ... | @@ -126,21 +133,12 @@ function handleEvent(event) { |
| 126 | return console.log(err); | 133 | return console.log(err); |
| 127 | } | 134 | } |
| 128 | console.log("The file was saved!"); | 135 | console.log("The file was saved!"); |
| 129 | - if(!error && response.statusCode == 200){ | ||
| 130 | - console.log('audio streaming'); | ||
| 131 | - for_audio_client.replyAudio(event.replyToken,audio_sys).then(resolve).catch(reject); | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | - | ||
| 135 | }); | 136 | }); |
| 136 | } | 137 | } |
| 137 | } | 138 | } |
| 138 | }); | 139 | }); |
| 139 | 140 | ||
| 140 | } | 141 | } |
| 141 | - | ||
| 142 | - | ||
| 143 | - | ||
| 144 | }); | 142 | }); |
| 145 | 143 | ||
| 146 | 144 | ... | ... |
-
Please register or login to post a comment