Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김승찬
/
LINEBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김수민
2019-11-23 18:04:31 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8057cf9a3bad4a610761d1e9ac3fa95e909edbec
8057cf9a
1 parent
2504fc6a
오디오 수정
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
19 deletions
.idea/workspace.xml
app.js
.idea/workspace.xml
View file @
8057cf9
...
...
@@ -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>
...
...
app.js
View file @
8057cf9
...
...
@@ -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
{
...
...
Please
register
or
login
to post a comment