@vocasync/astro 0.1.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.
- package/README.md +580 -0
- package/dist/api/client.d.ts +77 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +223 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +257 -0
- package/dist/cli.js.map +1 -0
- package/dist/components/AudioPlayer.astro +1097 -0
- package/dist/components/index.d.ts +19 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +275 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +124 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/core/audio-map.d.ts +52 -0
- package/dist/core/audio-map.d.ts.map +1 -0
- package/dist/core/audio-map.js +97 -0
- package/dist/core/audio-map.js.map +1 -0
- package/dist/core/content-loader.d.ts +17 -0
- package/dist/core/content-loader.d.ts.map +1 -0
- package/dist/core/content-loader.js +141 -0
- package/dist/core/content-loader.js.map +1 -0
- package/dist/core/hash-manager.d.ts +16 -0
- package/dist/core/hash-manager.d.ts.map +1 -0
- package/dist/core/hash-manager.js +21 -0
- package/dist/core/hash-manager.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/speech-builder.d.ts +19 -0
- package/dist/core/speech-builder.d.ts.map +1 -0
- package/dist/core/speech-builder.js +252 -0
- package/dist/core/speech-builder.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.d.ts +27 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +110 -0
- package/dist/integration.js.map +1 -0
- package/dist/lib/latex-to-speech/index.d.ts +26 -0
- package/dist/lib/latex-to-speech/index.d.ts.map +1 -0
- package/dist/lib/latex-to-speech/index.js +101 -0
- package/dist/lib/latex-to-speech/index.js.map +1 -0
- package/dist/rehype/audio-words.d.ts +50 -0
- package/dist/rehype/audio-words.d.ts.map +1 -0
- package/dist/rehype/audio-words.js +269 -0
- package/dist/rehype/audio-words.js.map +1 -0
- package/dist/rehype/index.d.ts +6 -0
- package/dist/rehype/index.d.ts.map +1 -0
- package/dist/rehype/index.js +4 -0
- package/dist/rehype/index.js.map +1 -0
- package/dist/rehype/rehype-math-speech.d.ts +18 -0
- package/dist/rehype/rehype-math-speech.d.ts.map +1 -0
- package/dist/rehype/rehype-math-speech.js +117 -0
- package/dist/rehype/rehype-math-speech.js.map +1 -0
- package/dist/rehype/remark-math-speech.d.ts +13 -0
- package/dist/rehype/remark-math-speech.d.ts.map +1 -0
- package/dist/rehype/remark-math-speech.js +26 -0
- package/dist/rehype/remark-math-speech.js.map +1 -0
- package/dist/styles/variables.css +181 -0
- package/dist/sync/index.d.ts +3 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/orchestrator.d.ts +36 -0
- package/dist/sync/orchestrator.d.ts.map +1 -0
- package/dist/sync/orchestrator.js +166 -0
- package/dist/sync/orchestrator.js.map +1 -0
- package/dist/types/index.d.ts +196 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +89 -0
- package/src/api/client.ts +316 -0
- package/src/api/index.ts +1 -0
- package/src/cli.ts +301 -0
- package/src/components/AudioPlayer.astro +1097 -0
- package/src/components/index.ts +24 -0
- package/src/config/index.ts +30 -0
- package/src/config/schema.ts +177 -0
- package/src/core/audio-map.ts +107 -0
- package/src/core/content-loader.ts +171 -0
- package/src/core/hash-manager.ts +22 -0
- package/src/core/index.ts +12 -0
- package/src/core/speech-builder.ts +307 -0
- package/src/data/audio-map.example.json +19 -0
- package/src/env.d.ts +13 -0
- package/src/index.ts +67 -0
- package/src/integration.ts +123 -0
- package/src/lib/latex-to-speech/index.ts +126 -0
- package/src/rehype/audio-words.ts +345 -0
- package/src/rehype/index.ts +6 -0
- package/src/rehype/rehype-math-speech.ts +145 -0
- package/src/rehype/remark-math-speech.ts +31 -0
- package/src/styles/variables.css +181 -0
- package/src/sync/index.ts +2 -0
- package/src/sync/orchestrator.ts +239 -0
- package/src/types/index.ts +211 -0
- package/src/types/modules.d.ts +11 -0
package/README.md
ADDED
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
# @vocasync/astro
|
|
2
|
+
|
|
3
|
+
Turn your Astro blog posts into narrated audio with word-level synchronization.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎙️ **Text-to-Speech Synthesis** - Generate natural-sounding audio narration for your content
|
|
8
|
+
- 🎯 **Word-Level Alignment** - Precise timestamps for every word, powered by forced alignment
|
|
9
|
+
- ✨ **Live Word Highlighting** - Karaoke-style highlighting that follows along with playback
|
|
10
|
+
- 🎛️ **Built-in Audio Player** - Accessible player with keyboard shortcuts and mini-player mode
|
|
11
|
+
- 🌍 **57 Languages** - Global reach with support for 57 languages
|
|
12
|
+
- 🎨 **Fully Themeable** - CSS variables for seamless integration with any design
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Installation](#installation)
|
|
17
|
+
- [Quick Start](#quick-start)
|
|
18
|
+
- [Project Structure](#project-structure)
|
|
19
|
+
- [Configuration](#configuration)
|
|
20
|
+
- [CLI Commands](#cli-commands)
|
|
21
|
+
- [Components](#components)
|
|
22
|
+
- [Supported Languages](#supported-languages)
|
|
23
|
+
- [Math Support](#math-support)
|
|
24
|
+
- [Deployment](#deployment)
|
|
25
|
+
- [Important: Audio Map](#important-audio-map)
|
|
26
|
+
- [Customizing Styles](#customizing-styles)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @vocasync/astro
|
|
32
|
+
# or
|
|
33
|
+
bun add @vocasync/astro
|
|
34
|
+
# or
|
|
35
|
+
pnpm add @vocasync/astro
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
### 1. Create VocaSync Config
|
|
41
|
+
|
|
42
|
+
Create a `vocasync.config.mjs` file in your project root:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
// vocasync.config.mjs
|
|
46
|
+
export default {
|
|
47
|
+
collection: {
|
|
48
|
+
name: "blog", // Your content collection name
|
|
49
|
+
path: "./src/content/blog", // Path to your content
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Add to Astro Config
|
|
55
|
+
|
|
56
|
+
Update your `astro.config.mjs`:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
// astro.config.mjs
|
|
60
|
+
import { defineConfig } from "astro/config";
|
|
61
|
+
import vocasync from "@vocasync/astro";
|
|
62
|
+
import { rehypeAudioWords } from "@vocasync/astro/rehype";
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
markdown: {
|
|
66
|
+
rehypePlugins: [
|
|
67
|
+
[rehypeAudioWords, {
|
|
68
|
+
collectionName: "blog", // Must match your collection name
|
|
69
|
+
audioMapPath: "src/data/audio-map.json" // Must match output.audioMapPath
|
|
70
|
+
}]
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
integrations: [vocasync()],
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 3. Set API Key
|
|
78
|
+
|
|
79
|
+
Create a `.env` file:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
VOCASYNC_API_KEY=voca_xxxxxxxxxxxxxxxx
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Get your API key at [vocasync.io](https://vocasync.io)
|
|
86
|
+
|
|
87
|
+
### 4. Create Audio Map Directory
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
mkdir -p src/data
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 5. Sync Your Content
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx vocasync sync
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This will:
|
|
100
|
+
- Read all content from your collection
|
|
101
|
+
- Submit synthesis jobs to VocaSync API
|
|
102
|
+
- Wait for processing to complete
|
|
103
|
+
- Save metadata to `audio-map.json`
|
|
104
|
+
|
|
105
|
+
### 6. Add the Player Component
|
|
106
|
+
|
|
107
|
+
In your article layout or page:
|
|
108
|
+
|
|
109
|
+
```astro
|
|
110
|
+
---
|
|
111
|
+
// src/layouts/ArticleLayout.astro
|
|
112
|
+
import { AudioPlayer } from "@vocasync/astro/components";
|
|
113
|
+
|
|
114
|
+
const { post } = Astro.props;
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
<article>
|
|
118
|
+
<!-- Audio player at the top -->
|
|
119
|
+
<AudioPlayer slug={post.slug} label="Listen to this post" />
|
|
120
|
+
|
|
121
|
+
<!-- Article content - must have data-article-body for word highlighting -->
|
|
122
|
+
<div data-article-body>
|
|
123
|
+
<slot />
|
|
124
|
+
</div>
|
|
125
|
+
</article>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Project Structure
|
|
129
|
+
|
|
130
|
+
After setup, your project should look like this:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
my-astro-site/
|
|
134
|
+
├── astro.config.mjs # Astro config with vocasync integration
|
|
135
|
+
├── vocasync.config.mjs # VocaSync configuration
|
|
136
|
+
├── .env # API key (add to .gitignore)
|
|
137
|
+
├── src/
|
|
138
|
+
│ ├── content/
|
|
139
|
+
│ │ └── blog/ # Your content collection
|
|
140
|
+
│ │ ├── my-post.md
|
|
141
|
+
│ │ └── another-post.md
|
|
142
|
+
│ ├── data/
|
|
143
|
+
│ │ └── audio-map.json # Generated - DO NOT DELETE (see below)
|
|
144
|
+
│ └── layouts/
|
|
145
|
+
│ └── ArticleLayout.astro
|
|
146
|
+
└── package.json
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Configuration
|
|
150
|
+
|
|
151
|
+
### vocasync.config.mjs
|
|
152
|
+
|
|
153
|
+
Full configuration options:
|
|
154
|
+
|
|
155
|
+
```javascript
|
|
156
|
+
// vocasync.config.mjs
|
|
157
|
+
export default {
|
|
158
|
+
// Content collection settings (required)
|
|
159
|
+
collection: {
|
|
160
|
+
name: "blog", // Collection name
|
|
161
|
+
path: "./src/content/blog", // Path to content files
|
|
162
|
+
slugField: "slug", // Frontmatter field for slug (optional)
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
// Language for synthesis and alignment (ISO 639-1 code)
|
|
166
|
+
// See "Supported Languages" section below for all options
|
|
167
|
+
language: "en",
|
|
168
|
+
|
|
169
|
+
// Synthesis settings
|
|
170
|
+
synthesis: {
|
|
171
|
+
voice: "onyx", // alloy, echo, fable, onyx, nova, shimmer
|
|
172
|
+
quality: "sd", // sd (standard) or hd (high definition)
|
|
173
|
+
format: "mp3", // mp3, opus, aac, flac
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
// LaTeX/math support
|
|
177
|
+
math: {
|
|
178
|
+
enabled: false, // Enable math-to-speech conversion
|
|
179
|
+
style: "clearspeak", // clearspeak or mathspeak
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
// Output settings
|
|
183
|
+
output: {
|
|
184
|
+
audioMapPath: "./src/data/audio-map.json",
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
// Frontmatter field to opt-in/out per post
|
|
188
|
+
frontmatterField: "audio", // Set `audio: false` in frontmatter to skip
|
|
189
|
+
|
|
190
|
+
// Processing options
|
|
191
|
+
processing: {
|
|
192
|
+
concurrency: 3, // Parallel jobs (1-10)
|
|
193
|
+
force: false, // Force reprocessing
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Rehype Plugin Options
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
// In astro.config.mjs
|
|
202
|
+
[rehypeAudioWords, {
|
|
203
|
+
collectionName: "blog", // Content collection name
|
|
204
|
+
audioMapPath: "src/data/audio-map.json", // Path to audio map
|
|
205
|
+
classPrefix: "vocasync", // CSS class prefix (default: "vocasync")
|
|
206
|
+
}]
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## CLI Commands
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Sync all content (synthesis + alignment)
|
|
213
|
+
npx vocasync sync
|
|
214
|
+
|
|
215
|
+
# Sync a single post
|
|
216
|
+
npx vocasync sync --only my-post-slug
|
|
217
|
+
|
|
218
|
+
# Force reprocessing (ignores cache)
|
|
219
|
+
npx vocasync sync --force
|
|
220
|
+
|
|
221
|
+
# Dry run (preview without API calls)
|
|
222
|
+
npx vocasync sync --dry-run
|
|
223
|
+
|
|
224
|
+
# Use a custom config file
|
|
225
|
+
npx vocasync sync --config ./path/to/vocasync.config.mjs
|
|
226
|
+
|
|
227
|
+
# Check configuration
|
|
228
|
+
npx vocasync check
|
|
229
|
+
|
|
230
|
+
# Check job status
|
|
231
|
+
npx vocasync status <projectUuid>
|
|
232
|
+
|
|
233
|
+
# Show help
|
|
234
|
+
npx vocasync help
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### CLI Options
|
|
238
|
+
|
|
239
|
+
| Option | Description |
|
|
240
|
+
|--------|-------------|
|
|
241
|
+
| `--only <slug>` | Only process a specific post by slug |
|
|
242
|
+
| `--force` | Force reprocessing, ignore cache |
|
|
243
|
+
| `--dry-run` | Preview what would be processed without API calls |
|
|
244
|
+
| `--config <path>` | Use a custom config file path |
|
|
245
|
+
|
|
246
|
+
## Components
|
|
247
|
+
|
|
248
|
+
### AudioPlayer
|
|
249
|
+
|
|
250
|
+
The main audio player component with word highlighting support.
|
|
251
|
+
|
|
252
|
+
```astro
|
|
253
|
+
---
|
|
254
|
+
import { AudioPlayer } from "@vocasync/astro/components";
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
<AudioPlayer
|
|
258
|
+
slug={post.slug}
|
|
259
|
+
label="Listen to this post"
|
|
260
|
+
articleSelector="[data-article-body]"
|
|
261
|
+
enableHighlighting={true}
|
|
262
|
+
enableMiniPlayer={true}
|
|
263
|
+
trailLength={4}
|
|
264
|
+
/>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### Props
|
|
268
|
+
|
|
269
|
+
| Prop | Type | Default | Description |
|
|
270
|
+
|------|------|---------|-------------|
|
|
271
|
+
| `slug` | `string` | required | Post slug to lookup audio |
|
|
272
|
+
| `label` | `string` | `"Listen to this post"` | Accessible label |
|
|
273
|
+
| `showPlaceholder` | `boolean` | `true` | Show message when no audio |
|
|
274
|
+
| `class` | `string` | `""` | Additional CSS classes |
|
|
275
|
+
| `articleSelector` | `string` | `"[data-article-body]"` | Selector for word highlighting container |
|
|
276
|
+
| `enableMiniPlayer` | `boolean` | `true` | Show floating mini player on scroll |
|
|
277
|
+
| `enableHighlighting` | `boolean` | `true` | Enable word highlighting |
|
|
278
|
+
| `trailLength` | `number` | `4` | Number of trailing highlighted words |
|
|
279
|
+
|
|
280
|
+
#### Keyboard Shortcuts
|
|
281
|
+
|
|
282
|
+
When the player is focused (click on it or Tab to it), the following keyboard shortcuts are available:
|
|
283
|
+
|
|
284
|
+
| Key | Action |
|
|
285
|
+
|-----|--------|
|
|
286
|
+
| `Space` | Play/Pause |
|
|
287
|
+
| `←` Left Arrow | Seek backward 5 seconds |
|
|
288
|
+
| `→` Right Arrow | Seek forward 5 seconds |
|
|
289
|
+
| `M` | Toggle mute |
|
|
290
|
+
| `H` | Toggle word highlighting |
|
|
291
|
+
|
|
292
|
+
#### Highlighting Toggle
|
|
293
|
+
|
|
294
|
+
The player includes a highlighter icon button that allows users to toggle word highlighting on/off during playback. This is useful for users who find the highlighting distracting or prefer to just listen.
|
|
295
|
+
|
|
296
|
+
### Word Highlighting
|
|
297
|
+
|
|
298
|
+
For word highlighting to work, wrap your article content with `data-article-body`:
|
|
299
|
+
|
|
300
|
+
```astro
|
|
301
|
+
<div data-article-body>
|
|
302
|
+
<Content /> <!-- Your markdown content -->
|
|
303
|
+
</div>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
The rehype plugin wraps each word in a `<span>` with timing data at build time.
|
|
307
|
+
|
|
308
|
+
## Supported Languages
|
|
309
|
+
|
|
310
|
+
VocaSync supports 57 languages using ISO 639-1 codes:
|
|
311
|
+
|
|
312
|
+
| Code | Language | Code | Language | Code | Language |
|
|
313
|
+
|------|----------|------|----------|------|----------|
|
|
314
|
+
| `af` | Afrikaans | `hu` | Hungarian | `pl` | Polish |
|
|
315
|
+
| `ar` | Arabic | `is` | Icelandic | `pt` | Portuguese |
|
|
316
|
+
| `hy` | Armenian | `id` | Indonesian | `ro` | Romanian |
|
|
317
|
+
| `az` | Azerbaijani | `it` | Italian | `ru` | Russian |
|
|
318
|
+
| `be` | Belarusian | `ja` | Japanese | `sr` | Serbian |
|
|
319
|
+
| `bs` | Bosnian | `kn` | Kannada | `sk` | Slovak |
|
|
320
|
+
| `bg` | Bulgarian | `kk` | Kazakh | `sl` | Slovenian |
|
|
321
|
+
| `ca` | Catalan | `ko` | Korean | `es` | Spanish |
|
|
322
|
+
| `zh` | Chinese | `lv` | Latvian | `sw` | Swahili |
|
|
323
|
+
| `hr` | Croatian | `lt` | Lithuanian | `sv` | Swedish |
|
|
324
|
+
| `cs` | Czech | `mk` | Macedonian | `tl` | Tagalog |
|
|
325
|
+
| `da` | Danish | `ms` | Malay | `ta` | Tamil |
|
|
326
|
+
| `nl` | Dutch | `mr` | Marathi | `th` | Thai |
|
|
327
|
+
| `en` | English | `mi` | Māori | `tr` | Turkish |
|
|
328
|
+
| `et` | Estonian | `ne` | Nepali | `uk` | Ukrainian |
|
|
329
|
+
| `fi` | Finnish | `no` | Norwegian | `ur` | Urdu |
|
|
330
|
+
| `fr` | French | `fa` | Persian | `vi` | Vietnamese |
|
|
331
|
+
| `gl` | Galician | | | `cy` | Welsh |
|
|
332
|
+
| `de` | German | | | | |
|
|
333
|
+
| `el` | Greek | | | | |
|
|
334
|
+
| `he` | Hebrew | | | | |
|
|
335
|
+
| `hi` | Hindi | | | | |
|
|
336
|
+
|
|
337
|
+
## Math Support
|
|
338
|
+
|
|
339
|
+
VocaSync supports LaTeX math equations using [Speech Rule Engine](https://github.com/zorkow/speech-rule-engine) to convert math to spoken text.
|
|
340
|
+
|
|
341
|
+
### Installation
|
|
342
|
+
|
|
343
|
+
Install the optional dependency:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
npm install latex-to-speech
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Setup
|
|
350
|
+
|
|
351
|
+
For math to work with word highlighting, you need additional plugins that run in a specific order:
|
|
352
|
+
|
|
353
|
+
```javascript
|
|
354
|
+
// astro.config.mjs
|
|
355
|
+
import { defineConfig } from "astro/config";
|
|
356
|
+
import vocasync from "@vocasync/astro";
|
|
357
|
+
import { rehypeAudioWords, rehypeMathSpeech, remarkMathSpeech } from "@vocasync/astro/rehype";
|
|
358
|
+
import remarkMath from "remark-math";
|
|
359
|
+
import rehypeKatex from "rehype-katex"; // or rehype-mathjax
|
|
360
|
+
|
|
361
|
+
export default defineConfig({
|
|
362
|
+
markdown: {
|
|
363
|
+
remarkPlugins: [
|
|
364
|
+
remarkMath, // 1. Parse LaTeX syntax
|
|
365
|
+
remarkMathSpeech, // 2. Collect math expressions
|
|
366
|
+
],
|
|
367
|
+
rehypePlugins: [
|
|
368
|
+
rehypeKatex, // 3. Render math to HTML
|
|
369
|
+
rehypeMathSpeech, // 4. Inject hidden spoken text
|
|
370
|
+
[rehypeAudioWords, { // 5. Wrap words with timing (runs last)
|
|
371
|
+
collectionName: "blog",
|
|
372
|
+
audioMapPath: "src/data/audio-map.json"
|
|
373
|
+
}]
|
|
374
|
+
]
|
|
375
|
+
},
|
|
376
|
+
integrations: [vocasync()],
|
|
377
|
+
});
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### How It Works
|
|
381
|
+
|
|
382
|
+
1. **remarkMathSpeech** collects all LaTeX expressions during markdown parsing
|
|
383
|
+
2. **rehypeKatex/rehypeMathjax** renders the math to visual HTML
|
|
384
|
+
3. **rehypeMathSpeech** converts LaTeX to spoken text (e.g., `$x^2$` → "x squared") and injects it as hidden `<span>` elements
|
|
385
|
+
4. **rehypeAudioWords** wraps all text (including the spoken math) with timing spans
|
|
386
|
+
|
|
387
|
+
The spoken text is visually hidden (`sr-only`) but gets highlighted during audio playback.
|
|
388
|
+
|
|
389
|
+
### Configuration
|
|
390
|
+
|
|
391
|
+
Set the speech style in `vocasync.config.mjs`:
|
|
392
|
+
|
|
393
|
+
```javascript
|
|
394
|
+
export default {
|
|
395
|
+
// ...
|
|
396
|
+
math: {
|
|
397
|
+
enabled: true,
|
|
398
|
+
style: "clearspeak", // or "mathspeak"
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
- **clearspeak**: Natural, conversational style (recommended)
|
|
404
|
+
- **mathspeak**: More formal, precise mathematical speech
|
|
405
|
+
|
|
406
|
+
## Deployment
|
|
407
|
+
|
|
408
|
+
### Build Strategy
|
|
409
|
+
|
|
410
|
+
#### For Large Content Collections
|
|
411
|
+
|
|
412
|
+
If you have many posts, we recommend running `npx vocasync sync` **once locally** before your first deployment:
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
# Run locally to generate all audio (may take a while)
|
|
416
|
+
npx vocasync sync
|
|
417
|
+
|
|
418
|
+
# Commit the audio-map to version control
|
|
419
|
+
git add src/data/audio-map.json
|
|
420
|
+
git commit -m "Add audio map"
|
|
421
|
+
git push
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
This approach:
|
|
425
|
+
- Prevents long CI/CD build times (important for platforms like Vercel with time limits)
|
|
426
|
+
- Only new or changed posts will be processed on subsequent builds
|
|
427
|
+
- Audio map acts as a cache - existing entries are skipped
|
|
428
|
+
|
|
429
|
+
#### For New/Updated Posts
|
|
430
|
+
|
|
431
|
+
For ongoing updates, include the sync command in your build script:
|
|
432
|
+
|
|
433
|
+
```json
|
|
434
|
+
{
|
|
435
|
+
"scripts": {
|
|
436
|
+
"dev": "astro dev",
|
|
437
|
+
"build": "npx vocasync sync && astro build",
|
|
438
|
+
"preview": "astro preview"
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
Since most builds only process new or changed content, this adds minimal time.
|
|
444
|
+
|
|
445
|
+
### CI/CD Environment Variables
|
|
446
|
+
|
|
447
|
+
Make sure to set `VOCASYNC_API_KEY` in your deployment environment:
|
|
448
|
+
|
|
449
|
+
- **Vercel**: Settings → Environment Variables
|
|
450
|
+
- **Netlify**: Site settings → Environment variables
|
|
451
|
+
- **GitHub Actions**: Repository secrets
|
|
452
|
+
|
|
453
|
+
### Example GitHub Actions
|
|
454
|
+
|
|
455
|
+
```yaml
|
|
456
|
+
name: Deploy
|
|
457
|
+
on:
|
|
458
|
+
push:
|
|
459
|
+
branches: [main]
|
|
460
|
+
|
|
461
|
+
jobs:
|
|
462
|
+
build:
|
|
463
|
+
runs-on: ubuntu-latest
|
|
464
|
+
steps:
|
|
465
|
+
- uses: actions/checkout@v4
|
|
466
|
+
- uses: oven-sh/setup-bun@v1
|
|
467
|
+
|
|
468
|
+
- run: bun install
|
|
469
|
+
- run: bun run build
|
|
470
|
+
env:
|
|
471
|
+
VOCASYNC_API_KEY: ${{ secrets.VOCASYNC_API_KEY }}
|
|
472
|
+
|
|
473
|
+
- name: Deploy
|
|
474
|
+
# Your deploy step here
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
## Important: Audio Map
|
|
478
|
+
|
|
479
|
+
### What is audio-map.json?
|
|
480
|
+
|
|
481
|
+
The `audio-map.json` file is the **source of truth** for VocaSync. It stores:
|
|
482
|
+
|
|
483
|
+
- Project UUIDs for each synced article
|
|
484
|
+
- Content hashes (to detect changes)
|
|
485
|
+
- Audio and alignment URLs
|
|
486
|
+
- Timestamps
|
|
487
|
+
|
|
488
|
+
### ⚠️ Do Not Delete
|
|
489
|
+
|
|
490
|
+
**If you delete `audio-map.json`, running `npx vocasync sync` will re-create synthesis and alignment jobs for ALL content.** This will:
|
|
491
|
+
|
|
492
|
+
1. Incur API costs for re-processing everything
|
|
493
|
+
2. Generate new audio files (old URLs will still work)
|
|
494
|
+
|
|
495
|
+
### Best Practices
|
|
496
|
+
|
|
497
|
+
1. **Commit to version control**: Add `audio-map.json` to git
|
|
498
|
+
2. **Back it up**: Keep a backup before major changes
|
|
499
|
+
3. **Don't edit manually**: Let the CLI manage this file
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
# Add to git
|
|
503
|
+
git add src/data/audio-map.json
|
|
504
|
+
git commit -m "Add audio map"
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### What to Ignore
|
|
508
|
+
|
|
509
|
+
Add your `.env` file to `.gitignore`:
|
|
510
|
+
|
|
511
|
+
```gitignore
|
|
512
|
+
# .gitignore
|
|
513
|
+
.env
|
|
514
|
+
.env.local
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
## Customizing Styles
|
|
518
|
+
|
|
519
|
+
Override CSS variables to match your theme:
|
|
520
|
+
|
|
521
|
+
```css
|
|
522
|
+
:root {
|
|
523
|
+
/* Player colors */
|
|
524
|
+
--vocasync-primary: #3b82f6;
|
|
525
|
+
--vocasync-primary-content: white;
|
|
526
|
+
--vocasync-surface: #f8fafc;
|
|
527
|
+
--vocasync-border: #e2e8f0;
|
|
528
|
+
--vocasync-text: #1e293b;
|
|
529
|
+
--vocasync-text-muted: #64748b;
|
|
530
|
+
|
|
531
|
+
/* Word highlighting */
|
|
532
|
+
--vocasync-highlight: #10b981;
|
|
533
|
+
--vocasync-highlight-text: white;
|
|
534
|
+
--vocasync-highlight-active-opacity: 0.25;
|
|
535
|
+
--vocasync-highlight-trail-opacity: 0.12;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/* Dark mode */
|
|
539
|
+
@media (prefers-color-scheme: dark) {
|
|
540
|
+
:root {
|
|
541
|
+
--vocasync-surface: #1e293b;
|
|
542
|
+
--vocasync-border: #334155;
|
|
543
|
+
--vocasync-text: #f1f5f9;
|
|
544
|
+
--vocasync-text-muted: #94a3b8;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
## Troubleshooting
|
|
550
|
+
|
|
551
|
+
### "No VocaSync configuration found"
|
|
552
|
+
|
|
553
|
+
Create a `vocasync.config.mjs` file in your project root.
|
|
554
|
+
|
|
555
|
+
### Words not highlighting
|
|
556
|
+
|
|
557
|
+
1. Make sure the rehype plugin is configured in `astro.config.mjs`
|
|
558
|
+
2. Check that `collectionName` matches your collection
|
|
559
|
+
3. Verify `audioMapPath` points to your audio map
|
|
560
|
+
4. Ensure content is wrapped in `[data-article-body]`
|
|
561
|
+
|
|
562
|
+
### Audio not playing
|
|
563
|
+
|
|
564
|
+
1. Run `npx vocasync sync` to generate audio
|
|
565
|
+
2. Check that `audio-map.json` exists and has entries
|
|
566
|
+
3. Verify the `slug` prop matches your content slug
|
|
567
|
+
|
|
568
|
+
### CLI errors
|
|
569
|
+
|
|
570
|
+
```bash
|
|
571
|
+
# Check your configuration
|
|
572
|
+
npx vocasync check
|
|
573
|
+
|
|
574
|
+
# Verify API key is set
|
|
575
|
+
echo $VOCASYNC_API_KEY
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
## License
|
|
579
|
+
|
|
580
|
+
MIT
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { VocaSyncConfig } from "../config/index.js";
|
|
2
|
+
import type { SynthesisResponse, ProjectStatus, AlignmentData } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* VocaSync API client for synthesis and alignment operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class VocaSyncClient {
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private apiKey;
|
|
9
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Make an authenticated API request.
|
|
12
|
+
*/
|
|
13
|
+
private request;
|
|
14
|
+
/**
|
|
15
|
+
* Create a synthesis project with alignment.
|
|
16
|
+
*
|
|
17
|
+
* Uses the `align=true` flag to automatically create a linked alignment project
|
|
18
|
+
* that starts processing once synthesis completes.
|
|
19
|
+
*/
|
|
20
|
+
synthesize(params: {
|
|
21
|
+
name: string;
|
|
22
|
+
text: string;
|
|
23
|
+
voice: string;
|
|
24
|
+
quality: "sd" | "hd";
|
|
25
|
+
language: string;
|
|
26
|
+
}): Promise<SynthesisResponse>;
|
|
27
|
+
/**
|
|
28
|
+
* Get project status including synthesis and alignment job status.
|
|
29
|
+
*/
|
|
30
|
+
getProjectStatus(projectUuid: string): Promise<ProjectStatus>;
|
|
31
|
+
/**
|
|
32
|
+
* Fetch alignment data (words with timestamps) from completed alignment job.
|
|
33
|
+
*/
|
|
34
|
+
getAlignment(alignmentUrl: string): Promise<AlignmentData>;
|
|
35
|
+
/**
|
|
36
|
+
* Poll project status until completion or failure.
|
|
37
|
+
*
|
|
38
|
+
* @param projectUuid - The project to poll
|
|
39
|
+
* @param options - Polling options
|
|
40
|
+
* @returns The final project status
|
|
41
|
+
*/
|
|
42
|
+
pollUntilComplete(projectUuid: string, options?: {
|
|
43
|
+
maxAttempts?: number;
|
|
44
|
+
intervalMs?: number;
|
|
45
|
+
onProgress?: (status: ProjectStatus) => void;
|
|
46
|
+
}): Promise<ProjectStatus>;
|
|
47
|
+
/**
|
|
48
|
+
* Check API key validity and account balance.
|
|
49
|
+
*/
|
|
50
|
+
validateApiKey(): Promise<{
|
|
51
|
+
valid: boolean;
|
|
52
|
+
balance?: number;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Custom error class for VocaSync API errors.
|
|
57
|
+
*/
|
|
58
|
+
export declare class VocaSyncAPIError extends Error {
|
|
59
|
+
statusCode: number;
|
|
60
|
+
responseBody?: string;
|
|
61
|
+
constructor(message: string, statusCode: number, responseBody?: string);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a VocaSync client from configuration.
|
|
65
|
+
*/
|
|
66
|
+
export declare function createClient(_config: VocaSyncConfig): VocaSyncClient;
|
|
67
|
+
/**
|
|
68
|
+
* Get streaming URLs for stable audio/alignment access.
|
|
69
|
+
* These URLs don't expire and redirect to fresh presigned URLs on each request.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getStreamingUrls(projectUuid: string, baseUrl?: string): {
|
|
72
|
+
synthesisUrl: string;
|
|
73
|
+
alignmentUrl: string;
|
|
74
|
+
srtUrl: string;
|
|
75
|
+
vttUrl: string;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EAEb,aAAa,EAEd,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM,EAAE,OAAO,SAA+B;IAKlE;;OAEG;YACW,OAAO;IA8BrB;;;;;OAKG;IACG,UAAU,CAAC,MAAM,EAAE;QACvB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,IAAI,GAAG,IAAI,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkC9B;;OAEG;IACG,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAyCnE;;OAEG;IACG,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAuBhE;;;;;;OAMG;IACG,iBAAiB,CACrB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;KACzC,GACL,OAAO,CAAC,aAAa,CAAC;IA0DzB;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAWtE;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;CAMvE;AASD;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAWpE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,OAAO,SAA+B,GACrC;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAOA"}
|