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
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김수민
2019-12-02 18:38:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a48452998260987888460828b8d59fa32d27dd1c
a4845299
1 parent
fe8ceb95
audio language
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
87 deletions
.idea/workspace.xml
app.js
.idea/workspace.xml
View file @
a484529
...
...
@@ -61,6 +61,10 @@
<workItem
from=
"1574494473410"
duration=
"2577000"
/>
<workItem
from=
"1574565997693"
duration=
"30000"
/>
<workItem
from=
"1574569996051"
duration=
"559000"
/>
<workItem
from=
"1574579419218"
duration=
"794000"
/>
<workItem
from=
"1574662422550"
duration=
"816000"
/>
<workItem
from=
"1574669792266"
duration=
"65000"
/>
<workItem
from=
"1574670031852"
duration=
"24000"
/>
</task>
<servers
/>
</component>
...
...
app.js
View file @
a484529
...
...
@@ -98,104 +98,104 @@ function handleEvent(event) {
})
})
}
// 번역 기능 & 음성 기능
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
);
if
(
!
error
&&
response
.
statusCode
==
200
){
var
detect_body
=
JSON
.
parse
(
response
.
body
);
var
source
=
''
;
var
target
=
''
;
var
result
=
{
type
:
'text'
,
text
:
''
};
//언어 감지가 제대로 됐는지 확인
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/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'
;
target
=
source
==
'ko'
?
'en'
:
'ko'
;
//papago 번역 option
var
options
=
{
url
:
translate_api_url
,
// 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
form
:
{
'source'
:
source
,
'target'
:
target
,
'text'
:
event
.
message
.
text
},
else
{
// 번역 기능 & 음성 기능
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
}
};
// Naver Post API
request
.
post
(
options
,
function
(
error
,
response
,
body
){
// Translate API Sucess
if
(
!
error
&&
response
.
statusCode
==
200
){
// JSON
var
objBody
=
JSON
.
parse
(
response
.
body
);
result
.
text
=
objBody
.
message
.
result
.
translatedText
;
//번역된 문자 audio로 저장
if
(
options
.
form
.
target
==
'ko'
){
let
audio_options
=
{
'Text'
:
result
.
text
,
'OutputFormat'
:
'mp3'
,
'VoiceId'
:
'Amy'
,
"LanguageCode"
:
'ko-KR'
};
//papago 언어 감지
request
.
post
(
detect_options
,
function
(
error
,
response
,
body
)
{
console
.
log
(
response
.
statusCode
);
if
(
!
error
&&
response
.
statusCode
==
200
)
{
var
detect_body
=
JSON
.
parse
(
response
.
body
);
var
source
=
''
;
var
target
=
''
;
var
result
=
{
type
:
'text'
,
text
:
''
};
//언어 감지가 제대로 됐는지 확인
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/speech.m4a"
,
"duration"
:
24000
}).
then
(
resolve
).
catch
(
reject
);
}
}
else
if
(
options
.
form
.
target
==
'en'
){
let
audio_options
=
{
'Text'
:
result
.
text
,
'OutputFormat'
:
'mp3'
,
'VoiceId'
:
'Amy'
,
"LanguageCode"
:
'en-US'
//번역은 한국어->영어 / 영어->한국어만 지원
else
if
(
detect_body
.
langCode
==
'ko'
||
detect_body
.
langCode
==
'en'
)
{
source
=
detect_body
.
langCode
==
'ko'
?
'ko'
:
'en'
;
target
=
source
==
'ko'
?
'en'
:
'ko'
;
//papago 번역 option
var
options
=
{
url
:
translate_api_url
,
// 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
form
:
{
'source'
:
source
,
'target'
:
target
,
'text'
:
event
.
message
.
text
},
headers
:
{
'X-Naver-Client-Id'
:
client_id
,
'X-Naver-Client-Secret'
:
client_secret
}
};
}
Polly
.
synthesizeSpeech
(
audio_options
,
(
err
,
data
)
=>
{
console
.
log
(
"check"
);
if
(
err
)
{
throw
err
;
}
else
if
(
data
)
{
if
(
data
.
AudioStream
instanceof
Buffer
)
{
fs
.
writeFile
(
"public/speech.m4a"
,
data
.
AudioStream
,
function
(
err
)
{
// Naver Post API
request
.
post
(
options
,
function
(
error
,
response
,
body
)
{
// Translate API Sucess
if
(
!
error
&&
response
.
statusCode
==
200
)
{
// JSON
var
objBody
=
JSON
.
parse
(
response
.
body
);
result
.
text
=
objBody
.
message
.
result
.
translatedText
;
//번역된 문자 audio로 저장
if
(
options
.
form
.
target
==
'ko'
)
{
var
audio_options
=
{
'Text'
:
result
.
text
,
'OutputFormat'
:
'mp3'
,
'VoiceId'
:
'Seoyeon'
,
"LanguageCode"
:
'ko-KR'
};
}
else
if
(
options
.
form
.
target
==
'en'
)
{
var
audio_options
=
{
'Text'
:
result
.
text
,
'OutputFormat'
:
'mp3'
,
'VoiceId'
:
'Kendra'
,
"LanguageCode"
:
'en-US'
};
}
Polly
.
synthesizeSpeech
(
audio_options
,
(
err
,
data
)
=>
{
console
.
log
(
"check"
);
if
(
err
)
{
return
console
.
log
(
err
);
throw
err
;
}
else
if
(
data
)
{
if
(
data
.
AudioStream
instanceof
Buffer
)
{
fs
.
writeFile
(
"public/speech.m4a"
,
data
.
AudioStream
,
function
(
err
)
{
if
(
err
)
{
return
console
.
log
(
err
);
}
console
.
log
(
"The file was saved!"
);
});
}
}
console
.
log
(
"The file was saved!"
);
});
// Message 잘 찍히는지 확인
console
.
log
(
result
.
text
);
//번역된 문장 보내기
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
}
}
});
// Message 잘 찍히는지 확인
console
.
log
(
result
.
text
);
//번역된 문장 보내기
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
}
});
}
// 메시지의 언어가 영어 또는 한국어가 아닐 경우
else
{
result
.
text
=
'언어를 감지할 수 없습니다. \n 번역 언어는 한글 또는 영어만 가능합니다.'
;
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
}
});
}
// 메시지의 언어가 영어 또는 한국어가 아닐 경우
else
{
result
.
text
=
'언어를 감지할 수 없습니다. \n 번역 언어는 한글 또는 영어만 가능합니다.'
;
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
}
}
}
});
});
});
});
}
}
app
.
listen
(
80
,
function
()
{
...
...
Please
register
or
login
to post a comment