Download audio file from Google Drive and get duration

Describe the problem/error/question

  • Download m4a file from Google drive (working)
  • Using this file to get duration of the audio file (not working)

What is the error message (if any)?

Please share your workflow

  • not sure what the best approach would be to get the duration of the audio file.
  • tried with music-metadata (npm package), but cannot get it work, as I need to provide the audio file and not the binary. (so if I could provide the temporary local storage, that might work already…not sure how to get that path)

Information on your n8n setup

  • n8n version: latest
  • Database (default: SQLite): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: docker

Hey @checkso,

Welcome to the community :cake:

I am not familiar with the package you are using but the docs for it suggests it can work with Buffers and Streams so it should be able to work with n8n data. Rather than using parseFile have you tried parseBuffer instead?

You could also use the write file node to save the file to a location you know then pass that into your code so you can use parseFile.

Hi @Jon,

thanks for the welcome and the quick help!

That was exactly the push in the correct direction I needed :slightly_smiling_face:

Got it working with the parsebuffer.

For anyone else looking for a solution, I’ll paste my code here:

const mm = require('music-metadata');

async function getAudioDuration(base64String, mimeType) {
    try {
        const buffer = Buffer.from(base64String, 'base64');
        const metadata = await mm.parseBuffer(buffer, mimeType);
        return metadata.format.duration;
    } catch (error) {
        console.error('Error in getAudioDuration:', error);

async function main() {
    const base64String = $('Google Drive');
    const mimeType = $('Google Drive');

    try {
        const duration = await getAudioDuration(base64String, mimeType);
        console.log('Duration:', duration);
        return { "duration": duration };
    } catch (error) {
        console.error('Error:', error);

return main();
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.