Created
June 17, 2023 05:20
-
-
Save guiseek/1a7035e0e01c27dfbe150e8b7b588754 to your computer and use it in GitHub Desktop.
Youtube subtitles to text
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
const subtitle = segToSub(subtitles.events); | |
console.log(subtitle); |
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
function segToSub(segments: SubtitleEvent[], withTime: false): string[]; | |
function segToSub(segments: SubtitleEvent[], withTime: true): SubtitleTimed[]; | |
function segToSub(segments: SubtitleEvent[], withTime = false) { | |
return segments.map(({ tStartMs, dDurationMs, segs = [] }) => { | |
return withTime | |
? { | |
start: tStartMs, | |
duration: dDurationMs, | |
text: segs.map((seg) => seg.utf8).join(''), | |
} | |
: segs.map((seg) => seg.utf8).join(''); | |
}); | |
} |
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
export interface Subtitles { | |
wireMagic: string; | |
pens: Pen[]; | |
wsWinStyles: WsWinStyle[]; | |
wpWinPositions: WpWinPosition[]; | |
events: SubtitleEvent[]; | |
} | |
export interface SubtitleEvent { | |
tStartMs: number; | |
dDurationMs?: number; | |
id?: number; | |
wpWinPosId?: number; | |
wsWinStyleId?: number; | |
wWinId?: number; | |
segs?: Seg[]; | |
aAppend?: number; | |
} | |
export interface Seg { | |
utf8: string; | |
acAsrConf?: number; | |
tOffsetMs?: number; | |
} | |
export interface Pen {} | |
export interface WpWinPosition { | |
apPoint?: number; | |
ahHorPos?: number; | |
avVerPos?: number; | |
rcRows?: number; | |
ccCols?: number; | |
} | |
export interface WsWinStyle { | |
mhModeHint?: number; | |
juJustifCode?: number; | |
sdScrollDir?: number; | |
} | |
interface SubtitleTimed { | |
start: number; | |
duration: number; | |
text: string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment