Created
June 6, 2023 17:43
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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