Skip to content

Commit f00915c

Browse files
committed
修正拆分单词的问题
1 parent 90931f8 commit f00915c

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/components/Dialogs/split-word.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export const SplitWordDialog = memo(() => {
8383
const splittedDuration = duration / splittedWords.length;
8484
const newWords = splittedWords.map((w, i) => ({
8585
...newLyricWord(),
86-
startTime: startTime + splittedDuration * i,
87-
endTime: startTime + splittedDuration * (i + 1),
86+
startTime: (startTime + splittedDuration * i) | 0,
87+
endTime: (startTime + splittedDuration * (i + 1)) | 0,
8888
word: w,
8989
}));
9090
line.words.splice(splitState.wordIndex, 1, ...newWords);

src/utils/timestamp.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ export function parseTimespan(timeSpan: string): number {
2222
throw new TypeError(`时间戳字符串解析失败:${timeSpan}`);
2323
}
2424

25-
export function msToTimestamp(timeMS: number): string {
25+
export function msToTimestamp(timeMS: number, skipSafeCheck = false): string {
2626
let t = timeMS;
2727
if (t === Number.POSITIVE_INFINITY) {
2828
return "99:99.999";
2929
}
30-
if (!Number.isSafeInteger(t) || t < 0) {
30+
if (skipSafeCheck) {
31+
t = t | 0;
32+
} else if (!Number.isSafeInteger(t) || t < 0) {
3133
throw new Error(`Invalid timestamp: ${t}`);
3234
}
3335
t = timeMS / 1000;

src/utils/ttml-writer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
* 但是可能会有信息会丢失
1616
*/
1717

18-
import { msToTimestamp } from "./timestamp";
18+
import { msToTimestamp as origMsToTimestamp } from "./timestamp";
1919
import type { LyricLine, LyricWord, TTMLLyric } from "./ttml-types";
2020

21+
const msToTimestamp = (time: number) => origMsToTimestamp(time, true);
22+
2123
export default function exportTTMLText(
2224
ttmlLyric: TTMLLyric,
2325
pretty = false,

0 commit comments

Comments
 (0)