김수민

audio commit

...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
4 <list default="true" id="5c08ae96-2f87-46c1-b81d-f30e494ce252" name="Default Changelist" comment=""> 4 <list default="true" id="5c08ae96-2f87-46c1-b81d-f30e494ce252" name="Default Changelist" comment="">
5 <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> 5 <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6 <change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" /> 6 <change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
7 - <change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
8 - <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
9 </list> 7 </list>
10 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> 8 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
11 <option name="SHOW_DIALOG" value="false" /> 9 <option name="SHOW_DIALOG" value="false" />
...@@ -57,7 +55,8 @@ ...@@ -57,7 +55,8 @@
57 <workItem from="1573898557106" duration="89000" /> 55 <workItem from="1573898557106" duration="89000" />
58 <workItem from="1573899005304" duration="7410000" /> 56 <workItem from="1573899005304" duration="7410000" />
59 <workItem from="1574071758382" duration="6285000" /> 57 <workItem from="1574071758382" duration="6285000" />
60 - <workItem from="1574323490142" duration="7902000" /> 58 + <workItem from="1574323490142" duration="15840000" />
59 + <workItem from="1574342689824" duration="11000" />
61 </task> 60 </task>
62 <servers /> 61 <servers />
63 </component> 62 </component>
......
...@@ -37,7 +37,7 @@ const config = { ...@@ -37,7 +37,7 @@ const config = {
37 // create LINE SDK client 37 // create LINE SDK client
38 const client = new line.Client(config); 38 const client = new line.Client(config);
39 const for_audio_client=LineClient.connect({ 39 const for_audio_client=LineClient.connect({
40 - channelAccessToken: process.env.channelAccessToken, 40 + accessToken: process.env.channelAccessToken,
41 channelSecret: process.env.channelSecret, 41 channelSecret: process.env.channelSecret,
42 }); 42 });
43 // create Express app 43 // create Express app
...@@ -77,7 +77,11 @@ function handleEvent(event) { ...@@ -77,7 +77,11 @@ function handleEvent(event) {
77 var source = ''; 77 var source = '';
78 var target = ''; 78 var target = '';
79 var result = { type: 'text', text:''}; 79 var result = { type: 'text', text:''};
80 - 80 + var audio_sys = {
81 + "type": "audio",
82 + "originalContentUrl": "https://panguin.ml/speech.m4a",
83 + "duration": 60000
84 + };
81 //언어 감지가 제대로 됐는지 확인 85 //언어 감지가 제대로 됐는지 확인
82 console.log(detect_body.langCode); 86 console.log(detect_body.langCode);
83 87
...@@ -105,6 +109,7 @@ function handleEvent(event) { ...@@ -105,6 +109,7 @@ function handleEvent(event) {
105 result.text = objBody.message.result.translatedText; 109 result.text = objBody.message.result.translatedText;
106 console.log(result.text); 110 console.log(result.text);
107 //번역된 문장 보내기 111 //번역된 문장 보내기
112 + client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
108 let audio_options={ 113 let audio_options={
109 'Text': result.text, 114 'Text': result.text,
110 'OutputFormat': 'mp3', 115 'OutputFormat': 'mp3',
...@@ -116,26 +121,26 @@ function handleEvent(event) { ...@@ -116,26 +121,26 @@ function handleEvent(event) {
116 throw err; 121 throw err;
117 } else if (data) { 122 } else if (data) {
118 if (data.AudioStream instanceof Buffer) { 123 if (data.AudioStream instanceof Buffer) {
119 - fs.writeFile("./speech.mp3", data.AudioStream, function(err) { 124 + fs.writeFile("public/speech.m4a", data.AudioStream, function(err) {
120 if (err) { 125 if (err) {
121 return console.log(err); 126 return console.log(err);
122 } 127 }
123 console.log("The file was saved!"); 128 console.log("The file was saved!");
124 - }) 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 + });
125 } 136 }
126 } 137 }
127 }); 138 });
128 - request.post(audio_options, function (error,response,body) {
129 - if(!error && response.statusCode == 200){
130 - for_audio_client.replyAudio(event.replyToken,{
131 - originalContentUrl: 'https://panguin.ml/speech.mp3',
132 - duration: 240000
133 - }).then(resolve).catch(reject);
134 - }
135 - });
136 - client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
137 139
138 } 140 }
141 +
142 +
143 +
139 }); 144 });
140 145
141 146
......