Reputation: 69
I am new to nodejs . I create some content based on nodejs . I upload audio files and store it in my mongodb. But I want when I fetch data from mongodb ,it find the audio file time duration(how much time contain that audio file) and show me the file name ,image and time duration of that audio file. But I have no idea about it how to find time duration of that file and show to user audio file ,image with time duration. can any one give me a suggestion about it, and sample code for this type of senario.
Upvotes: 1
Views: 3603
Reputation: 31
You can achieve it by using this package
For Windows:
npm install --save get-audio-duration
Usage:
const { getAudioDurationInSeconds } = require('get-audio-duration')
// From a local path...
getAudioDurationInSeconds('audio.flac').then((duration) => {
console.log(duration)
})
// From a readable stream...
const fs = require('fs')
const stream = fs.createReadStream('audio.flac')
getAudioDurationInSeconds(stream).then((duration) => {
console.log(duration)
})
Upvotes: 3