@aim-packages/subtitle 0.1.0 → 0.1.2
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 +438 -2
- package/dist/index.cjs.js +81 -16
- package/dist/index.d.ts +143 -1
- package/dist/index.es.js +1222 -1013
- 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,32 @@ 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 outputTxt({ segments1, segments2, speakerData, locale, useIndex, useTimestamp, useParagraph }: OutputTextParams): string;
|
|
343
|
+
|
|
344
|
+
declare function outputVtt({ segments1, segments2, speakerData }: OutputTextParams): string;
|
|
345
|
+
|
|
270
346
|
/**
|
|
271
347
|
* 为数字前方自动补0到特定的位数,默认两位
|
|
272
348
|
*/
|
|
@@ -399,6 +475,23 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
399
475
|
end: number;
|
|
400
476
|
};
|
|
401
477
|
|
|
478
|
+
export declare interface SpeakerData {
|
|
479
|
+
settings: Record<string, {
|
|
480
|
+
spk: string;
|
|
481
|
+
name?: string;
|
|
482
|
+
color: string;
|
|
483
|
+
}>;
|
|
484
|
+
speakers: Record<string, number>;
|
|
485
|
+
data: {
|
|
486
|
+
start: number;
|
|
487
|
+
end: number;
|
|
488
|
+
speaker: string;
|
|
489
|
+
}[];
|
|
490
|
+
options?: {
|
|
491
|
+
speakerCount?: number;
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
402
495
|
declare function splitToSentences(text: string, languageCode?: LanguageCode): string[];
|
|
403
496
|
|
|
404
497
|
declare function srtToAimSegments(text: string): Promise<AimSegments[]>;
|
|
@@ -420,6 +513,8 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
420
513
|
end(): string;
|
|
421
514
|
}
|
|
422
515
|
|
|
516
|
+
export declare type SubtitleLanguage = "ogLang" | "transLang" | "multiLang";
|
|
517
|
+
|
|
423
518
|
/**
|
|
424
519
|
* 字幕优化函数
|
|
425
520
|
*
|
|
@@ -468,6 +563,32 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
468
563
|
ep: RegExp;
|
|
469
564
|
};
|
|
470
565
|
|
|
566
|
+
export declare type SubtitlePosition = {
|
|
567
|
+
bottom: number;
|
|
568
|
+
left: number;
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
export declare type SubtitleSettings = {
|
|
572
|
+
disabled: boolean;
|
|
573
|
+
stroke: boolean;
|
|
574
|
+
shadow: boolean;
|
|
575
|
+
background: boolean;
|
|
576
|
+
backgroundColor: string;
|
|
577
|
+
main: SubtitleTextStyle;
|
|
578
|
+
sub: SubtitleTextStyle;
|
|
579
|
+
position: SubtitlePosition;
|
|
580
|
+
mode: SubtitleLanguage;
|
|
581
|
+
order?: number[];
|
|
582
|
+
watermark?: WatermarkStyle;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
export declare type SubtitleTextStyle = {
|
|
586
|
+
color: string;
|
|
587
|
+
borderColor: string;
|
|
588
|
+
size: number;
|
|
589
|
+
fontFamily?: string;
|
|
590
|
+
};
|
|
591
|
+
|
|
471
592
|
declare interface TingwuResult {
|
|
472
593
|
TaskId: string;
|
|
473
594
|
Transcription: {
|
|
@@ -502,7 +623,12 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
502
623
|
detectAllLanguage,
|
|
503
624
|
detectLanguage,
|
|
504
625
|
LanguageDetectionResultsEntry,
|
|
505
|
-
splitToSentences
|
|
626
|
+
splitToSentences,
|
|
627
|
+
outputSrt,
|
|
628
|
+
outputVtt,
|
|
629
|
+
outputLrc,
|
|
630
|
+
outputTxt,
|
|
631
|
+
outputAss
|
|
506
632
|
}
|
|
507
633
|
}
|
|
508
634
|
|
|
@@ -513,6 +639,9 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
513
639
|
convertToSeconds,
|
|
514
640
|
containsCJKCharacters,
|
|
515
641
|
languageCodeToName,
|
|
642
|
+
convertHexColorToAssFormat,
|
|
643
|
+
convertTimeToAssFormat,
|
|
644
|
+
convertHexColorToFFmpegFormat,
|
|
516
645
|
chunkArrayStrings,
|
|
517
646
|
chunkSegmentStringsWithIndex,
|
|
518
647
|
consolidateSegments
|
|
@@ -521,4 +650,17 @@ declare function chunkArrayStrings(strings: string[], characterLimit: number): s
|
|
|
521
650
|
|
|
522
651
|
declare function vttToAimSegments(text: string): Promise<AimSegments[]>;
|
|
523
652
|
|
|
653
|
+
export declare type WatermarkStyle = {
|
|
654
|
+
size: number;
|
|
655
|
+
enabled: boolean;
|
|
656
|
+
text: string;
|
|
657
|
+
position: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
658
|
+
opacity: number;
|
|
659
|
+
image?: string;
|
|
660
|
+
fontSize?: number;
|
|
661
|
+
color?: string;
|
|
662
|
+
fontFamily?: string;
|
|
663
|
+
fontFile?: string;
|
|
664
|
+
};
|
|
665
|
+
|
|
524
666
|
export { }
|