Skip to content

Instantly share code, notes, and snippets.

@nelsondev19
Created June 6, 2023 17:43
Show Gist options
  • Select an option

  • Save nelsondev19/dc7bedf1b4bdf9aec5d047c70ef63d55 to your computer and use it in GitHub Desktop.

Select an option

Save nelsondev19/dc7bedf1b4bdf9aec5d047c70ef63d55 to your computer and use it in GitHub Desktop.
Function for convert time position from captions to time clock format | Whisper model captions
// OUTPUT FROM WHISPER CAPTIONS
/*
const captions = [
{
"start": 22.64,
"end": 29.080000000000002,
"text": " rolas en el top 10, hubo un tiempo que tenía en Spotify las 5"
}
]
*/
// FUNCTION FOR CONVERT AUDIO POSITION TO TIME 22.64 -> 00:22:64
export function convertSecondsToTime(totalSeconds: number): string {
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
if (hours === 0) {
return `${minutes < 10 ? "0" + minutes : minutes}:${seconds < 10
? "0" + parseFloat(seconds.toFixed(2))
: parseFloat(seconds.toFixed(2))
}`;
}
return `${hours < 10 ? "0" + hours : hours}:${minutes < 10 ? "0" + minutes : minutes
}:${seconds < 10 ? "0" + seconds : seconds}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment