Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[parse-transcript] fix: removing the first line is not necessary #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/tsToArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ export default function parseTranscript(vtt: string): ITranscriptLine[] {
// 1. separate lines by matching the format like "[00:03:04.000 --> 00:03:13.000] XXXXXX"
const lines: string[] = vtt.match(/\[[0-9:.]+\s-->\s[0-9:.]+\].*/g);

// 2. remove the first line, which is empty
lines.shift();

// 3. convert each line into an object
// 2. convert each line into an object
return lines.map(line => {
// 3a. split ts from speech
let [timestamp, speech] = line.split('] '); // two spaces (3 spaces doesn't work with punctuation like period . )
Expand All @@ -21,13 +18,13 @@ export default function parseTranscript(vtt: string): ITranscriptLine[] {

// 3c. split timestamp into begin and end
const [start, end] = timestamp.split(' --> ');

// 3d. remove \n from speech with regex
speech = speech.replace(/\n/g, '');

// 3e. remove beginning space
speech = speech.replace(' ', '');

return { start, end, speech };
});
}
}