@aim-packages/subtitle 0.1.3 → 0.1.4
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 +57 -57
- package/dist/index.d.ts +67 -9
- package/dist/index.es.js +1189 -1217
- package/package.json +33 -33
package/dist/index.d.ts
CHANGED
|
@@ -222,15 +222,41 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
222
222
|
*
|
|
223
223
|
* @returns A new Parser parser, with `parse`, `end` and `reset` methods.
|
|
224
224
|
* @public
|
|
225
|
+
*
|
|
226
|
+
* Whisper字幕解析器
|
|
227
|
+
*
|
|
228
|
+
* 用于解析Whisper模型输出的字幕格式,支持VAD(Voice Activity Detection)时间调整
|
|
229
|
+
* 输入格式示例:
|
|
230
|
+
* [00:00:00.000 --> 00:00:03.000] 这是第一句话
|
|
231
|
+
* [00:00:03.000 --> 00:00:06.000] 这是第二句话
|
|
232
|
+
* [--Single--] // 单个文件结束标记
|
|
233
|
+
* [--Full--] // 所有文件结束标记
|
|
234
|
+
* [--end--] // 解析结束标记
|
|
235
|
+
*
|
|
236
|
+
* @param options - 解析器配置选项
|
|
237
|
+
* @param options.vad - VAD时间片段数组,用于调整字幕时间戳
|
|
238
|
+
* @param options.vadPadding - VAD时间调整的填充值 [前填充, 后填充],默认 [0.4, 0]
|
|
239
|
+
* @returns 返回一个Parser实例,包含feed、reset、end方法
|
|
225
240
|
*/
|
|
226
|
-
declare function create(options?: ParserOptions<AimSegments[], AimSegments[], string> & {
|
|
241
|
+
declare function create(options?: ParserOptions<AimSegments[], AimSegments[], string, AimSegments[]> & {
|
|
227
242
|
vad?: Segment[];
|
|
228
243
|
vadPadding?: [number, number];
|
|
229
244
|
}): Parser<string>;
|
|
230
245
|
|
|
231
|
-
declare function create_2(options?: ParserOptions<RequiredByKey<Partial<AimSegments>, "index">[], Partial<AimSegments>[], string>): Parser<string>;
|
|
246
|
+
declare function create_2(options?: ParserOptions<RequiredByKey<Partial<AimSegments>, "index">[], Partial<AimSegments>[], string, RequiredByKey<Partial<AimSegments>, "index">[]>): Parser<string>;
|
|
232
247
|
|
|
233
|
-
|
|
248
|
+
/**
|
|
249
|
+
* 创建字幕分段解析器
|
|
250
|
+
* 主要功能:
|
|
251
|
+
* 1. 将输入的字幕片段按句子长度进行分组
|
|
252
|
+
* 2. 检测和处理重复内容
|
|
253
|
+
* 3. 支持多语言分句
|
|
254
|
+
* 4. 流式处理字幕数据
|
|
255
|
+
*
|
|
256
|
+
* @param options 解析器配置选项
|
|
257
|
+
* @returns 解析器实例
|
|
258
|
+
*/
|
|
259
|
+
declare function create_3(options?: ParserOptions<AimSegments[], AimSegments[], AimSegments[], AimSegments[]> & {
|
|
234
260
|
sentenceLength?: number;
|
|
235
261
|
repeatString?: string[];
|
|
236
262
|
}): Parser<AimSegments[]>;
|
|
@@ -274,6 +300,18 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
274
300
|
}
|
|
275
301
|
}
|
|
276
302
|
|
|
303
|
+
/**
|
|
304
|
+
* 查找文本中重复子串的位置
|
|
305
|
+
* @param text 要搜索的文本
|
|
306
|
+
* @param substring 要查找的重复子串
|
|
307
|
+
* @returns 重复子串在文本中的位置数组
|
|
308
|
+
*/
|
|
309
|
+
declare function findRepeatedSubstringPositions(text: string, substring: string): {
|
|
310
|
+
start: number;
|
|
311
|
+
end: number;
|
|
312
|
+
match: string;
|
|
313
|
+
}[];
|
|
314
|
+
|
|
277
315
|
/**
|
|
278
316
|
* 将秒数转换为 xx:xx:xx.xxx 格式
|
|
279
317
|
*
|
|
@@ -285,6 +323,13 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
285
323
|
|
|
286
324
|
export declare type ISegment = [string, string, string, string | undefined];
|
|
287
325
|
|
|
326
|
+
/**
|
|
327
|
+
* 将多个子片段合并成一个片段
|
|
328
|
+
* @param s 要合并的子片段数组
|
|
329
|
+
* @returns 合并后的片段
|
|
330
|
+
*/
|
|
331
|
+
declare function joinAimSegmentItems(s: AimSegments[]): AimSegments | undefined;
|
|
332
|
+
|
|
288
333
|
export declare type LanguageCode = "auto" | "none" | "zh" | "zh_cn" | "zh_tw" | "yue" | "en" | "ja" | "ko" | "fr" | "es" | "ru" | "de" | "it" | "tr" | "pt" | "vi" | "id" | "th" | "ms" | "ar" | "hi" | "ro" | "ug" | "uz" | "kk" | "az" | "ky" | "fa" | "tg";
|
|
289
334
|
|
|
290
335
|
/**
|
|
@@ -375,12 +420,13 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
375
420
|
*
|
|
376
421
|
* @public
|
|
377
422
|
*/
|
|
378
|
-
declare type ParseCallback<T> = (event: ParsedEvent<T>) => void;
|
|
423
|
+
declare type ParseCallback<T, R = never> = (event: ParsedEvent<T, R>) => void;
|
|
379
424
|
|
|
380
|
-
declare interface ParsedEvent<T> {
|
|
425
|
+
declare interface ParsedEvent<T, R = never> {
|
|
381
426
|
type: "event";
|
|
382
427
|
event: "start" | "message" | "end";
|
|
383
428
|
data?: T;
|
|
429
|
+
result?: R;
|
|
384
430
|
}
|
|
385
431
|
|
|
386
432
|
/**
|
|
@@ -429,17 +475,18 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
429
475
|
* @template S - 解析开始时的状态类型
|
|
430
476
|
* @template P - 解析过程中使用的状态类型
|
|
431
477
|
* @template E - 解析结束时的状态类型
|
|
478
|
+
* @template R - 解析结果类型(用于 onEnd 回调)
|
|
432
479
|
*
|
|
433
480
|
* @property {ParseCallback<S>} [onStart] - 解析开始时的回调函数
|
|
434
481
|
* @property {ParseCallback<P>} [onParse] - 解析过程中调用的回调函数
|
|
435
482
|
* @property {ParseCallback<P>} [onProgress] - 解析进度更新时的回调函数
|
|
436
|
-
* @property {ParseCallback<E>} [onEnd] - 解析结束时的回调函数
|
|
483
|
+
* @property {ParseCallback<E, R>} [onEnd] - 解析结束时的回调函数
|
|
437
484
|
*/
|
|
438
|
-
declare type ParserOptions<S, P, E> = {
|
|
485
|
+
declare type ParserOptions<S, P, E, R = never> = {
|
|
439
486
|
onStart?: ParseCallback<S>;
|
|
440
487
|
onParse?: ParseCallback<P>;
|
|
441
488
|
onProgress?: ParseCallback<P>;
|
|
442
|
-
onEnd?: ParseCallback<E>;
|
|
489
|
+
onEnd?: ParseCallback<E, R>;
|
|
443
490
|
};
|
|
444
491
|
|
|
445
492
|
export declare type PartialByKey<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -497,6 +544,14 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
497
544
|
end: number;
|
|
498
545
|
};
|
|
499
546
|
|
|
547
|
+
/**
|
|
548
|
+
* 从片段中移除指定数量的子项
|
|
549
|
+
* @param segment 父片段
|
|
550
|
+
* @param count 要移除的子项数量
|
|
551
|
+
* @returns 被移除的子项合并后的新片段
|
|
552
|
+
*/
|
|
553
|
+
declare function shiftAimSegmentItems(segment: AimSegments, count?: number): AimSegments | undefined;
|
|
554
|
+
|
|
500
555
|
export declare interface SpeakerData {
|
|
501
556
|
settings: Record<string, {
|
|
502
557
|
spk: string;
|
|
@@ -661,6 +716,7 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
661
716
|
formatTime,
|
|
662
717
|
convertToSeconds,
|
|
663
718
|
cleanTimeDisplay,
|
|
719
|
+
findRepeatedSubstringPositions,
|
|
664
720
|
containsCJKCharacters,
|
|
665
721
|
languageCodeToName,
|
|
666
722
|
convertHexColorToAssFormat,
|
|
@@ -668,7 +724,9 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
668
724
|
convertHexColorToFFmpegFormat,
|
|
669
725
|
chunkArrayStrings,
|
|
670
726
|
chunkSegmentStringsWithIndex,
|
|
671
|
-
consolidateSegments
|
|
727
|
+
consolidateSegments,
|
|
728
|
+
joinAimSegmentItems,
|
|
729
|
+
shiftAimSegmentItems
|
|
672
730
|
}
|
|
673
731
|
}
|
|
674
732
|
|