@vocasync/astro 0.1.10 → 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 (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 +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 +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 +136 -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocasync/astro",
3
- "version": "0.1.10",
3
+ "version": "1.0.0",
4
4
  "description": "VocaSync integration for Astro - Text-to-speech synthesis and word-level alignment for static sites",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -28,6 +28,7 @@
28
28
  "scripts": {
29
29
  "build": "tsc && cp -r src/components/*.astro dist/components/ && cp -r src/styles dist/",
30
30
  "dev": "tsc --watch",
31
+ "test": "bun test",
31
32
  "check": "biome check .",
32
33
  "check:fix": "biome check --write .",
33
34
  "prepublishOnly": "bun run build"
@@ -47,11 +48,11 @@
47
48
  "license": "MIT",
48
49
  "repository": {
49
50
  "type": "git",
50
- "url": "git+https://github.com/sayedhfatimi/vocasync-astro.git"
51
+ "url": "git+https://github.com/vocasync/astro.git"
51
52
  },
52
- "homepage": "https://github.com/sayedhfatimi/vocasync-astro#readme",
53
+ "homepage": "https://github.com/vocasync/astro#readme",
53
54
  "bugs": {
54
- "url": "https://github.com/sayedhfatimi/vocasync-astro/issues"
55
+ "url": "https://github.com/vocasync/astro/issues"
55
56
  },
56
57
  "peerDependencies": {
57
58
  "astro": "^4.0.0 || ^5.0.0",
@@ -67,19 +68,21 @@
67
68
  }
68
69
  },
69
70
  "dependencies": {
70
- "zod": "^3.23.0",
71
- "unified": "^11.0.0",
71
+ "zod": "^3.25.76",
72
+ "unified": "^11.0.5",
72
73
  "remark-parse": "^11.0.0",
73
74
  "remark-math": "^6.0.0",
74
- "unist-util-visit-parents": "^6.0.0"
75
+ "unist-util-visit-parents": "^6.0.2"
75
76
  },
76
77
  "devDependencies": {
77
- "@biomejs/biome": "^1.9.0",
78
+ "@biomejs/biome": "^1.9.4",
78
79
  "@types/hast": "^3.0.4",
79
80
  "@types/mdast": "^4.0.4",
80
- "@types/node": "^22.0.0",
81
- "astro": "^5.0.0",
82
- "typescript": "^5.7.0"
81
+ "@types/node": "^22.19.19",
82
+ "astro": "^5.18.1",
83
+ "mathjax-full": "^3.2.2",
84
+ "speech-rule-engine": "^4.1.4",
85
+ "typescript": "^5.9.3"
83
86
  },
84
87
  "engines": {
85
88
  "node": ">=18.0.0"
package/src/api/client.ts CHANGED
@@ -1,14 +1,46 @@
1
1
  import type { VocaSyncConfig } from "../config/index.js";
2
2
  import type {
3
3
  AlignedWord,
4
- AlignmentData,
4
+ AlignmentPresignResponse,
5
+ AlignmentSubmitResponse,
5
6
  ProjectResponse,
6
7
  ProjectStatus,
7
8
  SynthesisResponse,
8
9
  } from "../types/index.js";
9
10
 
10
11
  /**
11
- * VocaSync API client for synthesis and alignment operations.
12
+ * Map a synthesis language (ISO 639-1) to its alignment locale (BCP-47).
13
+ * Only the alignment-supported set is valid; defaults to en-US.
14
+ */
15
+ export const SYNTHESIS_TO_ALIGNMENT_LANGUAGE: Record<string, string> = {
16
+ en: "en-US",
17
+ fr: "fr",
18
+ de: "de",
19
+ es: "es",
20
+ pt: "pt-PT",
21
+ sv: "sv",
22
+ cs: "cs",
23
+ pl: "pl",
24
+ tr: "tr",
25
+ ru: "ru",
26
+ uk: "uk",
27
+ ja: "ja",
28
+ ko: "ko",
29
+ zh: "zh-CN",
30
+ };
31
+
32
+ export function toAlignmentLocale(language: string): string {
33
+ return SYNTHESIS_TO_ALIGNMENT_LANGUAGE[language] ?? "en-US";
34
+ }
35
+
36
+ /**
37
+ * VocaSync API client.
38
+ *
39
+ * Implements the two-POST audio pipeline: synthesis (POST /synthesis) then
40
+ * an explicit alignment job (presign -> S3 upload -> POST /alignment) with a
41
+ * client-supplied transcript, so alignment word indices line up with the
42
+ * rehype plugin's `data-i` token stream. `align=true` auto-chaining is
43
+ * deprecated and no longer used.
12
44
  */
13
45
  export class VocaSyncClient {
14
46
  private baseUrl: string;
@@ -19,25 +51,19 @@ export class VocaSyncClient {
19
51
  this.baseUrl = baseUrl;
20
52
  }
21
53
 
22
- /**
23
- * Make an authenticated API request.
24
- */
54
+ /** Make an authenticated JSON API request. */
25
55
  private async request<T>(method: string, endpoint: string, body?: unknown): Promise<T> {
26
- const url = `${this.baseUrl}${endpoint}`;
27
-
28
- const headers: Record<string, string> = {
29
- Authorization: `Bearer ${this.apiKey}`,
30
- "Content-Type": "application/json",
31
- };
32
-
33
- const response = await fetch(url, {
56
+ const response = await fetch(`${this.baseUrl}${endpoint}`, {
34
57
  method,
35
- headers,
58
+ headers: {
59
+ Authorization: `Bearer ${this.apiKey}`,
60
+ "Content-Type": "application/json",
61
+ },
36
62
  body: body ? JSON.stringify(body) : undefined,
37
63
  });
38
64
 
39
65
  if (!response.ok) {
40
- const errorBody = await response.text();
66
+ const errorBody = await response.text().catch(() => "");
41
67
  throw new VocaSyncAPIError(
42
68
  `API request failed: ${response.status} ${response.statusText}`,
43
69
  response.status,
@@ -45,14 +71,17 @@ export class VocaSyncClient {
45
71
  );
46
72
  }
47
73
 
48
- return response.json() as T;
74
+ return response.json() as Promise<T>;
75
+ }
76
+
77
+ /** Stream URL (without publishable key) for an artifact. */
78
+ streamUrl(projectUuid: string, kind: "synthesis" | "alignment"): string {
79
+ return `${this.baseUrl}/stream/${projectUuid}/${kind}`;
49
80
  }
50
81
 
51
82
  /**
52
- * Create a synthesis project with alignment.
53
- *
54
- * Uses the `align=true` flag to automatically create a linked alignment project
55
- * that starts processing once synthesis completes.
83
+ * Create a synthesis project. No `align` flag — alignment is run as a
84
+ * separate explicit job (see runAlignment).
56
85
  */
57
86
  async synthesize(params: {
58
87
  name: string;
@@ -60,32 +89,27 @@ export class VocaSyncClient {
60
89
  voice: string;
61
90
  quality: "sd" | "hd";
62
91
  language: string;
92
+ outputFormat: string;
63
93
  }): Promise<SynthesisResponse> {
64
- const url = `${this.baseUrl}/synthesis`;
65
-
66
- // API expects multipart/form-data
67
94
  const formData = new FormData();
68
95
  formData.append("textType", "text");
69
96
  formData.append("text", params.text);
70
97
  formData.append("voice", params.voice);
71
98
  formData.append("quality", params.quality);
72
99
  formData.append("language", params.language);
100
+ formData.append("outputFormat", params.outputFormat);
73
101
  formData.append("projectName", params.name);
74
- formData.append("align", "true"); // Auto-create alignment project
75
102
 
76
- const response = await fetch(url, {
103
+ const response = await fetch(`${this.baseUrl}/synthesis`, {
77
104
  method: "POST",
78
- headers: {
79
- Authorization: `Bearer ${this.apiKey}`,
80
- // Don't set Content-Type - let fetch set it with boundary for FormData
81
- },
105
+ headers: { Authorization: `Bearer ${this.apiKey}` },
82
106
  body: formData,
83
107
  });
84
108
 
85
109
  if (!response.ok) {
86
- const errorBody = await response.text();
110
+ const errorBody = await response.text().catch(() => "");
87
111
  throw new VocaSyncAPIError(
88
- `API request failed: ${response.status} ${response.statusText}`,
112
+ `Synthesis request failed: ${response.status} ${response.statusText}`,
89
113
  response.status,
90
114
  errorBody
91
115
  );
@@ -94,92 +118,22 @@ export class VocaSyncClient {
94
118
  return (await response.json()) as SynthesisResponse;
95
119
  }
96
120
 
97
- /**
98
- * Create a publishable key for a project.
99
- * The publishable key enables public access to project artifacts via stream endpoints.
100
- *
101
- * @param projectUuid - The project UUID
102
- * @returns The publishable key (only returned once at creation)
103
- */
104
- async createPublishableKey(projectUuid: string): Promise<{ publishableKey: string }> {
105
- const response = await this.request<{ publishableKey: string; projectUuid: string }>(
106
- "POST",
107
- `/projects/${projectUuid}/publishable-key`
108
- );
109
- return { publishableKey: response.publishableKey };
110
- }
111
-
112
- /**
113
- * Get project status including synthesis and alignment job status.
114
- */
115
- async getProjectStatus(projectUuid: string): Promise<ProjectStatus> {
116
- // Fetch full project from the API
121
+ /** Fetch a single project's status (GET /projects/{uuid}). */
122
+ async getProject(projectUuid: string): Promise<ProjectStatus> {
117
123
  const project = await this.request<ProjectResponse>("GET", `/projects/${projectUuid}`);
118
-
119
- // Find synthesis artifact
120
- const synthesisArtifact = project.artifacts.find((a) => a.artifactType === "synthesis");
121
-
122
- // Map to internal ProjectStatus format
123
- const status: ProjectStatus = {
124
+ return {
124
125
  uuid: project.projectUuid,
125
- name: project.name || "",
126
+ name: project.name ?? "",
127
+ projectType: project.projectType,
126
128
  status: project.status,
129
+ durationSeconds: project.audioFileDurationSeconds ?? undefined,
130
+ error: project.error ?? undefined,
127
131
  };
128
-
129
- // Add synthesis job info if we have a synthesis artifact or this is a synthesis project
130
- if (synthesisArtifact || project.projectType === "synthesis") {
131
- status.synthesisJob = {
132
- status: project.status,
133
- duration: project.audioFileDurationSeconds || undefined,
134
- error: project.error || undefined,
135
- };
136
- if (synthesisArtifact?.synthesisFileKey) {
137
- status.synthesisJob.audioUrl = `/stream/${projectUuid}/synthesis`;
138
- }
139
- }
140
-
141
- // Add alignment job info from linked alignment project (for synthesis with align=true)
142
- if (project.linkedAlignment) {
143
- status.alignmentJob = {
144
- status: project.linkedAlignment.status,
145
- error: project.linkedAlignment.error || undefined,
146
- };
147
- // Alignment URL is on the synthesis project (uses linkedAlignmentProjectId internally)
148
- if (project.linkedAlignment.status === "completed") {
149
- status.alignmentJob.alignmentUrl = `/stream/${projectUuid}/alignment`;
150
- }
151
- }
152
-
153
- return status;
154
- }
155
-
156
- /**
157
- * Fetch alignment data (words with timestamps) from completed alignment job.
158
- */
159
- async getAlignment(alignmentUrl: string): Promise<AlignmentData> {
160
- // The alignmentUrl may be a full URL or relative
161
- const url = alignmentUrl.startsWith("http") ? alignmentUrl : `${this.baseUrl}${alignmentUrl}`;
162
-
163
- const response = await fetch(url, {
164
- headers: {
165
- Authorization: `Bearer ${this.apiKey}`,
166
- },
167
- });
168
-
169
- if (!response.ok) {
170
- throw new VocaSyncAPIError(`Failed to fetch alignment: ${response.status}`, response.status);
171
- }
172
-
173
- const data = (await response.json()) as { words: AlignedWord[]; duration: number };
174
- return data;
175
132
  }
176
133
 
177
134
  /**
178
- * Poll project status until completion or failure.
179
- *
180
- * @param projectUuid - The project to poll
181
- * @param options - Polling options
182
- * @returns The final project status
135
+ * Poll a project until it completes or fails. Throws on failure (with the
136
+ * server `error`) or timeout.
183
137
  */
184
138
  async pollUntilComplete(
185
139
  projectUuid: string,
@@ -189,68 +143,122 @@ export class VocaSyncClient {
189
143
  onProgress?: (status: ProjectStatus) => void;
190
144
  } = {}
191
145
  ): Promise<ProjectStatus> {
192
- const { maxAttempts = 120, intervalMs = 5000, onProgress } = options;
146
+ const { maxAttempts = 180, intervalMs = 5000, onProgress } = options;
193
147
 
194
148
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
195
- const status = await this.getProjectStatus(projectUuid);
196
-
149
+ const status = await this.getProject(projectUuid);
197
150
  onProgress?.(status);
198
151
 
199
- // Check if synthesis is complete
200
- const synthComplete =
201
- status.synthesisJob?.status === "completed" || status.synthesisJob?.status === "failed";
202
-
203
- // For alignment: if synthesis is complete but alignment job doesn't exist yet,
204
- // keep polling because the backend may still be creating the linked alignment project
205
- const alignComplete =
206
- status.alignmentJob?.status === "completed" || status.alignmentJob?.status === "failed";
152
+ if (status.status === "completed") return status;
153
+ if (status.status === "failed") {
154
+ throw new VocaSyncAPIError(
155
+ `${status.projectType} failed: ${status.error || "Unknown error"}`,
156
+ 500
157
+ );
158
+ }
159
+ await sleep(intervalMs);
160
+ }
207
161
 
208
- // Only exit when synth is complete AND either:
209
- // 1. Alignment is complete/failed, OR
210
- // 2. We've polled enough times after synth completion that alignment should have started
211
- // (alignment job will appear as "pending" or "processing" once linked)
212
- const shouldWaitForAlignment = synthComplete && !status.alignmentJob;
162
+ throw new VocaSyncAPIError("Polling timeout — job did not complete in time", 408);
163
+ }
213
164
 
214
- if (synthComplete && alignComplete) {
215
- // Check for failures
216
- if (status.synthesisJob?.status === "failed") {
217
- throw new VocaSyncAPIError(
218
- `Synthesis failed: ${status.synthesisJob.error || "Unknown error"}`,
219
- 500
220
- );
221
- }
222
- if (status.alignmentJob?.status === "failed") {
223
- throw new VocaSyncAPIError(
224
- `Alignment failed: ${status.alignmentJob.error || "Unknown error"}`,
225
- 500
226
- );
227
- }
165
+ /**
166
+ * Create a publishable key for a completed project (enables public stream
167
+ * access). The full key is only returned once.
168
+ */
169
+ async createPublishableKey(projectUuid: string): Promise<string> {
170
+ const response = await this.request<{ publishableKey: string }>(
171
+ "POST",
172
+ `/projects/${projectUuid}/publishable-key`
173
+ );
174
+ return response.publishableKey;
175
+ }
228
176
 
229
- return status;
230
- }
177
+ /** Download bytes from a stream URL (used to re-upload audio for alignment). */
178
+ async downloadBytes(url: string): Promise<{ bytes: Uint8Array; contentType: string }> {
179
+ const response = await fetch(url);
180
+ if (!response.ok) {
181
+ throw new VocaSyncAPIError(`Failed to download ${url}: ${response.status}`, response.status);
182
+ }
183
+ const bytes = new Uint8Array(await response.arrayBuffer());
184
+ const contentType = response.headers.get("content-type") ?? "audio/mpeg";
185
+ return { bytes, contentType };
186
+ }
231
187
 
232
- // If synthesis is complete but no alignment job yet, wait a bit longer
233
- // The backend creates the alignment project asynchronously after synthesis
234
- if (shouldWaitForAlignment && attempt > 5) {
235
- // After 5 additional polls with no alignment appearing, assume it won't be created
236
- // This handles the case where align=false or alignment language isn't supported
237
- return status;
238
- }
188
+ /** Request presigned upload URLs for the alignment audio + transcript. */
189
+ async presignAlignment(params: {
190
+ audioName: string;
191
+ audioType: string;
192
+ audioSize: number;
193
+ transcriptSize: number;
194
+ language: string;
195
+ }): Promise<AlignmentPresignResponse> {
196
+ return this.request<AlignmentPresignResponse>("POST", "/alignment/presign", {
197
+ audioFile: { name: params.audioName, type: params.audioType, size: params.audioSize },
198
+ transcriptFile: { name: "transcript.txt", type: "text/plain", size: params.transcriptSize },
199
+ language: params.language,
200
+ });
201
+ }
239
202
 
240
- // Wait before next poll
241
- await sleep(intervalMs);
203
+ /** PUT bytes to a presigned upload URL. */
204
+ async uploadToPresigned(
205
+ uploadUrl: string,
206
+ bytes: Uint8Array,
207
+ contentType: string
208
+ ): Promise<void> {
209
+ const response = await fetch(uploadUrl, {
210
+ method: "PUT",
211
+ headers: { "Content-Type": contentType },
212
+ // Uint8Array is a valid fetch body at runtime; the DOM lib's BodyInit
213
+ // type is narrower than undici/bun's, hence the cast.
214
+ body: bytes as unknown as BodyInit,
215
+ });
216
+ if (!response.ok) {
217
+ throw new VocaSyncAPIError(
218
+ `S3 upload failed: ${response.status} ${response.statusText}`,
219
+ response.status
220
+ );
242
221
  }
222
+ }
243
223
 
244
- throw new VocaSyncAPIError("Polling timeout - job did not complete in time", 408);
224
+ /** Submit an alignment job for pre-uploaded audio + transcript (JSON mode). */
225
+ async submitAlignment(params: {
226
+ projectUuid: string;
227
+ audioFileKey: string;
228
+ transcriptFileKey: string;
229
+ audioFileSizeBytes: number;
230
+ transcriptFileSizeBytes: number;
231
+ language: string;
232
+ projectName: string;
233
+ }): Promise<AlignmentSubmitResponse> {
234
+ return this.request<AlignmentSubmitResponse>("POST", "/alignment", {
235
+ projectUuid: params.projectUuid,
236
+ audioFileKey: params.audioFileKey,
237
+ transcriptFileKey: params.transcriptFileKey,
238
+ audioFileSizeBytes: params.audioFileSizeBytes,
239
+ transcriptFileSizeBytes: params.transcriptFileSizeBytes,
240
+ language: params.language,
241
+ projectName: params.projectName,
242
+ });
245
243
  }
246
244
 
247
- /**
248
- * Check API key validity and account balance.
249
- */
250
- async validateApiKey(): Promise<{ valid: boolean; balance?: number }> {
245
+ /** Fetch the alignment word timings from a completed alignment project. */
246
+ async fetchAlignmentWords(
247
+ alignmentStreamUrl: string
248
+ ): Promise<{ words: AlignedWord[]; duration: number }> {
249
+ const response = await fetch(alignmentStreamUrl);
250
+ if (!response.ok) {
251
+ throw new VocaSyncAPIError(`Failed to fetch alignment: ${response.status}`, response.status);
252
+ }
253
+ const data = (await response.json()) as { words?: AlignedWord[]; duration?: number };
254
+ return { words: data.words ?? [], duration: data.duration ?? 0 };
255
+ }
256
+
257
+ /** Validate the API key and return the prepaid balance in cents. */
258
+ async validateApiKey(): Promise<{ valid: boolean; balanceCents?: number }> {
251
259
  try {
252
- const response = await this.request<{ balance: number }>("GET", "/account");
253
- return { valid: true, balance: response.balance };
260
+ const response = await this.request<{ plan?: { balanceCents?: number } }>("GET", "/me");
261
+ return { valid: true, balanceCents: response.plan?.balanceCents };
254
262
  } catch (error) {
255
263
  if (error instanceof VocaSyncAPIError && error.statusCode === 401) {
256
264
  return { valid: false };
@@ -260,9 +268,14 @@ export class VocaSyncClient {
260
268
  }
261
269
  }
262
270
 
263
- /**
264
- * Custom error class for VocaSync API errors.
265
- */
271
+ /** Append a publishable key to a stream URL. */
272
+ export function withPublishableKey(url: string, publishableKey: string): string {
273
+ const u = new URL(url);
274
+ u.searchParams.set("pk", publishableKey);
275
+ return u.toString();
276
+ }
277
+
278
+ /** Custom error class for VocaSync API errors. */
266
279
  export class VocaSyncAPIError extends Error {
267
280
  statusCode: number;
268
281
  responseBody?: string;
@@ -275,46 +288,18 @@ export class VocaSyncAPIError extends Error {
275
288
  }
276
289
  }
277
290
 
278
- /**
279
- * Sleep utility for polling.
280
- */
281
291
  function sleep(ms: number): Promise<void> {
282
292
  return new Promise((resolve) => setTimeout(resolve, ms));
283
293
  }
284
294
 
285
- /**
286
- * Create a VocaSync client from configuration.
287
- */
295
+ /** Create a VocaSync client from configuration (reads VOCASYNC_API_KEY). */
288
296
  export function createClient(_config: VocaSyncConfig): VocaSyncClient {
289
297
  const apiKey = process.env.VOCASYNC_API_KEY;
290
-
291
298
  if (!apiKey) {
292
299
  throw new Error(
293
300
  "VOCASYNC_API_KEY environment variable is not set.\n" +
294
301
  "Get your API key at https://vocasync.io and add it to your .env file."
295
302
  );
296
303
  }
297
-
298
304
  return new VocaSyncClient(apiKey);
299
305
  }
300
-
301
- /**
302
- * Get streaming URLs for stable audio/alignment access.
303
- * These URLs don't expire and redirect to fresh presigned URLs on each request.
304
- */
305
- export function getStreamingUrls(
306
- projectUuid: string,
307
- baseUrl = "https://vocasync.io/api/v1"
308
- ): {
309
- synthesisUrl: string;
310
- alignmentUrl: string;
311
- srtUrl: string;
312
- vttUrl: string;
313
- } {
314
- return {
315
- synthesisUrl: `${baseUrl}/stream/${projectUuid}/synthesis`,
316
- alignmentUrl: `${baseUrl}/stream/${projectUuid}/alignment`,
317
- srtUrl: `${baseUrl}/stream/${projectUuid}/subtitles.srt`,
318
- vttUrl: `${baseUrl}/stream/${projectUuid}/subtitles.vtt`,
319
- };
320
- }
package/src/api/index.ts CHANGED
@@ -1 +1,8 @@
1
- export { VocaSyncClient, VocaSyncAPIError, createClient, getStreamingUrls } from "./client.js";
1
+ export {
2
+ VocaSyncClient,
3
+ VocaSyncAPIError,
4
+ createClient,
5
+ withPublishableKey,
6
+ toAlignmentLocale,
7
+ SYNTHESIS_TO_ALIGNMENT_LANGUAGE,
8
+ } from "./client.js";
package/src/cli.ts CHANGED
@@ -214,25 +214,18 @@ async function main(): Promise<void> {
214
214
  }
215
215
 
216
216
  log(`Checking status for ${projectId}...`, "info");
217
- const status = await client.getProjectStatus(projectId);
217
+ const status = await client.getProject(projectId);
218
218
 
219
219
  console.log("");
220
220
  console.log(`${colors.bold}Project:${colors.reset} ${status.uuid}`);
221
221
  console.log(`${colors.bold}Name:${colors.reset} ${status.name}`);
222
- console.log(
223
- `${colors.bold}Synthesis:${colors.reset} ${status.synthesisJob?.status || "N/A"}`
224
- );
225
- console.log(
226
- `${colors.bold}Alignment:${colors.reset} ${status.alignmentJob?.status || "N/A"}`
227
- );
228
-
229
- if (status.synthesisJob?.audioUrl) {
230
- console.log(`${colors.bold}Audio:${colors.reset} ${status.synthesisJob.audioUrl}`);
222
+ console.log(`${colors.bold}Type:${colors.reset} ${status.projectType}`);
223
+ console.log(`${colors.bold}Status:${colors.reset} ${status.status}`);
224
+ if (status.durationSeconds !== undefined) {
225
+ console.log(`${colors.bold}Duration:${colors.reset} ${status.durationSeconds}s`);
231
226
  }
232
- if (status.alignmentJob?.alignmentUrl) {
233
- console.log(
234
- `${colors.bold}Alignment:${colors.reset} ${status.alignmentJob.alignmentUrl}`
235
- );
227
+ if (status.error) {
228
+ console.log(`${colors.bold}Error:${colors.reset} ${status.error}`);
236
229
  }
237
230
 
238
231
  process.exit(0);