김수민

audio commit

......@@ -4,8 +4,6 @@
<list default="true" id="5c08ae96-2f87-46c1-b81d-f30e494ce252" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -57,7 +55,8 @@
<workItem from="1573898557106" duration="89000" />
<workItem from="1573899005304" duration="7410000" />
<workItem from="1574071758382" duration="6285000" />
<workItem from="1574323490142" duration="7902000" />
<workItem from="1574323490142" duration="15840000" />
<workItem from="1574342689824" duration="11000" />
</task>
<servers />
</component>
......
......@@ -37,7 +37,7 @@ const config = {
// create LINE SDK client
const client = new line.Client(config);
const for_audio_client=LineClient.connect({
channelAccessToken: process.env.channelAccessToken,
accessToken: process.env.channelAccessToken,
channelSecret: process.env.channelSecret,
});
// create Express app
......@@ -77,7 +77,11 @@ function handleEvent(event) {
var source = '';
var target = '';
var result = { type: 'text', text:''};
var audio_sys = {
"type": "audio",
"originalContentUrl": "https://panguin.ml/speech.m4a",
"duration": 60000
};
//언어 감지가 제대로 됐는지 확인
console.log(detect_body.langCode);
......@@ -105,6 +109,7 @@ function handleEvent(event) {
result.text = objBody.message.result.translatedText;
console.log(result.text);
//번역된 문장 보내기
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
let audio_options={
'Text': result.text,
'OutputFormat': 'mp3',
......@@ -116,26 +121,26 @@ function handleEvent(event) {
throw err;
} else if (data) {
if (data.AudioStream instanceof Buffer) {
fs.writeFile("./speech.mp3", data.AudioStream, function(err) {
fs.writeFile("public/speech.m4a", data.AudioStream, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
})
if(!error && response.statusCode == 200){
console.log('audio streaming');
for_audio_client.replyAudio(event.replyToken,audio_sys).then(resolve).catch(reject);
}
});
}
}
});
request.post(audio_options, function (error,response,body) {
if(!error && response.statusCode == 200){
for_audio_client.replyAudio(event.replyToken,{
originalContentUrl: 'https://panguin.ml/speech.mp3',
duration: 240000
}).then(resolve).catch(reject);
}
});
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
}
});
......