JUMBOTURN
JUMBOTURN

Reputation: 69

How to fetch time duration of an audio file from database using nodejs?

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

Answers (1)

Adil Sher
Adil Sher

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

Related Questions