@vocasync/astro 0.1.9 → 1.0.0

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 (78) hide show
  1. package/README.md +77 -41
  2. package/dist/api/client.d.ts +63 -50
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +132 -145
  5. package/dist/api/client.js.map +1 -1
  6. package/dist/api/index.d.ts +1 -1
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/index.js +1 -1
  9. package/dist/api/index.js.map +1 -1
  10. package/dist/cli.js +7 -7
  11. package/dist/cli.js.map +1 -1
  12. package/dist/components/AudioPlayer.astro +136 -137
  13. package/dist/config/schema.d.ts +21 -20
  14. package/dist/config/schema.d.ts.map +1 -1
  15. package/dist/config/schema.js +15 -4
  16. package/dist/config/schema.js.map +1 -1
  17. package/dist/core/audio-map.js +1 -1
  18. package/dist/core/speech-builder.d.ts +10 -7
  19. package/dist/core/speech-builder.d.ts.map +1 -1
  20. package/dist/core/speech-builder.js +73 -168
  21. package/dist/core/speech-builder.js.map +1 -1
  22. package/dist/core/spoken-form.d.ts +52 -0
  23. package/dist/core/spoken-form.d.ts.map +1 -0
  24. package/dist/core/spoken-form.js +279 -0
  25. package/dist/core/spoken-form.js.map +1 -0
  26. package/dist/lib/latex-to-speech/index.d.ts +9 -2
  27. package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
  28. package/dist/lib/latex-to-speech/index.js +20 -22
  29. package/dist/lib/latex-to-speech/index.js.map +1 -1
  30. package/dist/lib/latex-to-speech/speak.d.ts +13 -0
  31. package/dist/lib/latex-to-speech/speak.d.ts.map +1 -0
  32. package/dist/lib/latex-to-speech/speak.js +47 -0
  33. package/dist/lib/latex-to-speech/speak.js.map +1 -0
  34. package/dist/rehype/audio-words.d.ts +14 -24
  35. package/dist/rehype/audio-words.d.ts.map +1 -1
  36. package/dist/rehype/audio-words.js +131 -252
  37. package/dist/rehype/audio-words.js.map +1 -1
  38. package/dist/rehype/index.d.ts +1 -2
  39. package/dist/rehype/index.d.ts.map +1 -1
  40. package/dist/rehype/index.js +0 -1
  41. package/dist/rehype/index.js.map +1 -1
  42. package/dist/rehype/rehype-math-speech.d.ts +26 -10
  43. package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
  44. package/dist/rehype/rehype-math-speech.js +59 -92
  45. package/dist/rehype/rehype-math-speech.js.map +1 -1
  46. package/dist/rehype/shared.d.ts +9 -0
  47. package/dist/rehype/shared.d.ts.map +1 -0
  48. package/dist/rehype/shared.js +31 -0
  49. package/dist/rehype/shared.js.map +1 -0
  50. package/dist/sync/orchestrator.d.ts +4 -22
  51. package/dist/sync/orchestrator.d.ts.map +1 -1
  52. package/dist/sync/orchestrator.js +123 -123
  53. package/dist/sync/orchestrator.js.map +1 -1
  54. package/dist/types/index.d.ts +82 -46
  55. package/dist/types/index.d.ts.map +1 -1
  56. package/package.json +14 -11
  57. package/src/api/client.ts +175 -190
  58. package/src/api/index.ts +8 -1
  59. package/src/cli.ts +7 -14
  60. package/src/components/AudioPlayer.astro +136 -137
  61. package/src/config/schema.ts +15 -4
  62. package/src/core/audio-map.ts +1 -1
  63. package/src/core/speech-builder.ts +75 -192
  64. package/src/core/spoken-form.ts +298 -0
  65. package/src/lib/latex-to-speech/index.ts +32 -22
  66. package/src/lib/latex-to-speech/speak.ts +55 -0
  67. package/src/rehype/audio-words.ts +145 -307
  68. package/src/rehype/index.ts +1 -2
  69. package/src/rehype/rehype-math-speech.ts +64 -117
  70. package/src/rehype/shared.ts +36 -0
  71. package/src/sync/orchestrator.ts +150 -157
  72. package/src/types/index.ts +85 -47
  73. package/src/types/modules.d.ts +5 -2
  74. package/dist/rehype/remark-math-speech.d.ts +0 -13
  75. package/dist/rehype/remark-math-speech.d.ts.map +0 -1
  76. package/dist/rehype/remark-math-speech.js +0 -26
  77. package/dist/rehype/remark-math-speech.js.map +0 -1
  78. package/src/rehype/remark-math-speech.ts +0 -31
@@ -1,206 +1,115 @@
1
1
  import remarkMath from "remark-math";
2
2
  import remarkParse from "remark-parse";
3
3
  import { unified } from "unified";
4
- import { computeHash } from "./hash-manager.js";
5
- // Cache for latex-to-speech results
6
- const latexSpeechCache = new Map();
7
- let latexToSpeech = null;
8
- let latexToSpeechLoadAttempted = false;
9
- let warnedLatexSpeechFailure = false;
10
- /**
11
- * Normalize whitespace in text.
12
- */
13
- function normalizeWhitespace(value = "") {
14
- return value.replace(/\r/g, "").replace(/\s+/g, " ").trim();
15
- }
16
- /**
17
- * Create a lazy-loaded LaTeX converter using our internal latex-to-speech module.
18
- * This uses speech-rule-engine and mathjax-full as optional peer dependencies.
19
- */
20
- async function createLatexConverter(config) {
21
- if (!config.enabled) {
22
- return null;
23
- }
24
- // Lazy load our internal latex-to-speech module
25
- if (!latexToSpeechLoadAttempted) {
26
- latexToSpeechLoadAttempted = true;
27
- try {
28
- const mod = await import("../lib/latex-to-speech/index.js");
29
- latexToSpeech = mod.latexToSpeech || mod.default;
30
- }
31
- catch {
32
- console.warn("[vocasync] Math-to-speech initialization failed. Install optional dependencies:", "\n npm install speech-rule-engine mathjax-full");
33
- }
34
- }
35
- if (!latexToSpeech) {
36
- return null;
37
- }
38
- const options = {
39
- domain: config.style || "clearspeak",
40
- style: "default",
41
- locale: "en",
42
- modality: "speech",
43
- };
44
- return {
45
- async convert(latex, display) {
46
- const trimmed = latex.trim();
47
- if (!trimmed)
48
- return "";
49
- const cacheKey = `${display}:${trimmed}`;
50
- if (!latexSpeechCache.has(cacheKey)) {
51
- const pending = (async () => {
52
- try {
53
- const result = await latexToSpeech([trimmed], options);
54
- const spoken = Array.isArray(result) ? result[0] : String(result ?? "");
55
- return normalizeWhitespace(spoken);
56
- }
57
- catch (error) {
58
- if (!warnedLatexSpeechFailure) {
59
- console.warn("[vocasync] Failed to convert LaTeX to speech:", error instanceof Error ? error.message : error);
60
- warnedLatexSpeechFailure = true;
61
- }
62
- return normalizeWhitespace(trimmed);
63
- }
64
- })();
65
- latexSpeechCache.set(cacheKey, pending);
66
- }
67
- return latexSpeechCache.get(cacheKey);
68
- },
69
- };
70
- }
4
+ import { speakLatex } from "../lib/latex-to-speech/speak.js";
5
+ import { buildSpeechtextPair } from "./spoken-form.js";
71
6
  /**
72
7
  * Build a speech document from markdown content.
73
- * Converts markdown to plain text suitable for TTS synthesis.
74
8
  *
75
- * @param item - The content item to process
76
- * @param options - Build options including math configuration
77
- * @returns A speech document ready for synthesis
9
+ * Produces plain text from the SAME visible tokens the rehype word-wrapper
10
+ * sees — no phantom tokens (no "Quote:", "Image:", "[Code in X]", inline
11
+ * code), and code blocks / images are skipped exactly as rehype skips
12
+ * `pre`/`code`/`img`. This keeps the alignment transcript
13
+ * (`normalisedSpeechtext`) token-for-token with the rehype `data-i` stream.
14
+ *
15
+ * Headings keep a leading "# " marker so the synthesis backend chunks at
16
+ * heading boundaries; `stripForAlignment` removes it, so it never becomes an
17
+ * alignment token. Math expressions contribute their `speakLatex` output at
18
+ * their reading position (the same string the rehype math handler counts).
78
19
  */
79
20
  export async function buildSpeechDocument(item, options = {}) {
80
21
  const mathConfig = options.math ?? { enabled: false, style: "clearspeak" };
81
- const latexConverter = await createLatexConverter(mathConfig);
82
- // Parse markdown with math support
22
+ const style = mathConfig.style || "clearspeak";
83
23
  const processor = unified().use(remarkParse).use(remarkMath);
84
24
  const tree = processor.parse(item.content);
85
- // Extract text from AST - can contain strings or promises
86
25
  const textParts = [];
26
+ // Collect math spoken forms keyed by `${'d'|'i'}:${latex}` so the rehype
27
+ // plugin can reuse them without running math-to-speech in the Vite build.
28
+ const mathKeys = [];
29
+ const mathPromises = [];
30
+ function recordMath(latex, display) {
31
+ const p = speakLatex(latex, display, style);
32
+ mathKeys.push(`${display ? "d" : "i"}:${latex.trim()}`);
33
+ mathPromises.push(p);
34
+ return p;
35
+ }
36
+ function processChildren(node) {
37
+ for (const child of node.children) {
38
+ processNode(child);
39
+ }
40
+ }
87
41
  function processNode(node) {
88
42
  switch (node.type) {
89
43
  case "text": {
90
- const textNode = node;
91
- textParts.push(textNode.value);
92
- break;
93
- }
94
- case "inlineCode": {
95
- const codeNode = node;
96
- // Skip short code, read longer code
97
- if (codeNode.value.length > 10) {
98
- textParts.push(codeNode.value);
99
- }
44
+ textParts.push(node.value);
100
45
  break;
101
46
  }
47
+ // Inline code and code blocks are skipped by the rehype word-wrapper
48
+ // (pre/code in its skip set), so they must not contribute speech tokens.
49
+ case "inlineCode":
102
50
  case "code": {
103
- const blockCode = node;
104
- // Skip code blocks entirely for TTS
105
- // Could optionally add language hint: "Code block in {lang}"
106
- if (blockCode.lang) {
107
- textParts.push(`[Code in ${blockCode.lang}]`);
108
- }
109
51
  break;
110
52
  }
111
53
  case "heading": {
112
54
  const heading = node;
113
- // Add single # marker for synthesis chunking (backend expects single # for all heading levels)
55
+ // Single "#" chunk marker for all heading levels (synthesis backend
56
+ // expects it). Removed by stripForAlignment, so not an alignment token.
114
57
  textParts.push("\n# ");
115
- // Process children
116
- for (const child of heading.children) {
117
- processNode(child);
118
- }
119
- // Add newline after headings for separation
58
+ processChildren(heading);
120
59
  textParts.push("\n");
121
60
  break;
122
61
  }
123
62
  case "paragraph": {
124
- const para = node;
125
- for (const child of para.children) {
126
- processNode(child);
127
- }
128
- // Paragraph break
63
+ processChildren(node);
129
64
  textParts.push("\n");
130
65
  break;
131
66
  }
132
67
  case "emphasis": {
133
- const em = node;
134
- for (const child of em.children) {
135
- processNode(child);
136
- }
68
+ processChildren(node);
137
69
  break;
138
70
  }
139
71
  case "strong": {
140
- const strong = node;
141
- for (const child of strong.children) {
142
- processNode(child);
143
- }
72
+ processChildren(node);
144
73
  break;
145
74
  }
146
75
  case "link": {
147
- const link = node;
148
- // Only read link text, not URL
149
- for (const child of link.children) {
150
- processNode(child);
151
- }
76
+ // Read link text only, not the URL (matches rehype: <a> text is walked).
77
+ processChildren(node);
152
78
  break;
153
79
  }
80
+ // Images are skipped by the rehype word-wrapper (img in its skip set);
81
+ // alt text is an attribute, not a rendered text node — emit nothing.
154
82
  case "image": {
155
- const img = node;
156
- // Read alt text
157
- if (img.alt) {
158
- textParts.push(`Image: ${img.alt}`);
159
- }
160
83
  break;
161
84
  }
162
85
  case "list": {
163
- const list = node;
164
- for (const child of list.children) {
165
- processNode(child);
166
- }
86
+ processChildren(node);
167
87
  break;
168
88
  }
169
89
  case "listItem": {
170
- const listItem = node;
171
- for (const child of listItem.children) {
172
- processNode(child);
173
- }
90
+ processChildren(node);
91
+ // Sentence break for TTS prosody; punctuation only, not an alignment token.
174
92
  textParts.push(". ");
175
93
  break;
176
94
  }
177
95
  case "blockquote": {
178
- const quote = node;
179
- textParts.push("Quote: ");
180
- for (const child of quote.children) {
181
- processNode(child);
182
- }
183
- textParts.push(" End quote.");
96
+ // Just the quote's text — no "Quote:"/"End quote." wrappers (those
97
+ // words have no rendered-DOM counterpart and would desync data-i).
98
+ processChildren(node);
99
+ textParts.push("\n");
184
100
  break;
185
101
  }
186
- // Math nodes from remark-math
187
102
  case "math": {
188
103
  const mathNode = node;
189
- if (latexConverter) {
190
- textParts.push(latexConverter.convert(mathNode.value, true));
191
- }
192
- else {
193
- textParts.push(`[Math: ${mathNode.value.slice(0, 30)}]`);
104
+ if (mathConfig.enabled) {
105
+ textParts.push(recordMath(mathNode.value, true));
194
106
  }
195
107
  break;
196
108
  }
197
109
  case "inlineMath": {
198
110
  const inlineMathNode = node;
199
- if (latexConverter) {
200
- textParts.push(latexConverter.convert(inlineMathNode.value, false));
201
- }
202
- else {
203
- textParts.push(inlineMathNode.value);
111
+ if (mathConfig.enabled) {
112
+ textParts.push(recordMath(inlineMathNode.value, false));
204
113
  }
205
114
  break;
206
115
  }
@@ -208,44 +117,40 @@ export async function buildSpeechDocument(item, options = {}) {
208
117
  textParts.push("\n\n");
209
118
  break;
210
119
  }
211
- // Handle container nodes with children
212
120
  case "root": {
213
- const root = node;
214
- for (const child of root.children) {
215
- processNode(child);
216
- }
121
+ processChildren(node);
217
122
  break;
218
123
  }
219
124
  default: {
220
- // Try to process children if they exist
221
125
  const maybeParent = node;
222
- if (maybeParent.children) {
223
- for (const child of maybeParent.children) {
224
- processNode(child);
225
- }
226
- }
126
+ if (maybeParent.children)
127
+ processChildren(maybeParent);
227
128
  }
228
129
  }
229
130
  }
230
131
  processNode(tree);
231
- // Resolve all promises in textParts (for async math conversion)
132
+ // Resolve async math conversions.
232
133
  const resolvedParts = await Promise.all(textParts);
233
- // Clean up and normalize text
234
- const text = resolvedParts
134
+ // Normalize whitespace. The title is intentionally excluded so the
135
+ // alignment data matches the article body only.
136
+ const plainText = resolvedParts
235
137
  .join(" ")
236
- .replace(/\s+/g, " ") // Normalize whitespace
237
- .replace(/\n\s*\n/g, "\n\n") // Preserve paragraph breaks
238
- .replace(/\s*\.\s*\./g, ".") // Clean up double periods
138
+ .replace(/[ \t]+/g, " ")
139
+ .replace(/\n\s*\n/g, "\n\n")
140
+ .replace(/\s*\.\s*\./g, ".")
239
141
  .trim();
240
- // Note: We intentionally do NOT include the title in the speech text.
241
- // The title is displayed visually and doesn't need to be in the audio.
242
- // This also ensures alignment data matches the article body content.
243
- // Compute hash for change detection
244
- const hash = computeHash(text);
142
+ const { speechtext, normalisedSpeechtext } = buildSpeechtextPair(plainText);
143
+ // Map each math expression's latex key to its resolved spoken form.
144
+ const resolvedMath = await Promise.all(mathPromises);
145
+ const mathSpeech = {};
146
+ for (let i = 0; i < mathKeys.length; i++) {
147
+ mathSpeech[mathKeys[i]] = resolvedMath[i];
148
+ }
245
149
  return {
246
150
  slug: item.slug,
247
- text,
248
- hash,
151
+ speechtext,
152
+ normalisedSpeechtext,
153
+ mathSpeech,
249
154
  source: item.filePath,
250
155
  };
251
156
  }
@@ -1 +1 @@
1
- {"version":3,"file":"speech-builder.js","sourceRoot":"","sources":["../../src/core/speech-builder.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,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AAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU;QACV,oBAAoB;QACpB,UAAU;QACV,MAAM,EAAE,IAAI,CAAC,QAAQ;KACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Spoken-form normalization primitives.
3
+ *
4
+ * Ported from the Valeon blog's audio pipeline so the plugin's
5
+ * build-time tokenization reproduces VocaSync's alignment token stream
6
+ * exactly. Two transforms:
7
+ *
8
+ * expandSpokenForms(text) — expands currencies, numbers, percentages
9
+ * into spoken word equivalents. Preserves
10
+ * punctuation/casing so it reads naturally
11
+ * for TTS. This is the `speechtext` POSTed
12
+ * to synthesis.
13
+ *
14
+ * stripForAlignment(text) — derives the alignment-friendly form:
15
+ * lowercase, punctuation removed, whitespace
16
+ * collapsed, contractions preserved. This is
17
+ * the `normalisedSpeechtext` POSTed as the
18
+ * alignment transcript AND the basis for the
19
+ * rehype plugin's `data-i`/`data-n` indices.
20
+ *
21
+ * Because the alignment transcript IS `stripForAlignment(expandSpokenForms(text))`,
22
+ * the worker's own normalizer is a no-op over it and word indices line up
23
+ * token-for-token with the rehype output.
24
+ */
25
+ /**
26
+ * Expand currency symbols, numbers, and percentages into their spoken
27
+ * word forms. Preserves punctuation and surrounding text — this is the
28
+ * surface that becomes `speechtext`.
29
+ */
30
+ export declare function expandSpokenForms(input: string): string;
31
+ /**
32
+ * Strip a speechtext-form string into the alignment form: lowercase,
33
+ * punctuation removed, whitespace collapsed. Contractions are preserved
34
+ * (e.g. "don't" stays one token).
35
+ */
36
+ export declare function stripForAlignment(input: string): string;
37
+ /**
38
+ * Produce both the speechtext (POSTed to synthesis) and
39
+ * normalisedSpeechtext (POSTed as the alignment transcript) forms from a
40
+ * single plain-text input.
41
+ */
42
+ export declare function buildSpeechtextPair(plainText: string): {
43
+ speechtext: string;
44
+ normalisedSpeechtext: string;
45
+ };
46
+ /**
47
+ * How many alignment tokens a visible string expands to. Used by the
48
+ * rehype plugin to compute `data-n` for each wrapped word / math unit.
49
+ * "$50" -> 2 ("fifty dollar"); "1995" -> 6; unambiguous words -> 1.
50
+ */
51
+ export declare function spokenTokenCount(visible: string): number;
52
+ //# sourceMappingURL=spoken-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spoken-form.d.ts","sourceRoot":"","sources":["../../src/core/spoken-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA8LH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAuCvD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAIA;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIxD"}