From 2f3afe2e9db6d4e3414faf14ba47f5e5a86de56f Mon Sep 17 00:00:00 2001 From: Huse Kivrak Date: Mon, 18 Nov 2024 16:51:03 -0500 Subject: [PATCH] chore: implemented music-metadata library for audio duration calculation --- actions/s3.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/actions/s3.ts b/actions/s3.ts index 95b21de..0087153 100644 --- a/actions/s3.ts +++ b/actions/s3.ts @@ -2,6 +2,7 @@ import { getUserProfile } from './auth'; import { ActionStatus } from '@/types/types'; +import { parseBuffer } from 'music-metadata'; import { S3Client, @@ -81,7 +82,8 @@ export async function uploadAudioToS3( } //calculate duration in seconds - const duration = audioBuffer.byteLength / 44100 / 2; + const metadata = await parseBuffer(new Uint8Array(audioBuffer)); + const duration = metadata.format.duration; return { status: 'success', message: 'uploaded to s3',