@vocasync/astro 0.1.10 → 1.0.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.
Files changed (76) 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 +141 -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 +72 -116
  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.map +1 -1
  27. package/dist/lib/latex-to-speech/index.js +9 -11
  28. package/dist/lib/latex-to-speech/index.js.map +1 -1
  29. package/dist/lib/latex-to-speech/speak.d.ts +7 -2
  30. package/dist/lib/latex-to-speech/speak.d.ts.map +1 -1
  31. package/dist/lib/latex-to-speech/speak.js +10 -27
  32. package/dist/lib/latex-to-speech/speak.js.map +1 -1
  33. package/dist/rehype/audio-words.d.ts +14 -24
  34. package/dist/rehype/audio-words.d.ts.map +1 -1
  35. package/dist/rehype/audio-words.js +131 -252
  36. package/dist/rehype/audio-words.js.map +1 -1
  37. package/dist/rehype/index.d.ts +1 -2
  38. package/dist/rehype/index.d.ts.map +1 -1
  39. package/dist/rehype/index.js +0 -1
  40. package/dist/rehype/index.js.map +1 -1
  41. package/dist/rehype/rehype-math-speech.d.ts +26 -10
  42. package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
  43. package/dist/rehype/rehype-math-speech.js +59 -43
  44. package/dist/rehype/rehype-math-speech.js.map +1 -1
  45. package/dist/rehype/shared.d.ts +9 -0
  46. package/dist/rehype/shared.d.ts.map +1 -0
  47. package/dist/rehype/shared.js +31 -0
  48. package/dist/rehype/shared.js.map +1 -0
  49. package/dist/sync/orchestrator.d.ts +4 -22
  50. package/dist/sync/orchestrator.d.ts.map +1 -1
  51. package/dist/sync/orchestrator.js +123 -123
  52. package/dist/sync/orchestrator.js.map +1 -1
  53. package/dist/types/index.d.ts +82 -46
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/package.json +14 -11
  56. package/src/api/client.ts +175 -190
  57. package/src/api/index.ts +8 -1
  58. package/src/cli.ts +7 -14
  59. package/src/components/AudioPlayer.astro +141 -137
  60. package/src/config/schema.ts +15 -4
  61. package/src/core/audio-map.ts +1 -1
  62. package/src/core/speech-builder.ts +74 -130
  63. package/src/core/spoken-form.ts +298 -0
  64. package/src/lib/latex-to-speech/index.ts +8 -9
  65. package/src/lib/latex-to-speech/speak.ts +11 -34
  66. package/src/rehype/audio-words.ts +145 -307
  67. package/src/rehype/index.ts +1 -2
  68. package/src/rehype/rehype-math-speech.ts +64 -59
  69. package/src/rehype/shared.ts +36 -0
  70. package/src/sync/orchestrator.ts +150 -157
  71. package/src/types/index.ts +85 -47
  72. package/dist/rehype/remark-math-speech.d.ts +0 -14
  73. package/dist/rehype/remark-math-speech.d.ts.map +0 -1
  74. package/dist/rehype/remark-math-speech.js +0 -27
  75. package/dist/rehype/remark-math-speech.js.map +0 -1
  76. package/src/rehype/remark-math-speech.ts +0 -32
@@ -13,15 +13,26 @@ export interface ContentItem {
13
13
  }
14
14
 
15
15
  /**
16
- * Processed speech document ready for synthesis
16
+ * Processed speech document ready for synthesis + alignment.
17
+ *
18
+ * `speechtext` is POSTed to /synthesis (expanded spoken form, punctuation
19
+ * preserved). `normalisedSpeechtext` is POSTed as the alignment transcript
20
+ * (stripped form) and is the exact token stream the rehype plugin indexes.
17
21
  */
18
22
  export interface SpeechDocument {
19
23
  /** Unique slug identifier */
20
24
  slug: string;
21
- /** Plain text for TTS synthesis */
22
- text: string;
23
- /** Content hash for change detection */
24
- hash: string;
25
+ /** Expanded spoken text for TTS synthesis */
26
+ speechtext: string;
27
+ /** Normalised transcript for alignment (token-for-token with data-i) */
28
+ normalisedSpeechtext: string;
29
+ /**
30
+ * Spoken form of each math expression, keyed by `${'d'|'i'}:${latex}`
31
+ * (d = display/block, i = inline). The rehype plugin reuses these so the
32
+ * math tokens it counts match what was synthesized — math-to-speech runs
33
+ * only here (Node/CLI), never in the Astro/Vite build.
34
+ */
35
+ mathSpeech: Record<string, string>;
25
36
  /** Source file path */
26
37
  source: string;
27
38
  }
@@ -39,21 +50,34 @@ export interface AlignedWord {
39
50
  }
40
51
 
41
52
  /**
42
- * Audio artifact entry in audio-map.json
53
+ * Audio artifact entry in audio-map.json (v3).
54
+ *
55
+ * The two-POST flow produces TWO projects: a synthesis project (whose
56
+ * stream serves the audio) and an alignment project (used at build time
57
+ * to fetch the word timings, which are embedded here as `words`). Each
58
+ * project has its own publishable key.
43
59
  */
44
60
  export interface AudioArtifact {
45
- /** Synthesis project UUID */
46
- projectUuid: string;
47
- /** Content hash used for change detection */
61
+ /** Hash of normalisedSpeechtext + resolved voice/language/format */
48
62
  contentHash: string;
63
+ /** Resolved synthesis params (also part of change detection) */
64
+ voice: string;
65
+ language: string;
66
+ format: string;
67
+ /** Synthesis project (serves the audio stream) */
68
+ synthesisProjectUuid: string;
69
+ synthesisPublishableKey: string;
70
+ /** Stable audio stream URL (without the publishable key) */
71
+ audioUrl: string;
72
+ /** Alignment project (source of the embedded timings) */
73
+ alignmentProjectUuid: string;
74
+ alignmentPublishableKey: string;
75
+ /** Word timings, indexed positionally by the rehype plugin's data-i */
76
+ words: AlignedWord[];
49
77
  /** Total audio duration in seconds */
50
78
  duration: number;
51
- /** URL to stream audio (stable, non-expiring) */
52
- audioUrl: string;
53
- /** URL to fetch alignment JSON (stable, non-expiring) */
54
- alignmentUrl: string;
55
- /** Publishable key for streaming endpoint authentication */
56
- publishableKey?: string;
79
+ /** Spoken form of each math expression, keyed by `${'d'|'i'}:${latex}`. */
80
+ mathSpeech?: Record<string, string>;
57
81
  /** When this artifact was created */
58
82
  createdAt: string;
59
83
  /** When this artifact was last updated */
@@ -65,7 +89,7 @@ export interface AudioArtifact {
65
89
  */
66
90
  export interface AudioMap {
67
91
  /** Version of the audio-map schema */
68
- version: 1 | 2;
92
+ version: 1 | 2 | 3;
69
93
  /** When the map was last updated */
70
94
  updatedAt: string;
71
95
  /** Map of slug -> audio artifact */
@@ -73,24 +97,55 @@ export interface AudioMap {
73
97
  }
74
98
 
75
99
  /**
76
- * VocaSync API synthesis request
100
+ * VocaSync API synthesis request (FormData fields).
77
101
  */
78
102
  export interface SynthesisRequest {
79
103
  name: string;
80
104
  text: string;
81
105
  voice: string;
82
- speed?: number;
83
- quality?: "sd" | "hd";
84
- align?: boolean;
85
- language?: string;
106
+ quality: "sd" | "hd";
107
+ /** ISO 639-1 language code */
108
+ language: string;
109
+ /** Output container: mp3 | aac | opus | flac | wav */
110
+ outputFormat: string;
86
111
  }
87
112
 
88
113
  /**
89
- * VocaSync API synthesis response
114
+ * VocaSync API synthesis response (POST /v1/synthesis).
90
115
  */
91
116
  export interface SynthesisResponse {
92
117
  projectUuid: string;
93
- estimatedCost: number;
118
+ projectId?: string;
119
+ characterCount?: number;
120
+ status?: JobStatus;
121
+ }
122
+
123
+ /**
124
+ * Presigned upload target for one file.
125
+ */
126
+ export interface PresignTarget {
127
+ key: string;
128
+ uploadUrl: string;
129
+ }
130
+
131
+ /**
132
+ * Response from POST /v1/alignment/presign.
133
+ */
134
+ export interface AlignmentPresignResponse {
135
+ /** UUID minted for the alignment project; reused in the /alignment POST */
136
+ projectUuid: string;
137
+ audio: PresignTarget;
138
+ transcript: PresignTarget;
139
+ }
140
+
141
+ /**
142
+ * Response from POST /v1/alignment (JSON mode).
143
+ */
144
+ export interface AlignmentSubmitResponse {
145
+ projectUuid: string;
146
+ projectId?: string;
147
+ jobId?: string;
148
+ status?: JobStatus;
94
149
  }
95
150
 
96
151
  /**
@@ -138,23 +193,14 @@ export interface JobResponse {
138
193
  }
139
194
 
140
195
  /**
141
- * Linked alignment project status
142
- */
143
- export interface LinkedAlignmentStatus {
144
- projectUuid: string;
145
- status: JobStatus;
146
- error?: string | null;
147
- }
148
-
149
- /**
150
- * Project response from /projects/{uuid} endpoint
196
+ * Project response from GET /v1/projects/{uuid}.
151
197
  */
152
198
  export interface ProjectResponse {
153
199
  id: string;
154
200
  projectUuid: string;
155
201
  name: string | null;
156
202
  description: string | null;
157
- projectType: "alignment" | "synthesis";
203
+ projectType: "alignment" | "synthesis" | "transcription" | "translation";
158
204
  source: "web" | "api";
159
205
  language: string | null;
160
206
  status: JobStatus;
@@ -165,27 +211,19 @@ export interface ProjectResponse {
165
211
  error: string | null;
166
212
  artifacts: ArtifactResponse[];
167
213
  latestJob?: JobResponse | null;
168
- linkedAlignment?: LinkedAlignmentStatus | null;
169
214
  }
170
215
 
171
216
  /**
172
- * Project status (internal representation)
217
+ * Project status (internal, single-project representation used by the
218
+ * poller and the `status` CLI command).
173
219
  */
174
220
  export interface ProjectStatus {
175
221
  uuid: string;
176
222
  name: string;
223
+ projectType: ProjectResponse["projectType"];
177
224
  status: JobStatus;
178
- synthesisJob?: {
179
- status: JobStatus;
180
- audioUrl?: string;
181
- duration?: number;
182
- error?: string;
183
- };
184
- alignmentJob?: {
185
- status: JobStatus;
186
- alignmentUrl?: string;
187
- error?: string;
188
- };
225
+ durationSeconds?: number;
226
+ error?: string;
189
227
  }
190
228
 
191
229
  /**
@@ -1,14 +0,0 @@
1
- import type { Root } from "mdast";
2
- import type { VFile } from "vfile";
3
- export type MathSpeechEntry = {
4
- latex: string;
5
- display: boolean;
6
- };
7
- /**
8
- * Remark transformer that collects all math expressions from markdown.
9
- * Requires remark-math to be registered (order does not matter —
10
- * remark-math operates at parse time via micromark syntax extensions).
11
- * Stores entries in file.data.mathSpeech for rehypeMathSpeech to consume.
12
- */
13
- export default function remarkMathSpeechCollector(): (tree: Root, file: VFile) => void;
14
- //# sourceMappingURL=remark-math-speech.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remark-math-speech.d.ts","sourceRoot":"","sources":["../../src/rehype/remark-math-speech.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,KACnB,MAAM,IAAI,EAAE,MAAM,KAAK,UAepD"}
@@ -1,27 +0,0 @@
1
- import { visit } from "unist-util-visit";
2
- /**
3
- * Remark transformer that collects all math expressions from markdown.
4
- * Requires remark-math to be registered (order does not matter —
5
- * remark-math operates at parse time via micromark syntax extensions).
6
- * Stores entries in file.data.mathSpeech for rehypeMathSpeech to consume.
7
- */
8
- export default function remarkMathSpeechCollector() {
9
- return function transformer(tree, file) {
10
- const entries = [];
11
- visit(tree, (node) => {
12
- if (node.type !== "math" && node.type !== "inlineMath")
13
- return;
14
- const latex = String("value" in node ? (node.value ?? "") : "").trim();
15
- if (!latex)
16
- return;
17
- entries.push({
18
- latex,
19
- display: node.type === "math",
20
- });
21
- });
22
- if (entries.length) {
23
- file.data.mathSpeech = entries;
24
- }
25
- };
26
- }
27
- //# sourceMappingURL=remark-math-speech.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remark-math-speech.js","sourceRoot":"","sources":["../../src/rehype/remark-math-speech.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAQzC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB;IAC/C,OAAO,SAAS,WAAW,CAAC,IAAU,EAAE,IAAW;QACjD,MAAM,OAAO,GAAsB,EAAE,CAAC;QACtC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;gBAAE,OAAO;YAC/D,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACvE,IAAI,CAAC,KAAK;gBAAE,OAAO;YACnB,OAAO,CAAC,IAAI,CAAC;gBACX,KAAK;gBACL,OAAO,EAAE,IAAI,CAAC,IAAI,KAAK,MAAM;aAC9B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC;QACjC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -1,32 +0,0 @@
1
- import type { Root } from "mdast";
2
- import { visit } from "unist-util-visit";
3
- import type { VFile } from "vfile";
4
-
5
- export type MathSpeechEntry = {
6
- latex: string;
7
- display: boolean;
8
- };
9
-
10
- /**
11
- * Remark transformer that collects all math expressions from markdown.
12
- * Requires remark-math to be registered (order does not matter —
13
- * remark-math operates at parse time via micromark syntax extensions).
14
- * Stores entries in file.data.mathSpeech for rehypeMathSpeech to consume.
15
- */
16
- export default function remarkMathSpeechCollector() {
17
- return function transformer(tree: Root, file: VFile) {
18
- const entries: MathSpeechEntry[] = [];
19
- visit(tree, (node) => {
20
- if (node.type !== "math" && node.type !== "inlineMath") return;
21
- const latex = String("value" in node ? (node.value ?? "") : "").trim();
22
- if (!latex) return;
23
- entries.push({
24
- latex,
25
- display: node.type === "math",
26
- });
27
- });
28
- if (entries.length) {
29
- file.data.mathSpeech = entries;
30
- }
31
- };
32
- }