Skip to content

Commit

Permalink
chore: implemented music-metadata library for audio duration calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
huseKivrak committed Nov 18, 2024
1 parent 765e800 commit 2f3afe2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion actions/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { getUserProfile } from './auth';
import { ActionStatus } from '@/types/types';
import { parseBuffer } from 'music-metadata';

import {
S3Client,
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 2f3afe2

Please sign in to comment.