@aim-packages/subtitle 0.1.1 → 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 CHANGED
@@ -1162,6 +1162,100 @@ console.log(assContent);
1162
1162
  // 输出完整的ASS格式字幕文件,包含样式定义和字幕内容
1163
1163
  ```
1164
1164
 
1165
+ ##### `outputTxt(params: OutputTextParams): string`
1166
+
1167
+ 生成TXT格式的纯文本文件,支持多种输出模式。
1168
+
1169
+ **参数:**
1170
+ - `params: OutputTextParams` - 输出参数配置
1171
+ - `useIndex?: boolean` - 是否显示索引编号
1172
+ - `useTimestamp?: boolean` - 是否显示时间戳
1173
+ - `useParagraph?: boolean` - 是否使用段落模式(按发言人分组或按chunkSize分组)
1174
+
1175
+ **返回值:**
1176
+ - `string` - TXT格式的文本内容
1177
+
1178
+ **功能特性:**
1179
+ - **段落模式**: 支持按说话人分组或按固定大小分块
1180
+ - **行模式**: 每个字幕片段单独一行
1181
+ - **多语言支持**: 自动检测中日韩语言,调整文本连接方式
1182
+ - **说话人支持**: 支持显示说话人名称和时间戳
1183
+
1184
+ **示例:**
1185
+ ```typescript
1186
+ import { tools } from '@aim-packages/subtitle';
1187
+
1188
+ const segments1 = [
1189
+ ["00:00:01,000", "00:00:03,000", "Hello world", "speaker1"],
1190
+ ["00:00:03,000", "00:00:05,000", "How are you?", "speaker1"],
1191
+ ["00:00:05,000", "00:00:07,000", "I'm fine, thank you.", "speaker2"]
1192
+ ];
1193
+
1194
+ const segments2 = [
1195
+ ["00:00:01,000", "00:00:03,000", "你好世界", "speaker1"],
1196
+ ["00:00:03,000", "00:00:05,000", "你好吗?", "speaker1"],
1197
+ ["00:00:05,000", "00:00:07,000", "我很好,谢谢。", "speaker2"]
1198
+ ];
1199
+
1200
+ const speakerData = {
1201
+ settings: {
1202
+ speaker1: { spk: "speaker1", name: "张三", color: "#FF0000" },
1203
+ speaker2: { spk: "speaker2", name: "李四", color: "#00FF00" }
1204
+ },
1205
+ speakers: { speaker1: 1, speaker2: 1 },
1206
+ data: []
1207
+ };
1208
+
1209
+ // 行模式 - 每个字幕片段单独一行
1210
+ const txtContent1 = tools.output.outputTxt({
1211
+ segments1,
1212
+ segments2,
1213
+ speakerData,
1214
+ useIndex: true,
1215
+ useTimestamp: true,
1216
+ useParagraph: false
1217
+ });
1218
+
1219
+ console.log(txtContent1);
1220
+ // 输出:
1221
+ // 0
1222
+ // 00:00:01,000 --> 00:00:03,000
1223
+ // 张三: Hello world
1224
+ // 你好世界
1225
+ //
1226
+ // 1
1227
+ // 00:00:03,000 --> 00:00:05,000
1228
+ // 张三: How are you?
1229
+ // 你好吗?
1230
+ //
1231
+ // 2
1232
+ // 00:00:05,000 --> 00:00:07,000
1233
+ // 李四: I'm fine, thank you.
1234
+ // 我很好,谢谢。
1235
+
1236
+ // 段落模式 - 按说话人分组
1237
+ const txtContent2 = tools.output.outputTxt({
1238
+ segments1,
1239
+ segments2,
1240
+ speakerData,
1241
+ useIndex: true,
1242
+ useTimestamp: true,
1243
+ useParagraph: true
1244
+ });
1245
+
1246
+ console.log(txtContent2);
1247
+ // 输出:
1248
+ // 1
1249
+ // 张三 - 00:00:01,000 --> 00:00:05,000
1250
+ // Hello world How are you?
1251
+ // 你好世界 你好吗?
1252
+ //
1253
+ // 2
1254
+ // 李四 - 00:00:05,000 --> 00:00:07,000
1255
+ // I'm fine, thank you.
1256
+ // 我很好,谢谢。
1257
+ ```
1258
+
1165
1259
  #### 完整的字幕处理流程示例
1166
1260
 
1167
1261
  ```typescript