@aim-packages/subtitle 0.0.19 → 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 +1416 -0
- package/dist/index.cjs.js +63 -13
- package/dist/index.d.ts +584 -306
- package/dist/index.es.js +1101 -949
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -67,319 +67,597 @@ export declare interface AimSegments {
|
|
|
67
67
|
|
|
68
68
|
declare function assToAimSegments(text: string): Promise<AimSegments[]>;
|
|
69
69
|
|
|
70
|
-
declare function chunkArrayStrings(strings: string[], characterLimit: number): string[];
|
|
71
|
-
|
|
72
|
-
declare function chunkSegmentStringsWithIndex(segments: AimSegments[], characterLimit: number): {
|
|
73
|
-
segmentsResult: AimSegments[][];
|
|
74
|
-
stringResult: string[];
|
|
75
|
-
indexStringResult: string[];
|
|
76
|
-
indexResult: number[];
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
declare function consolidateSegments(items: Segment[], option: {
|
|
80
|
-
maxDistance: number;
|
|
81
|
-
padding: number;
|
|
82
|
-
}): Segment[] | undefined;
|
|
83
|
-
|
|
84
70
|
/**
|
|
85
|
-
*
|
|
71
|
+
* 将字符串数组按字符限制分块
|
|
86
72
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
declare function containsCJKCharacters(str: string): boolean;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Convert a HH:MM:SS,MMM or HH:MM:SS.MMM time format into seconds.
|
|
73
|
+
* 作用:
|
|
74
|
+
* 1. 将字符串数组按照字符限制进行分块,避免单次处理内容过多
|
|
75
|
+
* 2. 使用换行符连接同一分块内的字符串
|
|
76
|
+
* 3. 在分块时会预留一定的字符空间(10个字符)用于换行符和格式调整
|
|
95
77
|
*
|
|
96
78
|
* @export
|
|
97
|
-
* @param {string}
|
|
98
|
-
* @
|
|
99
|
-
|
|
100
|
-
declare function convertToSeconds(time?: string): number;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Creates a new Parser parser.
|
|
104
|
-
*
|
|
105
|
-
* @param onParse - Callback to invoke when a new event is parsed, or a new reconnection interval
|
|
106
|
-
* has been sent from the server
|
|
107
|
-
*
|
|
108
|
-
* @returns A new Parser parser, with `parse`, `end` and `reset` methods.
|
|
109
|
-
* @public
|
|
79
|
+
* @param {string[]} strings - 输入的字符串数组
|
|
80
|
+
* @param {number} characterLimit - 每个分块的最大字符数限制
|
|
81
|
+
* @return {string[]} 分块后的字符串数组,每个元素是换行符分隔的文本块
|
|
110
82
|
*/
|
|
111
|
-
declare function
|
|
112
|
-
vad?: Segment[];
|
|
113
|
-
vadPadding?: [number, number];
|
|
114
|
-
}): Parser<string>;
|
|
115
|
-
|
|
116
|
-
declare function create_2(options?: ParserOptions<RequiredByKey<Partial<AimSegments>, "index">[], Partial<AimSegments>[], string>): Parser<string>;
|
|
117
|
-
|
|
118
|
-
declare function create_3(options?: ParserOptions<AimSegments[], AimSegments[], AimSegments[]> & {
|
|
119
|
-
sentenceLength?: number;
|
|
120
|
-
repeatString?: string[];
|
|
121
|
-
}): Parser<AimSegments[]>;
|
|
122
|
-
|
|
123
|
-
declare function detectAllLanguage(text: string): LanguageDetectionResultsEntry[];
|
|
124
|
-
|
|
125
|
-
declare function detectLanguage(text: string): LanguageDetectionResultsEntry;
|
|
126
|
-
|
|
127
|
-
export declare namespace filter {
|
|
128
|
-
export {
|
|
129
|
-
StreamFilter
|
|
130
|
-
}
|
|
131
|
-
}
|
|
83
|
+
declare function chunkArrayStrings(strings: string[], characterLimit: number): string[];
|
|
132
84
|
|
|
133
85
|
/**
|
|
134
|
-
*
|
|
86
|
+
* 将字幕片段按字符限制分块,并生成多种格式的结果
|
|
135
87
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
declare function formatTime(seconds: number): string;
|
|
141
|
-
|
|
142
|
-
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";
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 将语言代码转换为名称
|
|
88
|
+
* 作用:
|
|
89
|
+
* 1. 将字幕片段数组按照字符限制分块,避免单次处理内容过多
|
|
90
|
+
* 2. 为每个片段添加索引信息,便于后续处理和追踪
|
|
91
|
+
* 3. 生成多种格式的分块结果,满足不同场景的需求
|
|
146
92
|
*
|
|
147
93
|
* @export
|
|
148
|
-
* @param {
|
|
149
|
-
* @
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
*
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
94
|
+
* @param {AimSegments[]} segments - 输入的字幕片段数组
|
|
95
|
+
* @param {number} characterLimit - 每个分块的最大字符数限制
|
|
96
|
+
* @return {{
|
|
97
|
+
* segmentsResult: AimSegments[][] - 分块后的字幕片段数组,每个元素是一个片段数组
|
|
98
|
+
* stringResult: string[] - 纯文本分块结果,每个元素是换行符分隔的文本
|
|
99
|
+
* indexStringResult: string[] - 带索引的文本分块结果,格式为 [索引]文本
|
|
100
|
+
* indexResult: number[] - 每个分块的起始索引数组,用于追踪分块边界
|
|
101
|
+
* }} 分块处理的结果对象
|
|
102
|
+
*/
|
|
103
|
+
declare function chunkSegmentStringsWithIndex(segments: AimSegments[], characterLimit: number): {
|
|
104
|
+
segmentsResult: AimSegments[][];
|
|
105
|
+
stringResult: string[];
|
|
106
|
+
indexStringResult: string[];
|
|
107
|
+
indexResult: number[];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 合并字幕片段,优化字幕的时间轴
|
|
112
|
+
*
|
|
113
|
+
* 作用:
|
|
114
|
+
* 1. 将时间间隔小于 maxDistance 的相邻字幕片段合并为一个片段
|
|
115
|
+
* 2. 可选择性地为每个片段添加 padding 时间,扩展片段的开始和结束时间
|
|
116
|
+
* 3. 如果添加了 padding,会自动处理重叠的片段,将它们合并
|
|
117
|
+
*
|
|
118
|
+
* @export
|
|
119
|
+
* @param {Segment[]} items - 输入的字幕片段数组,每个片段包含 start 和 end 时间
|
|
120
|
+
* @param {{
|
|
121
|
+
* maxDistance: number - 最大时间间隔,小于此值的相邻片段会被合并
|
|
122
|
+
* padding: number - 可选的时间填充,为每个片段扩展开始和结束时间
|
|
123
|
+
* }} option - 合并选项
|
|
124
|
+
* @return {Segment[]} 合并后的字幕片段数组,如果输入为空则返回空数组
|
|
125
|
+
*/
|
|
126
|
+
declare function consolidateSegments(items: Segment[], option: {
|
|
127
|
+
maxDistance: number;
|
|
128
|
+
padding: number;
|
|
129
|
+
}): Segment[] | undefined;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 匹配中文、日文、韩文字符的正则表达式
|
|
133
|
+
*
|
|
134
|
+
* @export
|
|
135
|
+
* @param {string} str
|
|
136
|
+
* @return {*} {boolean}
|
|
137
|
+
*/
|
|
138
|
+
declare function containsCJKCharacters(str: string): boolean;
|
|
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
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Convert a HH:MM:SS,MMM or HH:MM:SS.MMM time format into seconds.
|
|
190
|
+
*
|
|
191
|
+
* @export
|
|
192
|
+
* @param {string} time - The time to be converted.
|
|
193
|
+
* @return {*} {number} - The time converted to seconds.
|
|
194
|
+
*/
|
|
195
|
+
declare function convertToSeconds(time?: string): number;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Creates a new Parser parser.
|
|
199
|
+
*
|
|
200
|
+
* @param onParse - Callback to invoke when a new event is parsed, or a new reconnection interval
|
|
201
|
+
* has been sent from the server
|
|
202
|
+
*
|
|
203
|
+
* @returns A new Parser parser, with `parse`, `end` and `reset` methods.
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
declare function create(options?: ParserOptions<AimSegments[], AimSegments[], string> & {
|
|
207
|
+
vad?: Segment[];
|
|
208
|
+
vadPadding?: [number, number];
|
|
209
|
+
}): Parser<string>;
|
|
210
|
+
|
|
211
|
+
declare function create_2(options?: ParserOptions<RequiredByKey<Partial<AimSegments>, "index">[], Partial<AimSegments>[], string>): Parser<string>;
|
|
212
|
+
|
|
213
|
+
declare function create_3(options?: ParserOptions<AimSegments[], AimSegments[], AimSegments[]> & {
|
|
214
|
+
sentenceLength?: number;
|
|
215
|
+
repeatString?: string[];
|
|
216
|
+
}): Parser<AimSegments[]>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 检测文本中的所有可能语言
|
|
220
|
+
* 使用 tinyld 库进行多语言检测,返回按概率排序的语言列表
|
|
221
|
+
*
|
|
222
|
+
* @param {string} text - 需要检测语言的文本内容
|
|
223
|
+
* @return {LanguageDetectionResultsEntry[]} 返回检测到的所有语言及其概率,按概率从高到低排序
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const results = detectAllLanguage("Hello world 你好世界");
|
|
228
|
+
* // 返回: [
|
|
229
|
+
* // { language: 'en', languageName: 'English', probability: 0.8 },
|
|
230
|
+
* // { language: 'zh', languageName: '中文', probability: 0.2 }
|
|
231
|
+
* // ]
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
declare function detectAllLanguage(text: string): LanguageDetectionResultsEntry[];
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 检测文本的主要语言
|
|
238
|
+
* 使用 tinyld 库进行单语言检测,返回最可能的语言
|
|
239
|
+
*
|
|
240
|
+
* @param {string} text - 需要检测语言的文本内容
|
|
241
|
+
* @return {LanguageDetectionResultsEntry} 返回检测到的主要语言信息
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* const result = detectLanguage("Hello world");
|
|
246
|
+
* // 返回: { language: 'en', languageName: 'English', probability: 1 }
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function detectLanguage(text: string): LanguageDetectionResultsEntry;
|
|
250
|
+
|
|
251
|
+
export declare namespace filter {
|
|
252
|
+
export {
|
|
253
|
+
StreamFilter
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 将秒数转换为 xx:xx:xx.xxx 格式
|
|
259
|
+
*
|
|
260
|
+
* @export
|
|
261
|
+
* @param {number} seconds
|
|
262
|
+
* @return {*} {string}
|
|
263
|
+
*/
|
|
264
|
+
declare function formatTime(seconds: number): string;
|
|
265
|
+
|
|
266
|
+
export declare type ISegment = [string, string, string, string | undefined];
|
|
267
|
+
|
|
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";
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 将语言代码转换为名称
|
|
272
|
+
*
|
|
273
|
+
* @export
|
|
274
|
+
* @param {LanguageCode} languageCode
|
|
275
|
+
* @return {*}
|
|
276
|
+
*/
|
|
277
|
+
declare function languageCodeToName(languageCode: LanguageCode): string;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* 语言检测结果条目接口
|
|
281
|
+
* 包含检测到的语言信息
|
|
282
|
+
*/
|
|
283
|
+
declare interface LanguageDetectionResultsEntry {
|
|
284
|
+
/** 语言代码 (如 'zh', 'en', 'ja' 等) */
|
|
285
|
+
language: LanguageCode;
|
|
286
|
+
/** 语言名称 (如 '中文', 'English', '日本語' 等) */
|
|
287
|
+
languageName: string;
|
|
288
|
+
/** 检测准确度概率 (0-1 之间的数值) */
|
|
289
|
+
probability: number;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
declare interface OpenAIResult {
|
|
293
|
+
task: string;
|
|
294
|
+
language: string;
|
|
295
|
+
text: string;
|
|
296
|
+
words: {
|
|
297
|
+
word: string;
|
|
298
|
+
start: number;
|
|
299
|
+
end: number;
|
|
300
|
+
}[];
|
|
301
|
+
segments: {
|
|
302
|
+
text: string;
|
|
303
|
+
start: number;
|
|
304
|
+
end: number;
|
|
305
|
+
}[];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
declare function openaiToAimSegments(json: OpenAIResult): Promise<AimSegments[]>;
|
|
309
|
+
|
|
310
|
+
export declare interface OptimizationOptions {
|
|
311
|
+
emt: boolean;
|
|
312
|
+
ep: boolean;
|
|
313
|
+
zf: boolean;
|
|
314
|
+
punc: boolean;
|
|
315
|
+
em: boolean;
|
|
316
|
+
space: boolean;
|
|
317
|
+
repeat: boolean;
|
|
318
|
+
}
|
|
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
|
+
|
|
344
|
+
/**
|
|
345
|
+
* 为数字前方自动补0到特定的位数,默认两位
|
|
346
|
+
*/
|
|
347
|
+
declare function padNumber(num: number, length?: number): string;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Callback passed as the `onParse` callback to a parser
|
|
351
|
+
*
|
|
352
|
+
* @public
|
|
353
|
+
*/
|
|
354
|
+
declare type ParseCallback<T> = (event: ParsedEvent<T>) => void;
|
|
355
|
+
|
|
356
|
+
declare interface ParsedEvent<T> {
|
|
357
|
+
type: "event";
|
|
358
|
+
event: "start" | "message" | "end";
|
|
359
|
+
data?: T;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Parser parser instance.
|
|
364
|
+
*
|
|
365
|
+
* Needs to be reset between reconnections/when switching data source, using the `reset()` method.
|
|
366
|
+
*
|
|
367
|
+
* @public
|
|
368
|
+
*/
|
|
369
|
+
declare interface Parser<T = string> {
|
|
370
|
+
/**
|
|
371
|
+
* Feeds the parser another chunk. The method _does not_ return a parsed message.
|
|
372
|
+
* Instead, if the chunk was a complete message (or completed a previously incomplete message),
|
|
373
|
+
* it will invoke the `onParse` callback used to create the parsers.
|
|
374
|
+
*
|
|
375
|
+
* @param chunk - The chunk to parse. Can be a partial, eg in the case of streaming messages.
|
|
376
|
+
* @public
|
|
377
|
+
*/
|
|
378
|
+
feed(chunk: T): void;
|
|
379
|
+
/**
|
|
380
|
+
* Resets the parser state. This is required when you have a new stream of messages -
|
|
381
|
+
* for instance in the case of a client being disconnected and reconnecting.
|
|
382
|
+
*
|
|
383
|
+
* @public
|
|
384
|
+
*/
|
|
385
|
+
reset(): void;
|
|
386
|
+
end(): void;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export declare namespace parser {
|
|
390
|
+
export {
|
|
391
|
+
srtToAimSegments,
|
|
392
|
+
vttToAimSegments,
|
|
393
|
+
assToAimSegments,
|
|
394
|
+
tingwuToAimSegments,
|
|
395
|
+
openaiToAimSegments,
|
|
396
|
+
create as createWhisperStreamParser,
|
|
397
|
+
create_2 as createTranslateStreamParser,
|
|
398
|
+
create_3 as createSegmentStreamParser
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* `ParserOptions` 是一个泛型类型,用于配置解析器的回调函数。
|
|
404
|
+
*
|
|
405
|
+
* @template S - 解析开始时的状态类型
|
|
406
|
+
* @template P - 解析过程中使用的状态类型
|
|
407
|
+
* @template E - 解析结束时的状态类型
|
|
408
|
+
*
|
|
409
|
+
* @property {ParseCallback<S>} [onStart] - 解析开始时的回调函数
|
|
410
|
+
* @property {ParseCallback<P>} [onParse] - 解析过程中调用的回调函数
|
|
411
|
+
* @property {ParseCallback<P>} [onProgress] - 解析进度更新时的回调函数
|
|
412
|
+
* @property {ParseCallback<E>} [onEnd] - 解析结束时的回调函数
|
|
413
|
+
*/
|
|
414
|
+
declare type ParserOptions<S, P, E> = {
|
|
415
|
+
onStart?: ParseCallback<S>;
|
|
416
|
+
onParse?: ParseCallback<P>;
|
|
417
|
+
onProgress?: ParseCallback<P>;
|
|
418
|
+
onEnd?: ParseCallback<E>;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
export declare type PartialByKey<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 重复内容检测器
|
|
425
|
+
*
|
|
426
|
+
* 用于检测字幕中连续重复的内容片段,当重复次数达到阈值时会触发回调
|
|
427
|
+
*/
|
|
428
|
+
declare class RepeatCheck {
|
|
429
|
+
/** 重复检测阈值,默认为2次 */
|
|
430
|
+
threshold: number;
|
|
431
|
+
/** 当前重复次数 */
|
|
432
|
+
hit: number;
|
|
433
|
+
/** 前一个字幕片段 */
|
|
434
|
+
prevSegment?: AimSegments;
|
|
435
|
+
/** 当前重复的字幕片段 */
|
|
436
|
+
hitSegment?: AimSegments;
|
|
437
|
+
/** 重复片段列表 */
|
|
438
|
+
hitSegmentList: AimSegments[];
|
|
439
|
+
/** 配置选项 */
|
|
440
|
+
options: RepeatCheckOption;
|
|
441
|
+
/**
|
|
442
|
+
* 构造函数
|
|
443
|
+
* @param options 重复检测选项
|
|
444
|
+
*/
|
|
445
|
+
constructor(options?: RepeatCheckOption);
|
|
446
|
+
/**
|
|
447
|
+
* 添加字幕片段进行重复检测
|
|
448
|
+
* @param segment 要检测的字幕片段
|
|
449
|
+
*/
|
|
450
|
+
push(segment: AimSegments): void;
|
|
451
|
+
/**
|
|
452
|
+
* 结束检测,处理最后的重复片段
|
|
453
|
+
*/
|
|
454
|
+
end(): void;
|
|
455
|
+
/**
|
|
456
|
+
* 重置检测器状态
|
|
457
|
+
*/
|
|
458
|
+
reset(): void;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 重复检测选项接口
|
|
463
|
+
*/
|
|
464
|
+
declare interface RepeatCheckOption {
|
|
465
|
+
/** 当检测到重复内容时的回调函数 */
|
|
466
|
+
onHit?: (segment: AimSegments[]) => void;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export declare type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
470
|
+
|
|
471
|
+
export declare type Segment = {
|
|
472
|
+
start: number;
|
|
473
|
+
end: number;
|
|
474
|
+
};
|
|
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
|
+
|
|
493
|
+
declare function splitToSentences(text: string, languageCode?: LanguageCode): string[];
|
|
494
|
+
|
|
495
|
+
declare function srtToAimSegments(text: string): Promise<AimSegments[]>;
|
|
496
|
+
|
|
497
|
+
declare class StreamFilter {
|
|
498
|
+
chains: Record<string, any>;
|
|
499
|
+
delimit: string;
|
|
500
|
+
onFilter?: (text: string) => any;
|
|
501
|
+
checked: boolean;
|
|
502
|
+
checkedText: string;
|
|
503
|
+
checkedLevel?: Record<string, any>;
|
|
504
|
+
filteredText: string;
|
|
505
|
+
constructor(onFilter?: (text: string) => any);
|
|
506
|
+
add(keyword: string, replaceText?: string): void;
|
|
507
|
+
parse(data: [string, string][]): void;
|
|
508
|
+
reParse(data: string[][]): void;
|
|
509
|
+
feed(c: string): void;
|
|
510
|
+
feedAll(text: string): string;
|
|
511
|
+
end(): string;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export declare type SubtitleLanguage = "ogLang" | "transLang" | "multiLang";
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* 字幕优化函数
|
|
518
|
+
*
|
|
519
|
+
* 对字幕片段进行全面的质量检查和优化,包括:
|
|
520
|
+
* - 重复内容检测和移除
|
|
521
|
+
* - 空白字幕处理
|
|
522
|
+
* - 0帧字幕处理(开始时间大于等于结束时间)
|
|
523
|
+
* - 标点符号检查
|
|
524
|
+
* - 句子结束标记检查
|
|
525
|
+
* - 多余空格处理
|
|
526
|
+
* - 结尾标点处理
|
|
527
|
+
*
|
|
528
|
+
* @export
|
|
529
|
+
* @param {AimSegments[]} segments - 需要优化的字幕片段数组
|
|
530
|
+
* @param {OptimizationOptions} [options] - 优化选项配置
|
|
531
|
+
* @return {Object} 返回优化结果,包含:
|
|
532
|
+
* - result: 各种问题的索引统计
|
|
533
|
+
* - repeat: 重复的片段列表
|
|
534
|
+
* - segments: 优化后的字幕片段数组
|
|
535
|
+
*/
|
|
536
|
+
declare function subtitleOptimization(segments: AimSegments[], options?: OptimizationOptions): {
|
|
537
|
+
result: {
|
|
538
|
+
emt: number[];
|
|
539
|
+
ep: number[];
|
|
540
|
+
zf: number[];
|
|
541
|
+
punc: number[];
|
|
542
|
+
em: number[];
|
|
543
|
+
space: number[];
|
|
544
|
+
repeat: number[];
|
|
545
|
+
};
|
|
546
|
+
repeat: AimSegments[];
|
|
547
|
+
segments: AimSegments[];
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* 字幕优化使用的正则表达式
|
|
552
|
+
*/
|
|
553
|
+
declare const subtitleOptimizationRegExp: {
|
|
554
|
+
/** 检测是否存在句子分割符号(逗号、句号、问号、感叹号等) */
|
|
555
|
+
punc: RegExp;
|
|
556
|
+
/** 检测是否存在行尾分割符号(句号、问号、感叹号等) */
|
|
557
|
+
em: RegExp;
|
|
558
|
+
/** 检测是否存在连续空白字符(行首行尾空白、多个连续空格) */
|
|
559
|
+
space: RegExp;
|
|
560
|
+
/** 检测是否存在行尾标点和可能存在的空格字符 */
|
|
561
|
+
ep: RegExp;
|
|
562
|
+
};
|
|
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
|
+
|
|
590
|
+
declare interface TingwuResult {
|
|
591
|
+
TaskId: string;
|
|
592
|
+
Transcription: {
|
|
593
|
+
AudioInfo: {
|
|
594
|
+
"Size": number;
|
|
595
|
+
"Duration": number;
|
|
596
|
+
"SampleRate": number;
|
|
597
|
+
"Language": string;
|
|
598
|
+
};
|
|
599
|
+
Paragraphs: {
|
|
600
|
+
ParagraphId: string;
|
|
601
|
+
SpeakerId: string;
|
|
602
|
+
Words: {
|
|
603
|
+
"Id": number;
|
|
604
|
+
"SentenceId": number;
|
|
605
|
+
"Start": number;
|
|
606
|
+
"End": number;
|
|
607
|
+
"Text": string;
|
|
608
|
+
}[];
|
|
609
|
+
}[];
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
declare function tingwuToAimSegments(json: TingwuResult): Promise<AimSegments[]>;
|
|
614
|
+
|
|
615
|
+
export declare namespace tools {
|
|
616
|
+
export {
|
|
617
|
+
subtitleOptimization,
|
|
618
|
+
RepeatCheckOption,
|
|
619
|
+
RepeatCheck,
|
|
620
|
+
subtitleOptimizationRegExp,
|
|
621
|
+
detectAllLanguage,
|
|
622
|
+
detectLanguage,
|
|
623
|
+
LanguageDetectionResultsEntry,
|
|
624
|
+
splitToSentences,
|
|
625
|
+
outputSrt,
|
|
626
|
+
outputVtt,
|
|
627
|
+
outputLrc,
|
|
628
|
+
outputAss
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export declare namespace utils {
|
|
633
|
+
export {
|
|
634
|
+
padNumber,
|
|
635
|
+
formatTime,
|
|
636
|
+
convertToSeconds,
|
|
637
|
+
containsCJKCharacters,
|
|
638
|
+
languageCodeToName,
|
|
639
|
+
convertHexColorToAssFormat,
|
|
640
|
+
convertTimeToAssFormat,
|
|
641
|
+
convertHexColorToFFmpegFormat,
|
|
642
|
+
chunkArrayStrings,
|
|
643
|
+
chunkSegmentStringsWithIndex,
|
|
644
|
+
consolidateSegments
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
declare function vttToAimSegments(text: string): Promise<AimSegments[]>;
|
|
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
|
+
|
|
663
|
+
export { }
|