@aim-packages/subtitle 0.1.0 → 0.1.1
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 +344 -2
- package/dist/index.cjs.js +63 -13
- package/dist/index.d.ts +140 -1
- package/dist/index.es.js +1076 -945
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -137,6 +137,54 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
137
137
|
*/
|
|
138
138
|
declare function containsCJKCharacters(str: string): boolean;
|
|
139
139
|
|
|
140
|
+
/**
|
|
141
|
+
* 将十六进制颜色转换为 ASS 格式
|
|
142
|
+
*
|
|
143
|
+
* 作用:
|
|
144
|
+
* 1. 将十六进制颜色转换为 ASS 格式,用于字幕样式设置
|
|
145
|
+
* 2. 支持 7 位和 9 位十六进制颜色格式
|
|
146
|
+
*
|
|
147
|
+
* @export
|
|
148
|
+
* @param {string} [hexColor]
|
|
149
|
+
* @return {*} {string}
|
|
150
|
+
*/
|
|
151
|
+
declare function convertHexColorToAssFormat(hexColor?: string): string;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 将十六进制颜色转换为 FFmpeg 格式
|
|
155
|
+
*
|
|
156
|
+
* 作用:
|
|
157
|
+
* 1. 将十六进制颜色转换为 FFmpeg 格式,用于字幕样式设置
|
|
158
|
+
* 2. 支持 7 位和 9 位十六进制颜色格式
|
|
159
|
+
*
|
|
160
|
+
* @param {string} hexColor
|
|
161
|
+
* @return {*} {string}
|
|
162
|
+
*/
|
|
163
|
+
declare function convertHexColorToFFmpegFormat(hexColor: string): string;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 将时间字符串转换为 ASS 字幕格式
|
|
167
|
+
*
|
|
168
|
+
* 作用:
|
|
169
|
+
* 1. 将标准时间格式字符串转换为 ASS 字幕文件所需的时间格式
|
|
170
|
+
* 2. 支持 HH:MM:SS.MMM 格式的输入
|
|
171
|
+
* 3. 确保时间轴的准确性和兼容性
|
|
172
|
+
*
|
|
173
|
+
* 处理流程:
|
|
174
|
+
* 1. 解析时间字符串,提取小时、分钟、秒、毫秒
|
|
175
|
+
* 2. 将时间转换为总秒数进行计算
|
|
176
|
+
* 3. 重新格式化为 ASS 标准格式
|
|
177
|
+
*
|
|
178
|
+
* 示例:
|
|
179
|
+
* 输入:"01:30:45.123" -> 输出:"1:30:45.12"
|
|
180
|
+
* 输入:"00:05:30.050" -> 输出:"0:05:30.05"
|
|
181
|
+
*
|
|
182
|
+
* @export
|
|
183
|
+
* @param {string} str - 输入的时间字符串,格式为 HH:MM:SS.MMM
|
|
184
|
+
* @return {string} 转换后的 ASS 格式时间字符串,格式为 H:MM:SS.MM
|
|
185
|
+
*/
|
|
186
|
+
declare function convertTimeToAssFormat(str: string): string;
|
|
187
|
+
|
|
140
188
|
/**
|
|
141
189
|
* Convert a HH:MM:SS,MMM or HH:MM:SS.MMM time format into seconds.
|
|
142
190
|
*
|
|
@@ -215,6 +263,8 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
215
263
|
*/
|
|
216
264
|
declare function formatTime(seconds: number): string;
|
|
217
265
|
|
|
266
|
+
export declare type ISegment = [string, string, string, string | undefined];
|
|
267
|
+
|
|
218
268
|
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";
|
|
219
269
|
|
|
220
270
|
/**
|
|
@@ -267,6 +317,30 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
267
317
|
repeat: boolean;
|
|
268
318
|
}
|
|
269
319
|
|
|
320
|
+
declare const outputAss: ({ segments1, segments2, subtitleSettings, isMac, reverse, speakerData }: OutputTextParams) => string;
|
|
321
|
+
|
|
322
|
+
declare function outputLrc({ segments1, segments2, speakerData }: OutputTextParams): string;
|
|
323
|
+
|
|
324
|
+
declare function outputSrt({ segments1, segments2, speakerData }: OutputTextParams): string;
|
|
325
|
+
|
|
326
|
+
export declare interface OutputTextParams {
|
|
327
|
+
segments1: Array<ISegment>;
|
|
328
|
+
segments2?: Array<ISegment>;
|
|
329
|
+
subtitleSettings?: SubtitleSettings;
|
|
330
|
+
speakerData?: SpeakerData | null;
|
|
331
|
+
locale?: Record<string, any>;
|
|
332
|
+
useIndex?: boolean;
|
|
333
|
+
useTimestamp?: boolean;
|
|
334
|
+
useParagraph?: boolean;
|
|
335
|
+
header?: string;
|
|
336
|
+
isMd?: boolean;
|
|
337
|
+
chunkSize?: number;
|
|
338
|
+
isMac?: boolean;
|
|
339
|
+
reverse?: boolean;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
declare function outputVtt({ segments1, segments2, speakerData }: OutputTextParams): string;
|
|
343
|
+
|
|
270
344
|
/**
|
|
271
345
|
* 为数字前方自动补0到特定的位数,默认两位
|
|
272
346
|
*/
|
|
@@ -399,6 +473,23 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
399
473
|
end: number;
|
|
400
474
|
};
|
|
401
475
|
|
|
476
|
+
export declare interface SpeakerData {
|
|
477
|
+
settings: Record<string, {
|
|
478
|
+
spk: string;
|
|
479
|
+
name?: string;
|
|
480
|
+
color: string;
|
|
481
|
+
}>;
|
|
482
|
+
speakers: Record<string, number>;
|
|
483
|
+
data: {
|
|
484
|
+
start: number;
|
|
485
|
+
end: number;
|
|
486
|
+
speaker: string;
|
|
487
|
+
}[];
|
|
488
|
+
options?: {
|
|
489
|
+
speakerCount?: number;
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
402
493
|
declare function splitToSentences(text: string, languageCode?: LanguageCode): string[];
|
|
403
494
|
|
|
404
495
|
declare function srtToAimSegments(text: string): Promise<AimSegments[]>;
|
|
@@ -420,6 +511,8 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
420
511
|
end(): string;
|
|
421
512
|
}
|
|
422
513
|
|
|
514
|
+
export declare type SubtitleLanguage = "ogLang" | "transLang" | "multiLang";
|
|
515
|
+
|
|
423
516
|
/**
|
|
424
517
|
* 字幕优化函数
|
|
425
518
|
*
|
|
@@ -468,6 +561,32 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
468
561
|
ep: RegExp;
|
|
469
562
|
};
|
|
470
563
|
|
|
564
|
+
export declare type SubtitlePosition = {
|
|
565
|
+
bottom: number;
|
|
566
|
+
left: number;
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
export declare type SubtitleSettings = {
|
|
570
|
+
disabled: boolean;
|
|
571
|
+
stroke: boolean;
|
|
572
|
+
shadow: boolean;
|
|
573
|
+
background: boolean;
|
|
574
|
+
backgroundColor: string;
|
|
575
|
+
main: SubtitleTextStyle;
|
|
576
|
+
sub: SubtitleTextStyle;
|
|
577
|
+
position: SubtitlePosition;
|
|
578
|
+
mode: SubtitleLanguage;
|
|
579
|
+
order?: number[];
|
|
580
|
+
watermark?: WatermarkStyle;
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
export declare type SubtitleTextStyle = {
|
|
584
|
+
color: string;
|
|
585
|
+
borderColor: string;
|
|
586
|
+
size: number;
|
|
587
|
+
fontFamily?: string;
|
|
588
|
+
};
|
|
589
|
+
|
|
471
590
|
declare interface TingwuResult {
|
|
472
591
|
TaskId: string;
|
|
473
592
|
Transcription: {
|
|
@@ -502,7 +621,11 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
502
621
|
detectAllLanguage,
|
|
503
622
|
detectLanguage,
|
|
504
623
|
LanguageDetectionResultsEntry,
|
|
505
|
-
splitToSentences
|
|
624
|
+
splitToSentences,
|
|
625
|
+
outputSrt,
|
|
626
|
+
outputVtt,
|
|
627
|
+
outputLrc,
|
|
628
|
+
outputAss
|
|
506
629
|
}
|
|
507
630
|
}
|
|
508
631
|
|
|
@@ -513,6 +636,9 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
513
636
|
convertToSeconds,
|
|
514
637
|
containsCJKCharacters,
|
|
515
638
|
languageCodeToName,
|
|
639
|
+
convertHexColorToAssFormat,
|
|
640
|
+
convertTimeToAssFormat,
|
|
641
|
+
convertHexColorToFFmpegFormat,
|
|
516
642
|
chunkArrayStrings,
|
|
517
643
|
chunkSegmentStringsWithIndex,
|
|
518
644
|
consolidateSegments
|
|
@@ -521,4 +647,17 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
521
647
|
|
|
522
648
|
declare function vttToAimSegments(text: string): Promise<AimSegments[]>;
|
|
523
649
|
|
|
650
|
+
export declare type WatermarkStyle = {
|
|
651
|
+
size: number;
|
|
652
|
+
enabled: boolean;
|
|
653
|
+
text: string;
|
|
654
|
+
position: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
655
|
+
opacity: number;
|
|
656
|
+
image?: string;
|
|
657
|
+
fontSize?: number;
|
|
658
|
+
color?: string;
|
|
659
|
+
fontFamily?: string;
|
|
660
|
+
fontFile?: string;
|
|
661
|
+
};
|
|
662
|
+
|
|
524
663
|
export { }
|