Skip to content

Commit 48c508e

Browse files
kamnan43Hyunje Jun
authored andcommitted
get actual audio duration (#68)
* get actual audio duration * add get-audio-duration dependency to package.json
1 parent 8fc4dfb commit 48c508e

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

examples/kitchensink/index.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,21 @@ function handleAudio(message, replyToken) {
315315

316316
return downloadContent(message.id, downloadPath)
317317
.then((downloadPath) => {
318-
return client.replyMessage(
319-
replyToken,
320-
{
321-
type: 'audio',
322-
originalContentUrl: baseURL + '/downloaded/' + path.basename(downloadPath),
323-
duration: 1000,
324-
}
325-
);
318+
var getDuration = require('get-audio-duration');
319+
var audioDuration;
320+
getDuration(downloadPath)
321+
.then((duration) => { audioDuration = duration; })
322+
.catch((error) => { audioDuration = 1; })
323+
.finally(() => {
324+
return client.replyMessage(
325+
replyToken,
326+
{
327+
type: 'audio',
328+
originalContentUrl: baseURL + '/downloaded/' + path.basename(downloadPath),
329+
duration: audioDuration * 1000,
330+
}
331+
);
332+
});
326333
});
327334
}
328335

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"@types/node": "^7.0.31",
4343
"axios": "^0.16.2",
4444
"body-parser": "^1.18.2",
45-
"file-type": "^7.2.0"
45+
"file-type": "^7.2.0",
46+
"get-audio-duration": "0.0.1"
4647
},
4748
"devDependencies": {
4849
"@types/express": "^4.0.35",

0 commit comments

Comments
 (0)