@aim-packages/subtitle 0.1.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1615 -1615
- package/dist/index.cjs.js +52 -49
- package/dist/index.d.ts +96 -3
- package/dist/index.es.js +1196 -1137
- package/package.json +33 -33
package/dist/index.d.ts
CHANGED
|
@@ -114,18 +114,31 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
114
114
|
* 1. 移除时间字符串末尾的毫秒部分(支持 .xxx、,xxx 等分隔符)
|
|
115
115
|
* 2. 移除时间字符串开头多余的 "00:" 小时前缀
|
|
116
116
|
* 3. 保持时间格式的简洁性和可读性
|
|
117
|
+
* 4. 支持数字(秒数)输入,自动转换为时间格式
|
|
117
118
|
*
|
|
118
119
|
* 示例:
|
|
119
120
|
* 输入:"00:01:30.500" -> 输出:"01:30"
|
|
120
121
|
* 输入:"01:45:20,123" -> 输出:"01:45:20"
|
|
121
122
|
* 输入:"00:00:05.00" -> 输出:"00:05"
|
|
122
123
|
* 输入:"01:30:45,50" -> 输出:"01:30:45"
|
|
124
|
+
* 输入:90(秒) -> 输出:"01:30"
|
|
125
|
+
* 输入:5(秒) -> 输出:"00:05"
|
|
126
|
+
* 输入:3665(秒) -> 输出:"01:01:05"
|
|
123
127
|
*
|
|
124
128
|
* @export
|
|
125
|
-
* @param {string}
|
|
129
|
+
* @param {string | number} timeInput - 输入的时间字符串或秒数
|
|
126
130
|
* @return {string} 清理后的时间字符串
|
|
127
131
|
*/
|
|
128
|
-
declare function cleanTimeDisplay(
|
|
132
|
+
declare function cleanTimeDisplay(timeInput: string | number): string;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 清除重复的项目并返回替换重复项目的字数
|
|
136
|
+
* @param s 要处理的片段
|
|
137
|
+
* @param start 开始位置
|
|
138
|
+
* @param count 要清除的数量
|
|
139
|
+
* @returns 被清除的重复文本长度
|
|
140
|
+
*/
|
|
141
|
+
declare function clearRepeatItems(s: AimSegments, start?: number, count?: number): number;
|
|
129
142
|
|
|
130
143
|
/**
|
|
131
144
|
* 合并字幕片段,优化字幕的时间轴
|
|
@@ -279,6 +292,27 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
279
292
|
*/
|
|
280
293
|
declare function detectAllLanguage(text: string): LanguageDetectionResultsEntry[];
|
|
281
294
|
|
|
295
|
+
/**
|
|
296
|
+
* 检测指定范围内被覆盖的子片段索引
|
|
297
|
+
* @param s 父片段
|
|
298
|
+
* @param start 开始位置
|
|
299
|
+
* @param end 结束位置
|
|
300
|
+
* @returns 被覆盖的子片段起始和结束索引
|
|
301
|
+
*/
|
|
302
|
+
declare function detectCoveredIndexByRange(s: AimSegments, start: number, end: number): {
|
|
303
|
+
start: number | undefined;
|
|
304
|
+
end: number | undefined;
|
|
305
|
+
} | undefined;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 检测文本在子片段数组中的覆盖索引
|
|
309
|
+
* 用于确定文本从哪个子片段开始被覆盖
|
|
310
|
+
* @param arr 子片段数组
|
|
311
|
+
* @param text 要检测的文本
|
|
312
|
+
* @returns 覆盖的索引位置
|
|
313
|
+
*/
|
|
314
|
+
declare function detectCoveredIndexByText(arr: AimSegments[] | undefined, text: string): number;
|
|
315
|
+
|
|
282
316
|
/**
|
|
283
317
|
* 检测文本的主要语言
|
|
284
318
|
* 使用 tinyld 库进行单语言检测,返回最可能的语言
|
|
@@ -300,6 +334,13 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
300
334
|
}
|
|
301
335
|
}
|
|
302
336
|
|
|
337
|
+
/**
|
|
338
|
+
* 查找最频繁出现的片段
|
|
339
|
+
* @param segments 片段数组
|
|
340
|
+
* @returns 出现频率最高的片段
|
|
341
|
+
*/
|
|
342
|
+
declare function findMostFrequentSegment(segments: AimSegments[]): AimSegments | undefined;
|
|
343
|
+
|
|
303
344
|
/**
|
|
304
345
|
* 查找文本中重复子串的位置
|
|
305
346
|
* @param text 要搜索的文本
|
|
@@ -369,6 +410,25 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
369
410
|
probability: number;
|
|
370
411
|
}
|
|
371
412
|
|
|
413
|
+
/**
|
|
414
|
+
* 将片段数组中指定范围的连续片段合并成一个片段
|
|
415
|
+
*
|
|
416
|
+
* 作用:
|
|
417
|
+
* 1. 将数组中指定索引范围内的连续片段合并为一个片段
|
|
418
|
+
* 2. 使用 joinAimSegmentItems 来合并片段及其 children
|
|
419
|
+
* 3. 返回新的数组,不修改原数组
|
|
420
|
+
*
|
|
421
|
+
* 示例:
|
|
422
|
+
* 输入:segments = [seg1, seg2, seg3, seg4], start = 1, end = 2
|
|
423
|
+
* 输出:[seg1, mergedSeg(seg2+seg3), seg4]
|
|
424
|
+
*
|
|
425
|
+
* @param segments 输入的片段数组
|
|
426
|
+
* @param start 要合并的开始索引(包含)
|
|
427
|
+
* @param end 要合并的结束索引(包含)
|
|
428
|
+
* @returns 合并后的新数组,如果索引无效或合并失败则返回原数组的副本
|
|
429
|
+
*/
|
|
430
|
+
declare function mergeAimSegmentRange(segments: AimSegments[], start: number, end: number): AimSegments[];
|
|
431
|
+
|
|
372
432
|
declare interface OpenAIResult {
|
|
373
433
|
task: string;
|
|
374
434
|
language: string;
|
|
@@ -444,6 +504,16 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
444
504
|
result?: R;
|
|
445
505
|
}
|
|
446
506
|
|
|
507
|
+
export declare type ParsedSubtitle = {
|
|
508
|
+
hasMultiLang: boolean;
|
|
509
|
+
firstLanguageMap: Record<string, number>;
|
|
510
|
+
secondLanguageMap: Record<string, number>;
|
|
511
|
+
multiLanguageCount: number;
|
|
512
|
+
firstSegments: AimSegments[];
|
|
513
|
+
secondSegments: AimSegments[];
|
|
514
|
+
segments: AimSegments[];
|
|
515
|
+
};
|
|
516
|
+
|
|
447
517
|
/**
|
|
448
518
|
* Parser parser instance.
|
|
449
519
|
*
|
|
@@ -479,6 +549,7 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
479
549
|
tingwuToAimSegments,
|
|
480
550
|
openaiToAimSegments,
|
|
481
551
|
whisperJsonToAimSegments,
|
|
552
|
+
parseSubtitle,
|
|
482
553
|
create as createWhisperStreamParser,
|
|
483
554
|
create_2 as createTranslateStreamParser,
|
|
484
555
|
create_3 as createSegmentStreamParser
|
|
@@ -505,8 +576,16 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
505
576
|
onEnd?: ParseCallback<E, R>;
|
|
506
577
|
};
|
|
507
578
|
|
|
579
|
+
declare function parseSubtitle(text: string): Promise<ParsedSubtitle | undefined>;
|
|
580
|
+
|
|
508
581
|
export declare type PartialByKey<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
509
582
|
|
|
583
|
+
/**
|
|
584
|
+
* 刷新片段的属性,根据子片段重新计算父片段的属性
|
|
585
|
+
* @param s 要刷新的片段
|
|
586
|
+
*/
|
|
587
|
+
declare function refreshItems(s: AimSegments): void;
|
|
588
|
+
|
|
510
589
|
/**
|
|
511
590
|
* 重复内容检测器
|
|
512
591
|
*
|
|
@@ -553,6 +632,13 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
553
632
|
onHit?: (segment: AimSegments[]) => void;
|
|
554
633
|
}
|
|
555
634
|
|
|
635
|
+
/**
|
|
636
|
+
* 处理重复项,将重复的片段合并为一个片段
|
|
637
|
+
* @param s 重复的片段数组
|
|
638
|
+
* @returns 合并后的片段,使用最频繁的文本内容
|
|
639
|
+
*/
|
|
640
|
+
declare function repeatItems(s: AimSegments[]): AimSegments | undefined;
|
|
641
|
+
|
|
556
642
|
export declare type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
557
643
|
|
|
558
644
|
export declare type Segment = {
|
|
@@ -743,7 +829,14 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
743
829
|
chunkSegmentStringsWithIndex,
|
|
744
830
|
consolidateSegments,
|
|
745
831
|
joinAimSegmentItems,
|
|
746
|
-
|
|
832
|
+
mergeAimSegmentRange,
|
|
833
|
+
shiftAimSegmentItems,
|
|
834
|
+
detectCoveredIndexByText,
|
|
835
|
+
detectCoveredIndexByRange,
|
|
836
|
+
findMostFrequentSegment,
|
|
837
|
+
repeatItems,
|
|
838
|
+
refreshItems,
|
|
839
|
+
clearRepeatItems
|
|
747
840
|
}
|
|
748
841
|
}
|
|
749
842
|
|