@hasna/microservices 0.0.15 → 0.0.17

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.
Files changed (296) hide show
  1. package/README.md +120 -138
  2. package/bin/index.js +703 -12728
  3. package/bin/mcp.js +250 -9726
  4. package/dist/index.js +170 -9407
  5. package/package.json +25 -25
  6. package/microservices/microservice-ads/package.json +0 -27
  7. package/microservices/microservice-ads/src/cli/index.ts +0 -605
  8. package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
  9. package/microservices/microservice-ads/src/db/database.ts +0 -93
  10. package/microservices/microservice-ads/src/db/migrations.ts +0 -60
  11. package/microservices/microservice-ads/src/index.ts +0 -39
  12. package/microservices/microservice-ads/src/mcp/index.ts +0 -480
  13. package/microservices/microservice-analytics/package.json +0 -27
  14. package/microservices/microservice-analytics/src/cli/index.ts +0 -373
  15. package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
  16. package/microservices/microservice-analytics/src/db/database.ts +0 -93
  17. package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
  18. package/microservices/microservice-analytics/src/index.ts +0 -37
  19. package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
  20. package/microservices/microservice-assets/package.json +0 -27
  21. package/microservices/microservice-assets/src/cli/index.ts +0 -375
  22. package/microservices/microservice-assets/src/db/assets.ts +0 -370
  23. package/microservices/microservice-assets/src/db/database.ts +0 -93
  24. package/microservices/microservice-assets/src/db/migrations.ts +0 -51
  25. package/microservices/microservice-assets/src/index.ts +0 -32
  26. package/microservices/microservice-assets/src/mcp/index.ts +0 -346
  27. package/microservices/microservice-bookkeeping/package.json +0 -27
  28. package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
  29. package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
  30. package/microservices/microservice-bookkeeping/src/db/database.ts +0 -93
  31. package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
  32. package/microservices/microservice-bookkeeping/src/index.ts +0 -32
  33. package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
  34. package/microservices/microservice-calendar/package.json +0 -27
  35. package/microservices/microservice-calendar/src/cli/index.ts +0 -287
  36. package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
  37. package/microservices/microservice-calendar/src/db/database.ts +0 -82
  38. package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
  39. package/microservices/microservice-calendar/src/index.ts +0 -24
  40. package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
  41. package/microservices/microservice-company/package.json +0 -27
  42. package/microservices/microservice-company/src/cli/index.ts +0 -1126
  43. package/microservices/microservice-company/src/db/company.ts +0 -854
  44. package/microservices/microservice-company/src/db/database.ts +0 -93
  45. package/microservices/microservice-company/src/db/migrations.ts +0 -214
  46. package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
  47. package/microservices/microservice-company/src/index.ts +0 -60
  48. package/microservices/microservice-company/src/lib/audit.ts +0 -168
  49. package/microservices/microservice-company/src/lib/finance.ts +0 -299
  50. package/microservices/microservice-company/src/lib/settings.ts +0 -85
  51. package/microservices/microservice-company/src/lib/workflows.ts +0 -698
  52. package/microservices/microservice-company/src/mcp/index.ts +0 -991
  53. package/microservices/microservice-compliance/package.json +0 -27
  54. package/microservices/microservice-compliance/src/cli/index.ts +0 -467
  55. package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
  56. package/microservices/microservice-compliance/src/db/database.ts +0 -93
  57. package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
  58. package/microservices/microservice-compliance/src/index.ts +0 -46
  59. package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
  60. package/microservices/microservice-contacts/package.json +0 -27
  61. package/microservices/microservice-contacts/src/cli/index.ts +0 -393
  62. package/microservices/microservice-contacts/src/db/companies.ts +0 -167
  63. package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
  64. package/microservices/microservice-contacts/src/db/database.ts +0 -93
  65. package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
  66. package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
  67. package/microservices/microservice-contacts/src/index.ts +0 -42
  68. package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
  69. package/microservices/microservice-contracts/package.json +0 -27
  70. package/microservices/microservice-contracts/src/cli/index.ts +0 -770
  71. package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
  72. package/microservices/microservice-contracts/src/db/database.ts +0 -93
  73. package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
  74. package/microservices/microservice-contracts/src/index.ts +0 -43
  75. package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
  76. package/microservices/microservice-crm/package.json +0 -27
  77. package/microservices/microservice-crm/src/cli/index.ts +0 -396
  78. package/microservices/microservice-crm/src/db/database.ts +0 -82
  79. package/microservices/microservice-crm/src/db/migrations.ts +0 -66
  80. package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
  81. package/microservices/microservice-crm/src/index.ts +0 -34
  82. package/microservices/microservice-crm/src/mcp/index.ts +0 -294
  83. package/microservices/microservice-documents/package.json +0 -27
  84. package/microservices/microservice-documents/src/cli/index.ts +0 -246
  85. package/microservices/microservice-documents/src/db/database.ts +0 -82
  86. package/microservices/microservice-documents/src/db/documents.ts +0 -316
  87. package/microservices/microservice-documents/src/db/migrations.ts +0 -49
  88. package/microservices/microservice-documents/src/index.ts +0 -24
  89. package/microservices/microservice-documents/src/mcp/index.ts +0 -202
  90. package/microservices/microservice-domains/package.json +0 -27
  91. package/microservices/microservice-domains/src/cli/index.ts +0 -1111
  92. package/microservices/microservice-domains/src/db/database.ts +0 -93
  93. package/microservices/microservice-domains/src/db/domains.ts +0 -1164
  94. package/microservices/microservice-domains/src/db/migrations.ts +0 -60
  95. package/microservices/microservice-domains/src/index.ts +0 -65
  96. package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
  97. package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
  98. package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
  99. package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
  100. package/microservices/microservice-domains/src/mcp/index.ts +0 -781
  101. package/microservices/microservice-expenses/package.json +0 -27
  102. package/microservices/microservice-expenses/src/cli/index.ts +0 -267
  103. package/microservices/microservice-expenses/src/db/database.ts +0 -82
  104. package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
  105. package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
  106. package/microservices/microservice-expenses/src/index.ts +0 -25
  107. package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
  108. package/microservices/microservice-habits/package.json +0 -27
  109. package/microservices/microservice-habits/src/cli/index.ts +0 -315
  110. package/microservices/microservice-habits/src/db/database.ts +0 -93
  111. package/microservices/microservice-habits/src/db/habits.ts +0 -451
  112. package/microservices/microservice-habits/src/db/migrations.ts +0 -46
  113. package/microservices/microservice-habits/src/index.ts +0 -31
  114. package/microservices/microservice-habits/src/mcp/index.ts +0 -313
  115. package/microservices/microservice-health/package.json +0 -27
  116. package/microservices/microservice-health/src/cli/index.ts +0 -484
  117. package/microservices/microservice-health/src/db/database.ts +0 -93
  118. package/microservices/microservice-health/src/db/health.ts +0 -708
  119. package/microservices/microservice-health/src/db/migrations.ts +0 -70
  120. package/microservices/microservice-health/src/index.ts +0 -63
  121. package/microservices/microservice-health/src/mcp/index.ts +0 -437
  122. package/microservices/microservice-hiring/package.json +0 -27
  123. package/microservices/microservice-hiring/src/cli/index.ts +0 -741
  124. package/microservices/microservice-hiring/src/db/database.ts +0 -93
  125. package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
  126. package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
  127. package/microservices/microservice-hiring/src/index.ts +0 -80
  128. package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
  129. package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
  130. package/microservices/microservice-inventory/package.json +0 -27
  131. package/microservices/microservice-inventory/src/cli/index.ts +0 -365
  132. package/microservices/microservice-inventory/src/db/database.ts +0 -82
  133. package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
  134. package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
  135. package/microservices/microservice-inventory/src/index.ts +0 -28
  136. package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
  137. package/microservices/microservice-invoices/dashboard/dist/assets/index-Bngq7FNM.css +0 -1
  138. package/microservices/microservice-invoices/dashboard/dist/assets/index-aHW4ARZR.js +0 -124
  139. package/microservices/microservice-invoices/dashboard/dist/index.html +0 -13
  140. package/microservices/microservice-invoices/dashboard/index.html +0 -12
  141. package/microservices/microservice-invoices/dashboard/package.json +0 -29
  142. package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
  143. package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
  144. package/microservices/microservice-invoices/package.json +0 -30
  145. package/microservices/microservice-invoices/src/cli/index.ts +0 -308
  146. package/microservices/microservice-invoices/src/db/business.ts +0 -241
  147. package/microservices/microservice-invoices/src/db/clients.ts +0 -127
  148. package/microservices/microservice-invoices/src/db/database.ts +0 -82
  149. package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
  150. package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
  151. package/microservices/microservice-invoices/src/index.ts +0 -56
  152. package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
  153. package/microservices/microservice-invoices/src/server/index.ts +0 -162
  154. package/microservices/microservice-leads/package.json +0 -27
  155. package/microservices/microservice-leads/src/cli/index.ts +0 -596
  156. package/microservices/microservice-leads/src/db/database.ts +0 -93
  157. package/microservices/microservice-leads/src/db/leads.ts +0 -520
  158. package/microservices/microservice-leads/src/db/lists.ts +0 -151
  159. package/microservices/microservice-leads/src/db/migrations.ts +0 -93
  160. package/microservices/microservice-leads/src/index.ts +0 -65
  161. package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
  162. package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
  163. package/microservices/microservice-leads/src/mcp/index.ts +0 -533
  164. package/microservices/microservice-notes/package.json +0 -27
  165. package/microservices/microservice-notes/src/cli/index.ts +0 -63
  166. package/microservices/microservice-notes/src/db/database.ts +0 -93
  167. package/microservices/microservice-notes/src/db/migrations.ts +0 -40
  168. package/microservices/microservice-notes/src/db/notes.ts +0 -114
  169. package/microservices/microservice-notes/src/index.ts +0 -2
  170. package/microservices/microservice-notes/src/mcp/index.ts +0 -37
  171. package/microservices/microservice-notifications/package.json +0 -27
  172. package/microservices/microservice-notifications/src/cli/index.ts +0 -349
  173. package/microservices/microservice-notifications/src/db/database.ts +0 -93
  174. package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
  175. package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
  176. package/microservices/microservice-notifications/src/index.ts +0 -41
  177. package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
  178. package/microservices/microservice-payments/package.json +0 -27
  179. package/microservices/microservice-payments/src/cli/index.ts +0 -609
  180. package/microservices/microservice-payments/src/db/database.ts +0 -93
  181. package/microservices/microservice-payments/src/db/migrations.ts +0 -81
  182. package/microservices/microservice-payments/src/db/payments.ts +0 -1204
  183. package/microservices/microservice-payments/src/index.ts +0 -51
  184. package/microservices/microservice-payments/src/mcp/index.ts +0 -683
  185. package/microservices/microservice-payroll/package.json +0 -27
  186. package/microservices/microservice-payroll/src/cli/index.ts +0 -643
  187. package/microservices/microservice-payroll/src/db/database.ts +0 -93
  188. package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
  189. package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
  190. package/microservices/microservice-payroll/src/index.ts +0 -48
  191. package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
  192. package/microservices/microservice-products/package.json +0 -27
  193. package/microservices/microservice-products/src/cli/index.ts +0 -416
  194. package/microservices/microservice-products/src/db/categories.ts +0 -154
  195. package/microservices/microservice-products/src/db/database.ts +0 -93
  196. package/microservices/microservice-products/src/db/migrations.ts +0 -58
  197. package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
  198. package/microservices/microservice-products/src/db/products.ts +0 -452
  199. package/microservices/microservice-products/src/index.ts +0 -53
  200. package/microservices/microservice-products/src/mcp/index.ts +0 -453
  201. package/microservices/microservice-projects/package.json +0 -27
  202. package/microservices/microservice-projects/src/cli/index.ts +0 -480
  203. package/microservices/microservice-projects/src/db/database.ts +0 -93
  204. package/microservices/microservice-projects/src/db/migrations.ts +0 -65
  205. package/microservices/microservice-projects/src/db/projects.ts +0 -715
  206. package/microservices/microservice-projects/src/index.ts +0 -57
  207. package/microservices/microservice-projects/src/mcp/index.ts +0 -501
  208. package/microservices/microservice-proposals/package.json +0 -27
  209. package/microservices/microservice-proposals/src/cli/index.ts +0 -400
  210. package/microservices/microservice-proposals/src/db/database.ts +0 -93
  211. package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
  212. package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
  213. package/microservices/microservice-proposals/src/index.ts +0 -37
  214. package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
  215. package/microservices/microservice-reading/package.json +0 -27
  216. package/microservices/microservice-reading/src/cli/index.ts +0 -464
  217. package/microservices/microservice-reading/src/db/database.ts +0 -93
  218. package/microservices/microservice-reading/src/db/migrations.ts +0 -59
  219. package/microservices/microservice-reading/src/db/reading.ts +0 -524
  220. package/microservices/microservice-reading/src/index.ts +0 -51
  221. package/microservices/microservice-reading/src/mcp/index.ts +0 -368
  222. package/microservices/microservice-shipping/package.json +0 -27
  223. package/microservices/microservice-shipping/src/cli/index.ts +0 -606
  224. package/microservices/microservice-shipping/src/db/database.ts +0 -93
  225. package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
  226. package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
  227. package/microservices/microservice-shipping/src/index.ts +0 -53
  228. package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
  229. package/microservices/microservice-social/package.json +0 -28
  230. package/microservices/microservice-social/src/cli/index.ts +0 -1583
  231. package/microservices/microservice-social/src/db/database.ts +0 -93
  232. package/microservices/microservice-social/src/db/migrations.ts +0 -160
  233. package/microservices/microservice-social/src/db/social.ts +0 -1076
  234. package/microservices/microservice-social/src/index.ts +0 -46
  235. package/microservices/microservice-social/src/lib/audience.ts +0 -353
  236. package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
  237. package/microservices/microservice-social/src/lib/media.ts +0 -311
  238. package/microservices/microservice-social/src/lib/mentions.ts +0 -434
  239. package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
  240. package/microservices/microservice-social/src/lib/publisher.ts +0 -377
  241. package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
  242. package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
  243. package/microservices/microservice-social/src/lib/threads.ts +0 -291
  244. package/microservices/microservice-social/src/mcp/index.ts +0 -1425
  245. package/microservices/microservice-social/src/server/index.ts +0 -441
  246. package/microservices/microservice-subscriptions/package.json +0 -27
  247. package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
  248. package/microservices/microservice-subscriptions/src/db/database.ts +0 -93
  249. package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
  250. package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
  251. package/microservices/microservice-subscriptions/src/index.ts +0 -41
  252. package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
  253. package/microservices/microservice-timesheets/package.json +0 -27
  254. package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
  255. package/microservices/microservice-timesheets/src/db/database.ts +0 -82
  256. package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
  257. package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
  258. package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
  259. package/microservices/microservice-timesheets/src/index.ts +0 -44
  260. package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
  261. package/microservices/microservice-transcriber/package.json +0 -28
  262. package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
  263. package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
  264. package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
  265. package/microservices/microservice-transcriber/src/db/database.ts +0 -82
  266. package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
  267. package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
  268. package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
  269. package/microservices/microservice-transcriber/src/index.ts +0 -43
  270. package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
  271. package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
  272. package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
  273. package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
  274. package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
  275. package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
  276. package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
  277. package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
  278. package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
  279. package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
  280. package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
  281. package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
  282. package/microservices/microservice-transcriber/src/server/index.ts +0 -199
  283. package/microservices/microservice-travel/package.json +0 -27
  284. package/microservices/microservice-travel/src/cli/index.ts +0 -505
  285. package/microservices/microservice-travel/src/db/database.ts +0 -93
  286. package/microservices/microservice-travel/src/db/migrations.ts +0 -77
  287. package/microservices/microservice-travel/src/db/travel.ts +0 -802
  288. package/microservices/microservice-travel/src/index.ts +0 -60
  289. package/microservices/microservice-travel/src/mcp/index.ts +0 -495
  290. package/microservices/microservice-wiki/package.json +0 -27
  291. package/microservices/microservice-wiki/src/cli/index.ts +0 -345
  292. package/microservices/microservice-wiki/src/db/database.ts +0 -93
  293. package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
  294. package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
  295. package/microservices/microservice-wiki/src/index.ts +0 -32
  296. package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
@@ -1,713 +0,0 @@
1
- /**
2
- * Transcription providers — ElevenLabs (default) and OpenAI Whisper.
3
- */
4
-
5
- import { readFileSync, unlinkSync, existsSync, statSync } from "node:fs";
6
- import { basename } from "node:path";
7
- import type { TranscriptChapterSegment, TranscriptMetadata, TranscriptProvider, TranscriptSpeakerSegment, TranscriptWord } from "../db/transcripts.js";
8
- import type { VideoChapter } from "./downloader.js";
9
- import { getAudioDuration, splitAudioIntoChunks } from "./downloader.js";
10
-
11
- export interface TranscriptionResult {
12
- text: string;
13
- language: string;
14
- duration_seconds: number | null;
15
- metadata: TranscriptMetadata;
16
- }
17
-
18
- export interface TranscribeOptions {
19
- provider?: TranscriptProvider;
20
- language?: string;
21
- diarize?: boolean;
22
- vocab?: string[]; // custom vocabulary hints
23
- chunkDurationSec?: number; // override auto-chunk size (default: 600 = 10 min)
24
- }
25
-
26
- const AUTO_CHUNK_THRESHOLD_SEC = 600; // 10 minutes
27
-
28
- /**
29
- * Transcribe an audio file using the specified provider.
30
- * Auto-chunks files longer than 10 minutes — splits into segments,
31
- * transcribes each, then combines results with correct timestamp offsets.
32
- */
33
- export async function transcribeFile(
34
- filePath: string,
35
- options: TranscribeOptions = {}
36
- ): Promise<TranscriptionResult> {
37
- const provider = options.provider ?? "elevenlabs";
38
- const chunkDuration = options.chunkDurationSec ?? AUTO_CHUNK_THRESHOLD_SEC;
39
-
40
- // Check duration — auto-chunk if long
41
- let duration: number;
42
- try {
43
- duration = await getAudioDuration(filePath);
44
- } catch {
45
- duration = 0; // can't probe — just send it as-is
46
- }
47
-
48
- if (duration > chunkDuration) {
49
- return transcribeChunked(filePath, duration, chunkDuration, options);
50
- }
51
-
52
- return transcribeSingle(filePath, options);
53
- }
54
-
55
- async function transcribeSingle(
56
- filePath: string,
57
- options: TranscribeOptions
58
- ): Promise<TranscriptionResult> {
59
- const provider = options.provider ?? "elevenlabs";
60
-
61
- if (provider === "elevenlabs") {
62
- return transcribeWithElevenLabs(filePath, options.language, options.diarize, options.vocab);
63
- } else if (provider === "openai") {
64
- return transcribeWithOpenAI(filePath, options.language, options.vocab);
65
- } else if (provider === "deepgram") {
66
- return transcribeWithDeepGram(filePath, options.language, options.diarize, options.vocab);
67
- }
68
-
69
- throw new Error(`Unknown provider: ${provider}`);
70
- }
71
-
72
- /**
73
- * Chunk-based transcription: splits audio, transcribes each chunk,
74
- * combines text and word arrays with correct timestamp offsets.
75
- */
76
- async function transcribeChunked(
77
- filePath: string,
78
- totalDuration: number,
79
- chunkDuration: number,
80
- options: TranscribeOptions
81
- ): Promise<TranscriptionResult> {
82
- const chunks = await splitAudioIntoChunks(filePath, chunkDuration);
83
-
84
- const allTexts: string[] = [];
85
- const allWords: TranscriptWord[] = [];
86
- let language = "en";
87
- let model: string | undefined;
88
- let diarized = false;
89
- const allSpeakers: TranscriptSpeakerSegment[] = [];
90
-
91
- try {
92
- for (let i = 0; i < chunks.length; i++) {
93
- const chunk = chunks[i];
94
- const result = await transcribeSingle(chunk.path, options);
95
-
96
- allTexts.push(result.text);
97
- language = result.language;
98
- model = result.metadata.model;
99
- if (result.metadata.diarized) diarized = true;
100
-
101
- // Offset word timestamps by chunk start position
102
- if (result.metadata.words) {
103
- for (const w of result.metadata.words) {
104
- allWords.push({
105
- ...w,
106
- start: w.start + chunk.startOffset,
107
- end: w.end + chunk.startOffset,
108
- });
109
- }
110
- }
111
-
112
- // Offset speaker segments
113
- if (result.metadata.speakers) {
114
- for (const s of result.metadata.speakers) {
115
- allSpeakers.push({
116
- ...s,
117
- start: s.start + chunk.startOffset,
118
- end: s.end + chunk.startOffset,
119
- });
120
- }
121
- }
122
- }
123
- } finally {
124
- // Clean up chunk temp files (don't delete original)
125
- for (const chunk of chunks) {
126
- if (chunk.path !== filePath) {
127
- try { if (existsSync(chunk.path)) unlinkSync(chunk.path); } catch {}
128
- }
129
- }
130
- }
131
-
132
- const combinedText = allTexts.join("\n\n");
133
-
134
- return {
135
- text: combinedText,
136
- language,
137
- duration_seconds: totalDuration,
138
- metadata: {
139
- model,
140
- words: allWords.length > 0 ? allWords : undefined,
141
- speakers: allSpeakers.length > 0 ? allSpeakers : undefined,
142
- ...(diarized ? { diarized: true } : {}),
143
- },
144
- };
145
- }
146
-
147
- // ---------------------------------------------------------------------------
148
- // ElevenLabs
149
- // ---------------------------------------------------------------------------
150
-
151
- async function transcribeWithElevenLabs(
152
- filePath: string,
153
- language?: string,
154
- diarize?: boolean,
155
- vocab?: string[]
156
- ): Promise<TranscriptionResult> {
157
- const apiKey = process.env["ELEVENLABS_API_KEY"];
158
- if (!apiKey) throw new Error("ELEVENLABS_API_KEY is not set");
159
-
160
- const fileName = basename(filePath);
161
- const fileSize = statSync(filePath).size;
162
- if (fileSize === 0) throw new Error(`Audio file is empty: ${filePath}`);
163
-
164
- // Use Bun.file() for proper streaming file upload (handles large files correctly)
165
- const audioFile = Bun.file(filePath);
166
-
167
- const form = new FormData();
168
- form.append("file", audioFile, fileName);
169
- form.append("model_id", "scribe_v1");
170
- form.append("timestamps_granularity", "word");
171
- if (language) form.append("language_code", language);
172
- if (diarize) form.append("diarize", "true");
173
- if (vocab && vocab.length > 0) {
174
- // ElevenLabs accepts custom_spelling as JSON array of {from, to} for custom vocab
175
- form.append("custom_spelling", JSON.stringify(vocab.map((v) => ({ from: v.toLowerCase(), to: v }))));
176
- }
177
-
178
- const res = await fetch("https://api.elevenlabs.io/v1/speech-to-text", {
179
- method: "POST",
180
- headers: { "xi-api-key": apiKey },
181
- body: form,
182
- });
183
-
184
- if (!res.ok) {
185
- const body = await res.text();
186
- throw new Error(`ElevenLabs API error ${res.status}: ${body}`);
187
- }
188
-
189
- const data = (await res.json()) as {
190
- text: string;
191
- language_code: string;
192
- language_probability: number;
193
- words?: Array<{ text: string; type: string; start: number; end: number; speaker_id?: string; logprob?: number }>;
194
- };
195
-
196
- const words = (data.words ?? [])
197
- .filter((w) => w.type === "word")
198
- .map((w) => ({
199
- text: w.text,
200
- start: w.start,
201
- end: w.end,
202
- type: w.type,
203
- speaker_id: w.speaker_id,
204
- ...(w.logprob !== undefined ? { logprob: w.logprob } : {}),
205
- }));
206
-
207
- const duration = words.length > 0 ? words[words.length - 1].end : null;
208
-
209
- // Build speaker segments and formatted text when diarized
210
- let text = data.text;
211
- let speakers: TranscriptSpeakerSegment[] | undefined;
212
-
213
- if (diarize && words.some((w) => w.speaker_id)) {
214
- speakers = buildSpeakerSegments(words);
215
- text = formatDiarizedText(speakers);
216
- }
217
-
218
- return {
219
- text,
220
- language: data.language_code ?? language ?? "en",
221
- duration_seconds: duration,
222
- metadata: {
223
- model: "scribe_v1",
224
- words,
225
- speakers,
226
- language_probability: data.language_probability,
227
- ...(diarize ? { diarized: true } : {}),
228
- },
229
- };
230
- }
231
-
232
- function buildSpeakerSegments(
233
- words: Array<{ text: string; start: number; end: number; speaker_id?: string }>
234
- ): TranscriptSpeakerSegment[] {
235
- const segments: TranscriptSpeakerSegment[] = [];
236
- let current: TranscriptSpeakerSegment | null = null;
237
-
238
- for (const word of words) {
239
- const speakerId = word.speaker_id ?? "speaker_unknown";
240
- if (!current || current.speaker_id !== speakerId) {
241
- if (current) segments.push(current);
242
- current = { speaker_id: speakerId, start: word.start, end: word.end, text: word.text };
243
- } else {
244
- current.end = word.end;
245
- current.text += " " + word.text;
246
- }
247
- }
248
- if (current) segments.push(current);
249
- return segments;
250
- }
251
-
252
- function formatDiarizedText(segments: TranscriptSpeakerSegment[]): string {
253
- return segments
254
- .map((s) => {
255
- // Convert "speaker_0" → "Speaker 1" (1-indexed for readability)
256
- const label = s.speaker_id.replace(/speaker_(\d+)/, (_, n) => `Speaker ${parseInt(n) + 1}`);
257
- return `${label}: ${s.text}`;
258
- })
259
- .join("\n");
260
- }
261
-
262
- // ---------------------------------------------------------------------------
263
- // OpenAI Whisper
264
- // ---------------------------------------------------------------------------
265
-
266
- async function transcribeWithOpenAI(
267
- filePath: string,
268
- language?: string,
269
- vocab?: string[]
270
- ): Promise<TranscriptionResult> {
271
- const apiKey = process.env["OPENAI_API_KEY"];
272
- if (!apiKey) throw new Error("OPENAI_API_KEY is not set");
273
-
274
- const fileName = basename(filePath);
275
- const audioFile = Bun.file(filePath);
276
-
277
- const form = new FormData();
278
- form.append("file", audioFile, fileName);
279
- form.append("model", "whisper-1");
280
- form.append("response_format", "verbose_json");
281
- form.append("timestamp_granularities[]", "word");
282
- form.append("timestamp_granularities[]", "segment");
283
- if (language) form.append("language", language);
284
- if (vocab && vocab.length > 0) {
285
- // OpenAI Whisper uses prompt field for vocabulary hints
286
- form.append("prompt", vocab.join(", "));
287
- }
288
-
289
- const res = await fetch("https://api.openai.com/v1/audio/transcriptions", {
290
- method: "POST",
291
- headers: { Authorization: `Bearer ${apiKey}` },
292
- body: form,
293
- });
294
-
295
- if (!res.ok) {
296
- const body = await res.text();
297
- throw new Error(`OpenAI API error ${res.status}: ${body}`);
298
- }
299
-
300
- const data = (await res.json()) as {
301
- text: string;
302
- language: string;
303
- duration: number;
304
- words?: Array<{ word: string; start: number; end: number }>;
305
- segments?: Array<{ start: number; end: number; text: string }>;
306
- };
307
-
308
- const words = (data.words ?? []).map((w) => ({
309
- text: w.word,
310
- start: w.start,
311
- end: w.end,
312
- }));
313
-
314
- const segments = (data.segments ?? []).map((s) => ({
315
- start: s.start,
316
- end: s.end,
317
- text: s.text,
318
- }));
319
-
320
- return {
321
- text: data.text,
322
- language: data.language ?? language ?? "en",
323
- duration_seconds: data.duration ?? null,
324
- metadata: {
325
- model: "whisper-1",
326
- words,
327
- segments,
328
- },
329
- };
330
- }
331
-
332
- // ---------------------------------------------------------------------------
333
- // Provider availability check
334
- // ---------------------------------------------------------------------------
335
-
336
- // ---------------------------------------------------------------------------
337
- // Cost calculation
338
- // ---------------------------------------------------------------------------
339
-
340
- // Rates per minute (approximate, as of 2025)
341
- const COST_PER_MINUTE: Record<string, number> = {
342
- elevenlabs: 0.40 / 60, // ~$0.40/hr = $0.00667/min
343
- openai: 0.006, // $0.006/min for Whisper
344
- };
345
-
346
- /**
347
- * Estimate transcription cost in USD based on provider and duration.
348
- */
349
- export function estimateCost(provider: string, durationSeconds: number): number {
350
- const rate = COST_PER_MINUTE[provider] ?? 0;
351
- return Math.round(rate * (durationSeconds / 60) * 10000) / 10000; // 4 decimal places
352
- }
353
-
354
- export function checkProviders(): { elevenlabs: boolean; openai: boolean; deepgram: boolean } {
355
- return {
356
- elevenlabs: !!process.env["ELEVENLABS_API_KEY"],
357
- openai: !!process.env["OPENAI_API_KEY"],
358
- deepgram: !!process.env["DEEPGRAM_API_KEY"],
359
- };
360
- }
361
-
362
- // ---------------------------------------------------------------------------
363
- // DeepGram
364
- // ---------------------------------------------------------------------------
365
-
366
- async function transcribeWithDeepGram(
367
- filePath: string,
368
- language?: string,
369
- diarize?: boolean,
370
- vocab?: string[]
371
- ): Promise<TranscriptionResult> {
372
- const apiKey = process.env["DEEPGRAM_API_KEY"];
373
- if (!apiKey) throw new Error("DEEPGRAM_API_KEY is not set");
374
-
375
- const audioData = await Bun.file(filePath).arrayBuffer();
376
-
377
- const params = new URLSearchParams({
378
- model: "nova-3",
379
- smart_format: "true",
380
- punctuate: "true",
381
- utterances: "true",
382
- });
383
- if (language) params.set("language", language);
384
- if (diarize) params.set("diarize", "true");
385
- if (vocab && vocab.length > 0) params.set("keywords", vocab.join(":5,") + ":5");
386
-
387
- const res = await fetch(`https://api.deepgram.com/v1/listen?${params}`, {
388
- method: "POST",
389
- headers: {
390
- Authorization: `Token ${apiKey}`,
391
- "Content-Type": "audio/mpeg",
392
- },
393
- body: audioData,
394
- });
395
-
396
- if (!res.ok) {
397
- const body = await res.text();
398
- throw new Error(`DeepGram API error ${res.status}: ${body}`);
399
- }
400
-
401
- const data = (await res.json()) as {
402
- results: {
403
- channels: Array<{
404
- alternatives: Array<{
405
- transcript: string;
406
- words: Array<{ word: string; start: number; end: number; speaker?: number; confidence: number }>;
407
- }>;
408
- }>;
409
- utterances?: Array<{ start: number; end: number; transcript: string; speaker: number }>;
410
- };
411
- metadata: { duration: number; language?: string };
412
- };
413
-
414
- const alt = data.results.channels[0]?.alternatives[0];
415
- if (!alt) throw new Error("DeepGram returned no results");
416
-
417
- const words = alt.words.map((w) => ({
418
- text: w.word,
419
- start: w.start,
420
- end: w.end,
421
- ...(w.speaker !== undefined ? { speaker_id: `speaker_${w.speaker}` } : {}),
422
- logprob: Math.log(w.confidence), // convert confidence to logprob
423
- }));
424
-
425
- let text = alt.transcript;
426
- let speakers: TranscriptSpeakerSegment[] | undefined;
427
-
428
- if (diarize && data.results.utterances) {
429
- speakers = data.results.utterances.map((u) => ({
430
- speaker_id: `speaker_${u.speaker}`,
431
- start: u.start,
432
- end: u.end,
433
- text: u.transcript,
434
- }));
435
- text = speakers.map((s) => {
436
- const label = s.speaker_id.replace(/speaker_(\d+)/, (_, n) => `Speaker ${parseInt(n) + 1}`);
437
- return `${label}: ${s.text}`;
438
- }).join("\n");
439
- }
440
-
441
- return {
442
- text,
443
- language: data.metadata.language ?? language ?? "en",
444
- duration_seconds: data.metadata.duration ?? null,
445
- metadata: {
446
- model: "nova-3",
447
- words,
448
- speakers,
449
- ...(diarize ? { diarized: true } : {}),
450
- },
451
- };
452
- }
453
-
454
- // ---------------------------------------------------------------------------
455
- // Markdown export helper
456
- // ---------------------------------------------------------------------------
457
-
458
- import type { Transcript } from "../db/transcripts.js";
459
-
460
- function formatTimestamp(seconds: number): string {
461
- const h = Math.floor(seconds / 3600);
462
- const m = Math.floor((seconds % 3600) / 60);
463
- const s = Math.floor(seconds % 60);
464
- if (h > 0) return `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`;
465
- return `${m}:${String(s).padStart(2, "0")}`;
466
- }
467
-
468
- /**
469
- * Export a transcript as formatted Markdown.
470
- * Chapters become ## headings, speaker labels are **bolded**, timestamps inline.
471
- */
472
- export function toMarkdown(t: Transcript): string {
473
- const lines: string[] = [];
474
-
475
- // Title
476
- lines.push(`# ${t.title ?? "Transcript"}`);
477
- lines.push("");
478
-
479
- // Metadata
480
- if (t.source_url) lines.push(`> Source: ${t.source_url}`);
481
- if (t.duration_seconds) lines.push(`> Duration: ${formatTimestamp(t.duration_seconds)}`);
482
- if (t.provider) lines.push(`> Provider: ${t.provider}`);
483
- lines.push("");
484
-
485
- // Summary
486
- if (t.metadata?.summary) {
487
- lines.push("## Summary", "", t.metadata.summary, "");
488
- }
489
-
490
- // Chapters with text
491
- if (t.metadata?.chapters && t.metadata.chapters.length > 0) {
492
- for (const ch of t.metadata.chapters) {
493
- lines.push(`## ${ch.title}`, "");
494
- lines.push(`_[${formatTimestamp(ch.start_time)}]_`, "");
495
- // Format text with speaker labels bolded
496
- const formatted = ch.text.replace(/(Speaker \d+|[A-Z][a-z]+ [A-Z][a-z]+):/g, "\n\n**$1:**");
497
- lines.push(formatted.trim(), "");
498
- }
499
- } else if (t.metadata?.speakers && t.metadata.speakers.length > 0) {
500
- // Diarized without chapters — use speaker segments
501
- for (const seg of t.metadata.speakers) {
502
- const label = seg.speaker_id.replace(/speaker_(\d+)/, (_, n) => `Speaker ${parseInt(n) + 1}`);
503
- const ts = formatTimestamp(seg.start);
504
- lines.push(`**${label}** _[${ts}]_: ${seg.text}`, "");
505
- }
506
- } else if (t.transcript_text) {
507
- // Plain text — bold any speaker labels
508
- const formatted = t.transcript_text.replace(/(Speaker \d+|[A-Z][a-z]+ [A-Z][a-z]+):/g, "\n\n**$1:**");
509
- lines.push(formatted.trim());
510
- }
511
-
512
- return lines.join("\n");
513
- }
514
-
515
- // ---------------------------------------------------------------------------
516
- // SRT export helper
517
- // ---------------------------------------------------------------------------
518
-
519
- export function toSrt(words: Array<{ text: string; start: number; end: number }>): string {
520
- if (words.length === 0) return "";
521
-
522
- const lines: string[] = [];
523
- const chunkSize = 10; // words per subtitle block
524
- let idx = 1;
525
-
526
- for (let i = 0; i < words.length; i += chunkSize) {
527
- const chunk = words.slice(i, i + chunkSize);
528
- const start = formatSrtTime(chunk[0].start);
529
- const end = formatSrtTime(chunk[chunk.length - 1].end);
530
- const text = chunk.map((w) => w.text).join(" ");
531
- lines.push(`${idx}\n${start} --> ${end}\n${text}\n`);
532
- idx++;
533
- }
534
-
535
- return lines.join("\n");
536
- }
537
-
538
- function formatSrtTime(seconds: number): string {
539
- const h = Math.floor(seconds / 3600);
540
- const m = Math.floor((seconds % 3600) / 60);
541
- const s = Math.floor(seconds % 60);
542
- const ms = Math.round((seconds % 1) * 1000);
543
- return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")},${String(ms).padStart(3, "0")}`;
544
- }
545
-
546
- // ---------------------------------------------------------------------------
547
- // Chapter segmentation helper
548
- // ---------------------------------------------------------------------------
549
-
550
- /**
551
- * Map word-level timestamps to video chapters, producing chapter-labelled segments.
552
- * Words that don't fall cleanly within any chapter are attributed to the nearest chapter.
553
- */
554
- export function segmentByChapters(
555
- words: Array<{ text: string; start: number; end: number }>,
556
- chapters: VideoChapter[]
557
- ): TranscriptChapterSegment[] {
558
- if (chapters.length === 0 || words.length === 0) return [];
559
-
560
- const segments: TranscriptChapterSegment[] = chapters.map((ch) => ({
561
- title: ch.title,
562
- start_time: ch.start_time,
563
- end_time: ch.end_time,
564
- text: "",
565
- }));
566
-
567
- for (const word of words) {
568
- // Find chapter that contains the word's midpoint
569
- const mid = (word.start + word.end) / 2;
570
- let idx = segments.findIndex((s) => mid >= s.start_time && mid < s.end_time);
571
- // Fall back to last chapter if midpoint is beyond last chapter end
572
- if (idx === -1) idx = segments.length - 1;
573
- segments[idx].text = segments[idx].text ? segments[idx].text + " " + word.text : word.text;
574
- }
575
-
576
- return segments.filter((s) => s.text.length > 0);
577
- }
578
-
579
- // ---------------------------------------------------------------------------
580
- // VTT (WebVTT) export helper
581
- // ---------------------------------------------------------------------------
582
-
583
- export function toVtt(words: Array<{ text: string; start: number; end: number }>): string {
584
- if (words.length === 0) return "WEBVTT\n";
585
-
586
- const lines: string[] = ["WEBVTT", ""];
587
- const chunkSize = 10;
588
-
589
- for (let i = 0; i < words.length; i += chunkSize) {
590
- const chunk = words.slice(i, i + chunkSize);
591
- const start = formatVttTime(chunk[0].start);
592
- const end = formatVttTime(chunk[chunk.length - 1].end);
593
- const text = chunk.map((w) => w.text).join(" ");
594
- lines.push(`${start} --> ${end}`, text, "");
595
- }
596
-
597
- return lines.join("\n");
598
- }
599
-
600
- function formatVttTime(seconds: number): string {
601
- const h = Math.floor(seconds / 3600);
602
- const m = Math.floor((seconds % 3600) / 60);
603
- const s = Math.floor(seconds % 60);
604
- const ms = Math.round((seconds % 1) * 1000);
605
- // VTT omits hours if zero, uses . not ,
606
- if (h > 0) {
607
- return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}.${String(ms).padStart(3, "0")}`;
608
- }
609
- return `${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}.${String(ms).padStart(3, "0")}`;
610
- }
611
-
612
- // ---------------------------------------------------------------------------
613
- // ASS (Advanced SubStation Alpha) export helper
614
- // ---------------------------------------------------------------------------
615
-
616
- export interface AssStyle {
617
- fontName?: string; // default: "Arial"
618
- fontSize?: number; // default: 20
619
- color?: string; // hex RGB e.g. "FFFFFF" or "#FFFFFF" (default: white)
620
- outline?: number; // default: 2
621
- shadow?: number; // default: 1
622
- }
623
-
624
- /**
625
- * Convert #RRGGBB or RRGGBB hex to ASS &HAABBGGRR color (alpha=00=opaque).
626
- */
627
- function hexToAssColor(hex: string): string {
628
- const clean = hex.replace("#", "").padStart(6, "0");
629
- const r = clean.slice(0, 2);
630
- const g = clean.slice(2, 4);
631
- const b = clean.slice(4, 6);
632
- return `&H00${b}${g}${r}`.toUpperCase();
633
- }
634
-
635
- function formatAssTime(seconds: number): string {
636
- const h = Math.floor(seconds / 3600);
637
- const m = Math.floor((seconds % 3600) / 60);
638
- const s = Math.floor(seconds % 60);
639
- // ASS uses centiseconds (2 digits)
640
- const cs = Math.round((seconds % 1) * 100);
641
- return `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}.${String(cs).padStart(2, "0")}`;
642
- }
643
-
644
- // ---------------------------------------------------------------------------
645
- // Confidence filtering helper
646
- // ---------------------------------------------------------------------------
647
-
648
- /**
649
- * Rebuild transcript text with low-confidence words wrapped in [?..?] markers.
650
- * Only applies to ElevenLabs transcripts that have logprob on words.
651
- *
652
- * @param words - word array with optional logprob
653
- * @param threshold - confidence threshold 0.0–1.0 (default 0.7). Words below this are flagged.
654
- */
655
- export function formatWithConfidence(
656
- words: Array<{ text: string; logprob?: number }>,
657
- threshold = 0.7
658
- ): string {
659
- return words
660
- .map((w) => {
661
- if (w.logprob === undefined) return w.text;
662
- const confidence = Math.exp(w.logprob);
663
- return confidence < threshold ? `[?${w.text}?]` : w.text;
664
- })
665
- .join(" ");
666
- }
667
-
668
- export function toAss(
669
- words: Array<{ text: string; start: number; end: number }>,
670
- style: AssStyle = {}
671
- ): string {
672
- if (words.length === 0) return "";
673
-
674
- const fontName = style.fontName ?? "Arial";
675
- const fontSize = style.fontSize ?? 20;
676
- const primaryColor = hexToAssColor(style.color ?? "FFFFFF");
677
- const outline = style.outline ?? 2;
678
- const shadow = style.shadow ?? 1;
679
-
680
- const scriptInfo = [
681
- "[Script Info]",
682
- "ScriptType: v4.00+",
683
- "PlayResX: 384",
684
- "PlayResY: 288",
685
- "ScaledBorderAndShadow: yes",
686
- "",
687
- ].join("\n");
688
-
689
- const stylesSection = [
690
- "[V4+ Styles]",
691
- "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding",
692
- `Style: Default,${fontName},${fontSize},${primaryColor},&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,${outline},${shadow},2,10,10,10,1`,
693
- "",
694
- ].join("\n");
695
-
696
- const eventsHeader = [
697
- "[Events]",
698
- "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text",
699
- ].join("\n");
700
-
701
- const chunkSize = 10;
702
- const dialogues: string[] = [];
703
-
704
- for (let i = 0; i < words.length; i += chunkSize) {
705
- const chunk = words.slice(i, i + chunkSize);
706
- const start = formatAssTime(chunk[0].start);
707
- const end = formatAssTime(chunk[chunk.length - 1].end);
708
- const text = chunk.map((w) => w.text).join(" ");
709
- dialogues.push(`Dialogue: 0,${start},${end},Default,,0,0,0,,${text}`);
710
- }
711
-
712
- return [scriptInfo, stylesSection, eventsHeader, ...dialogues].join("\n");
713
- }