@vocasync/astro 1.0.1 → 2.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.
Files changed (148) hide show
  1. package/README.md +735 -93
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js.map +1 -1
  4. package/dist/api/index.d.ts +1 -1
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api/index.js +1 -1
  7. package/dist/api/index.js.map +1 -1
  8. package/dist/cli.js.map +1 -1
  9. package/dist/components/AudioPlayer.astro +305 -1141
  10. package/dist/components/index.d.ts +10 -32
  11. package/dist/components/index.d.ts.map +1 -1
  12. package/dist/components/index.js +1 -3
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/components/types.d.ts +117 -0
  15. package/dist/components/types.d.ts.map +1 -0
  16. package/dist/components/types.js +2 -0
  17. package/dist/components/types.js.map +1 -0
  18. package/dist/config/index.d.ts +3 -2
  19. package/dist/config/index.d.ts.map +1 -1
  20. package/dist/config/index.js +2 -1
  21. package/dist/config/index.js.map +1 -1
  22. package/dist/config/languages.d.ts +33 -0
  23. package/dist/config/languages.d.ts.map +1 -0
  24. package/dist/config/languages.js +167 -0
  25. package/dist/config/languages.js.map +1 -0
  26. package/dist/config/schema.d.ts +225 -172
  27. package/dist/config/schema.d.ts.map +1 -1
  28. package/dist/config/schema.js +45 -24
  29. package/dist/config/schema.js.map +1 -1
  30. package/dist/core/content-loader.js +1 -1
  31. package/dist/core/content-loader.js.map +1 -1
  32. package/dist/core/index.d.ts +2 -2
  33. package/dist/core/index.d.ts.map +1 -1
  34. package/dist/core/index.js +2 -2
  35. package/dist/core/index.js.map +1 -1
  36. package/dist/core/speech-builder.js.map +1 -1
  37. package/dist/index.d.ts +6 -7
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +5 -6
  40. package/dist/index.js.map +1 -1
  41. package/dist/integration.d.ts +28 -2
  42. package/dist/integration.d.ts.map +1 -1
  43. package/dist/integration.js +40 -3
  44. package/dist/integration.js.map +1 -1
  45. package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
  46. package/dist/lib/latex-to-speech/index.js.map +1 -1
  47. package/dist/player-core/boot.d.ts +9 -0
  48. package/dist/player-core/boot.d.ts.map +1 -0
  49. package/dist/player-core/boot.js +59 -0
  50. package/dist/player-core/boot.js.map +1 -0
  51. package/dist/player-core/highlighter.d.ts +31 -0
  52. package/dist/player-core/highlighter.d.ts.map +1 -0
  53. package/dist/player-core/highlighter.js +103 -0
  54. package/dist/player-core/highlighter.js.map +1 -0
  55. package/dist/player-core/index.d.ts +17 -0
  56. package/dist/player-core/index.d.ts.map +1 -0
  57. package/dist/player-core/index.js +24 -0
  58. package/dist/player-core/index.js.map +1 -0
  59. package/dist/player-core/media-url.d.ts +18 -0
  60. package/dist/player-core/media-url.d.ts.map +1 -0
  61. package/dist/player-core/media-url.js +33 -0
  62. package/dist/player-core/media-url.js.map +1 -0
  63. package/dist/player-core/player.d.ts +9 -0
  64. package/dist/player-core/player.d.ts.map +1 -0
  65. package/dist/player-core/player.js +622 -0
  66. package/dist/player-core/player.js.map +1 -0
  67. package/dist/player-core/registry.d.ts +20 -0
  68. package/dist/player-core/registry.d.ts.map +1 -0
  69. package/dist/player-core/registry.js +31 -0
  70. package/dist/player-core/registry.js.map +1 -0
  71. package/dist/player-core/seek-delegate.d.ts +24 -0
  72. package/dist/player-core/seek-delegate.d.ts.map +1 -0
  73. package/dist/player-core/seek-delegate.js +64 -0
  74. package/dist/player-core/seek-delegate.js.map +1 -0
  75. package/dist/player-core/storage.d.ts +38 -0
  76. package/dist/player-core/storage.d.ts.map +1 -0
  77. package/dist/player-core/storage.js +107 -0
  78. package/dist/player-core/storage.js.map +1 -0
  79. package/dist/player-core/strings.d.ts +53 -0
  80. package/dist/player-core/strings.d.ts.map +1 -0
  81. package/dist/player-core/strings.js +45 -0
  82. package/dist/player-core/strings.js.map +1 -0
  83. package/dist/player-core/timings.d.ts +56 -0
  84. package/dist/player-core/timings.d.ts.map +1 -0
  85. package/dist/player-core/timings.js +90 -0
  86. package/dist/player-core/timings.js.map +1 -0
  87. package/dist/rehype/audio-words.d.ts +9 -3
  88. package/dist/rehype/audio-words.d.ts.map +1 -1
  89. package/dist/rehype/audio-words.js +17 -9
  90. package/dist/rehype/audio-words.js.map +1 -1
  91. package/dist/rehype/index.d.ts +2 -2
  92. package/dist/rehype/index.d.ts.map +1 -1
  93. package/dist/rehype/index.js.map +1 -1
  94. package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
  95. package/dist/rehype/rehype-math-speech.js +2 -0
  96. package/dist/rehype/rehype-math-speech.js.map +1 -1
  97. package/dist/styles/content.css +41 -0
  98. package/dist/styles/layers.css +13 -0
  99. package/dist/styles/player.css +517 -0
  100. package/dist/styles/preset-shadcn.css +31 -0
  101. package/dist/styles/tokens.css +266 -0
  102. package/dist/styles/vocasync.css +10 -0
  103. package/dist/sync/index.d.ts +1 -1
  104. package/dist/sync/index.d.ts.map +1 -1
  105. package/dist/sync/index.js +1 -1
  106. package/dist/sync/index.js.map +1 -1
  107. package/dist/sync/orchestrator.d.ts.map +1 -1
  108. package/dist/sync/orchestrator.js +101 -47
  109. package/dist/sync/orchestrator.js.map +1 -1
  110. package/dist/types/index.d.ts +19 -5
  111. package/dist/types/index.d.ts.map +1 -1
  112. package/package.json +39 -17
  113. package/src/api/index.ts +4 -4
  114. package/src/components/AudioPlayer.astro +305 -1141
  115. package/src/components/index.ts +19 -34
  116. package/src/components/types.ts +140 -0
  117. package/src/config/index.ts +29 -24
  118. package/src/config/languages.ts +171 -0
  119. package/src/config/schema.ts +47 -24
  120. package/src/core/content-loader.ts +1 -1
  121. package/src/core/index.ts +7 -7
  122. package/src/env.d.ts +2 -0
  123. package/src/index.ts +23 -28
  124. package/src/integration.ts +66 -4
  125. package/src/player-core/boot.ts +62 -0
  126. package/src/player-core/highlighter.ts +159 -0
  127. package/src/player-core/index.ts +45 -0
  128. package/src/player-core/media-url.ts +35 -0
  129. package/src/player-core/player.ts +725 -0
  130. package/src/player-core/registry.ts +40 -0
  131. package/src/player-core/seek-delegate.ts +92 -0
  132. package/src/player-core/storage.ts +112 -0
  133. package/src/player-core/strings.ts +89 -0
  134. package/src/player-core/timings.ts +115 -0
  135. package/src/rehype/audio-words.ts +25 -12
  136. package/src/rehype/index.ts +2 -3
  137. package/src/rehype/rehype-math-speech.ts +3 -1
  138. package/src/styles/content.css +41 -0
  139. package/src/styles/layers.css +13 -0
  140. package/src/styles/player.css +517 -0
  141. package/src/styles/preset-shadcn.css +31 -0
  142. package/src/styles/tokens.css +266 -0
  143. package/src/styles/vocasync.css +10 -0
  144. package/src/sync/index.ts +1 -1
  145. package/src/sync/orchestrator.ts +120 -56
  146. package/src/types/index.ts +19 -5
  147. package/dist/styles/variables.css +0 -164
  148. package/src/styles/variables.css +0 -164
@@ -1,34 +1,19 @@
1
- // Components are re-exported from the main components directory
2
- // Import using: import { AudioPlayer } from "@vocasync/astro/components"
3
-
4
- // Note: AudioPlayer.astro is copied to dist during build
5
- // This file provides TypeScript types for the component
6
-
7
- export interface AudioPlayerProps {
8
- /** Post slug to lookup audio in audio-map */
9
- slug: string;
10
- /** Audio entry data from audio-map.json */
11
- audioEntry?: {
12
- audioUrl: string;
13
- alignmentUrl?: string;
14
- words?: { word: string; start: number; end: number }[];
15
- duration?: number;
16
- publishableKey?: string;
17
- };
18
- /** Accessible label for the player */
19
- label?: string;
20
- /** Show placeholder when no audio available */
21
- showPlaceholder?: boolean;
22
- /** Additional CSS classes */
23
- class?: string;
24
- /** Selector for article body (for word highlighting) */
25
- articleSelector?: string;
26
- /** Enable floating mini player when main player scrolls out of view */
27
- enableMiniPlayer?: boolean;
28
- /** Enable word highlighting during playback */
29
- enableHighlighting?: boolean;
30
- /** Enable click on words to seek to that position */
31
- enableClickToSeek?: boolean;
32
- /** Number of trailing highlighted words */
33
- trailLength?: number;
34
- }
1
+ /**
2
+ * Types for the AudioPlayer component.
3
+ *
4
+ * The component itself is an .astro file and cannot be re-exported from JavaScript;
5
+ * import it directly:
6
+ *
7
+ * import AudioPlayer from "@vocasync/astro/components/AudioPlayer.astro";
8
+ */
9
+ export type {
10
+ AudioEntry,
11
+ AudioPlayerProps,
12
+ AutoScrollMode,
13
+ ControlName,
14
+ DockOptions,
15
+ HighlightOptions,
16
+ PlayerSize,
17
+ PlayerVariant,
18
+ } from "./types.js";
19
+ export { DEFAULT_CONTROLS } from "./types.js";
@@ -0,0 +1,140 @@
1
+ import type { SerializableStrings } from "../player-core/strings.js";
2
+ import type { AlignedWord } from "../types/index.js";
3
+
4
+ /**
5
+ * The AudioPlayer's props, defined once.
6
+ *
7
+ * This file previously described a component that did not exist: it declared
8
+ * `publishableKey` and `alignmentUrl` while the component took `synthesisPublishableKey`
9
+ * and had no `alignmentUrl` at all, and it advertised a named `AudioPlayer` export that
10
+ * could not be imported. The .astro now imports this type rather than restating it, so
11
+ * the two cannot drift again.
12
+ */
13
+
14
+ /** A control the player can render, in the order you list it. */
15
+ export type ControlName =
16
+ | "play"
17
+ /** Elapsed/total time above the seek bar; grows to fill the row. */
18
+ | "progress"
19
+ /** Elapsed/total time on its own. */
20
+ | "time"
21
+ | "highlight"
22
+ | "speed"
23
+ /** Mute button plus volume slider. */
24
+ | "volume"
25
+ /** Jump backwards by `skipSeconds`. */
26
+ | "skip-back"
27
+ /** Jump forwards by `skipSeconds`. */
28
+ | "skip-forward";
29
+
30
+ export const DEFAULT_CONTROLS: ControlName[] = ["play", "progress", "highlight", "speed", "volume"];
31
+
32
+ /** Shape of the player. `bar` is the default horizontal strip. */
33
+ export type PlayerVariant = "bar" | "minimal" | "card";
34
+
35
+ export type PlayerSize = "sm" | "md" | "lg";
36
+
37
+ /** What follows the spoken word as it plays. */
38
+ export type AutoScrollMode = "off" | "paragraph";
39
+
40
+ export interface AudioEntry {
41
+ audioUrl: string;
42
+ words?: AlignedWord[];
43
+ duration?: number;
44
+ /** Publishable key for the synthesis stream (v3 audio-map). */
45
+ synthesisPublishableKey?: string;
46
+ }
47
+
48
+ export interface HighlightOptions {
49
+ /** @default true */
50
+ enabled?: boolean;
51
+ /** Words kept marked behind the active one. @default 4 */
52
+ trailLength?: number;
53
+ /**
54
+ * Clicking a word seeks to it.
55
+ *
56
+ * Independent of `enabled`: it used to live inside the highlighting branch, so
57
+ * turning highlighting off silently disabled click-to-seek too.
58
+ *
59
+ * @default true
60
+ */
61
+ clickToSeek?: boolean;
62
+ }
63
+
64
+ export interface DockOptions {
65
+ /** Show a floating player once the main one scrolls out of view. @default true */
66
+ enabled?: boolean;
67
+ }
68
+
69
+ export interface AudioPlayerProps {
70
+ /** Post slug, used to look up audio and to key saved playback position. */
71
+ slug: string;
72
+ /** Audio entry from audio-map.json. */
73
+ audioEntry?: AudioEntry;
74
+
75
+ /** Shape and scale. */
76
+ variant?: PlayerVariant;
77
+ size?: PlayerSize;
78
+ /** Which controls to render, and in what order. */
79
+ controls?: ControlName[];
80
+ /** Playback rates offered by the speed menu. */
81
+ speeds?: number[];
82
+ /** How far the skip controls and arrow keys jump. @default 15 */
83
+ skipSeconds?: number;
84
+
85
+ /** Overrides for any visible text or accessible label. */
86
+ strings?: Partial<SerializableStrings>;
87
+
88
+ /** Selector for the element containing the article's word spans. */
89
+ articleSelector?: string;
90
+ highlight?: HighlightOptions;
91
+ dock?: DockOptions;
92
+
93
+ /**
94
+ * Follow the spoken word by scrolling its paragraph into view.
95
+ *
96
+ * Defaults to off. It was previously forced on with no way to disable it, which
97
+ * takes over the reader's scroll position while they are reading something else.
98
+ *
99
+ * @default "off"
100
+ */
101
+ autoScroll?: AutoScrollMode;
102
+
103
+ /** Pause other players on the page when this one starts. @default true */
104
+ exclusive?: boolean;
105
+
106
+ /**
107
+ * Remember speed, volume, mute and highlighting across pages and visits.
108
+ * @default true
109
+ */
110
+ rememberPreferences?: boolean;
111
+
112
+ /**
113
+ * Resume where the reader left off, keyed by `slug`.
114
+ *
115
+ * Off by default: it is a pleasant surprise on a long article and a confusing one
116
+ * on a short post that someone expects to start from the beginning.
117
+ *
118
+ * @default false
119
+ */
120
+ rememberPosition?: boolean;
121
+
122
+ /**
123
+ * Publish title and artwork to the OS media controls (lock screen, media keys).
124
+ * @default true
125
+ */
126
+ mediaSession?: boolean;
127
+
128
+ /** Title for the OS media controls. Falls back to the accessible label. */
129
+ title?: string;
130
+ /** Artwork URL for the OS media controls. */
131
+ artwork?: string;
132
+
133
+ /** Show a message when the article has no audio. @default true */
134
+ showPlaceholder?: boolean;
135
+
136
+ /** Extra classes on the player root. */
137
+ class?: string;
138
+ /** Overrides the generated element id. */
139
+ id?: string;
140
+ }
@@ -1,32 +1,37 @@
1
1
  export {
2
- VocaSyncConfigSchema,
3
- CollectionConfigSchema,
4
- SynthesisConfigSchema,
5
- MathConfigSchema,
6
- OutputConfigSchema,
7
- ProcessingConfigSchema,
8
- VoiceSchema,
9
- QualitySchema,
10
- FormatSchema,
11
- LanguageSchema,
12
- MathStyleSchema,
13
- validateConfig,
14
- defaultConfig,
15
- } from "./schema.js";
16
-
2
+ ALIGNMENT_LOCALES,
3
+ canAlign,
4
+ LANGUAGE_NAMES,
5
+ SYNTHESIS_LANGUAGES,
6
+ toAlignmentLocale,
7
+ } from "./languages.js";
8
+ export { loadVocaSyncConfig } from "./loader.js";
17
9
  export type {
18
- VocaSyncConfig,
19
- VocaSyncUserConfig,
20
10
  CollectionConfig,
21
- SynthesisConfig,
11
+ Format,
12
+ Language,
22
13
  MathConfig,
14
+ MathStyle,
23
15
  OutputConfig,
24
16
  ProcessingConfig,
25
- Voice,
26
17
  Quality,
27
- Format,
28
- Language,
29
- MathStyle,
18
+ SynthesisConfig,
19
+ VocaSyncConfig,
20
+ VocaSyncUserConfig,
21
+ Voice,
22
+ } from "./schema.js";
23
+ export {
24
+ CollectionConfigSchema,
25
+ defaultConfig,
26
+ FormatSchema,
27
+ LanguageSchema,
28
+ MathConfigSchema,
29
+ MathStyleSchema,
30
+ OutputConfigSchema,
31
+ ProcessingConfigSchema,
32
+ QualitySchema,
33
+ SynthesisConfigSchema,
34
+ VocaSyncConfigSchema,
35
+ VoiceSchema,
36
+ validateConfig,
30
37
  } from "./schema.js";
31
-
32
- export { loadVocaSyncConfig } from "./loader.js";
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Language support, which is not one list but two.
3
+ *
4
+ * Speech synthesis covers 57 languages. Forced alignment -- the word-level timing
5
+ * that drives highlighting and click-to-seek -- covers far fewer. A post that needs
6
+ * highlighting is therefore limited to the intersection; a post synthesised without
7
+ * alignment is limited only by the voice.
8
+ *
9
+ * Both lists mirror the enums published in the VocaSync OpenAPI document. Korean was
10
+ * withdrawn from alignment in September 2026 and remains available for synthesis.
11
+ */
12
+
13
+ /** Every language the synthesis voices can speak, ISO 639-1. */
14
+ export const SYNTHESIS_LANGUAGES = [
15
+ "af", // Afrikaans
16
+ "ar", // Arabic
17
+ "hy", // Armenian
18
+ "az", // Azerbaijani
19
+ "be", // Belarusian
20
+ "bs", // Bosnian
21
+ "bg", // Bulgarian
22
+ "ca", // Catalan
23
+ "zh", // Chinese
24
+ "hr", // Croatian
25
+ "cs", // Czech
26
+ "da", // Danish
27
+ "nl", // Dutch
28
+ "en", // English
29
+ "et", // Estonian
30
+ "fi", // Finnish
31
+ "fr", // French
32
+ "gl", // Galician
33
+ "de", // German
34
+ "el", // Greek
35
+ "he", // Hebrew
36
+ "hi", // Hindi
37
+ "hu", // Hungarian
38
+ "is", // Icelandic
39
+ "id", // Indonesian
40
+ "it", // Italian
41
+ "ja", // Japanese
42
+ "kn", // Kannada
43
+ "kk", // Kazakh
44
+ "ko", // Korean
45
+ "lv", // Latvian
46
+ "lt", // Lithuanian
47
+ "mk", // Macedonian
48
+ "ms", // Malay
49
+ "mr", // Marathi
50
+ "mi", // Maori
51
+ "ne", // Nepali
52
+ "no", // Norwegian
53
+ "fa", // Persian
54
+ "pl", // Polish
55
+ "pt", // Portuguese
56
+ "ro", // Romanian
57
+ "ru", // Russian
58
+ "sr", // Serbian
59
+ "sk", // Slovak
60
+ "sl", // Slovenian
61
+ "es", // Spanish
62
+ "sw", // Swahili
63
+ "sv", // Swedish
64
+ "tl", // Tagalog
65
+ "ta", // Tamil
66
+ "th", // Thai
67
+ "tr", // Turkish
68
+ "uk", // Ukrainian
69
+ "ur", // Urdu
70
+ "vi", // Vietnamese
71
+ "cy", // Welsh
72
+ ] as const;
73
+
74
+ /**
75
+ * Synthesis languages that can also be force-aligned, mapped to the locale the
76
+ * alignment API expects. A language absent from here can still be synthesised --
77
+ * it simply cannot carry word timings.
78
+ */
79
+ export const ALIGNMENT_LOCALES: Readonly<Record<string, string>> = {
80
+ en: "en-US", // English
81
+ fr: "fr", // French
82
+ de: "de", // German
83
+ es: "es", // Spanish
84
+ pt: "pt-PT", // Portuguese
85
+ sv: "sv", // Swedish
86
+ cs: "cs", // Czech
87
+ pl: "pl", // Polish
88
+ tr: "tr", // Turkish
89
+ ru: "ru", // Russian
90
+ uk: "uk", // Ukrainian
91
+ ja: "ja", // Japanese
92
+ zh: "zh-CN", // Chinese
93
+ };
94
+
95
+ /** Human-readable names, for error messages and docs. */
96
+ export const LANGUAGE_NAMES: Readonly<Record<string, string>> = {
97
+ af: "Afrikaans",
98
+ ar: "Arabic",
99
+ hy: "Armenian",
100
+ az: "Azerbaijani",
101
+ be: "Belarusian",
102
+ bs: "Bosnian",
103
+ bg: "Bulgarian",
104
+ ca: "Catalan",
105
+ zh: "Chinese",
106
+ hr: "Croatian",
107
+ cs: "Czech",
108
+ da: "Danish",
109
+ nl: "Dutch",
110
+ en: "English",
111
+ et: "Estonian",
112
+ fi: "Finnish",
113
+ fr: "French",
114
+ gl: "Galician",
115
+ de: "German",
116
+ el: "Greek",
117
+ he: "Hebrew",
118
+ hi: "Hindi",
119
+ hu: "Hungarian",
120
+ is: "Icelandic",
121
+ id: "Indonesian",
122
+ it: "Italian",
123
+ ja: "Japanese",
124
+ kn: "Kannada",
125
+ kk: "Kazakh",
126
+ ko: "Korean",
127
+ lv: "Latvian",
128
+ lt: "Lithuanian",
129
+ mk: "Macedonian",
130
+ ms: "Malay",
131
+ mr: "Marathi",
132
+ mi: "Maori",
133
+ ne: "Nepali",
134
+ no: "Norwegian",
135
+ fa: "Persian",
136
+ pl: "Polish",
137
+ pt: "Portuguese",
138
+ ro: "Romanian",
139
+ ru: "Russian",
140
+ sr: "Serbian",
141
+ sk: "Slovak",
142
+ sl: "Slovenian",
143
+ es: "Spanish",
144
+ sw: "Swahili",
145
+ sv: "Swedish",
146
+ tl: "Tagalog",
147
+ ta: "Tamil",
148
+ th: "Thai",
149
+ tr: "Turkish",
150
+ uk: "Ukrainian",
151
+ ur: "Urdu",
152
+ vi: "Vietnamese",
153
+ cy: "Welsh",
154
+ };
155
+
156
+ /** True when a language can carry word-level timings. */
157
+ export function canAlign(language: string): boolean {
158
+ return Object.hasOwn(ALIGNMENT_LOCALES, language);
159
+ }
160
+
161
+ /**
162
+ * The locale the alignment API expects, or null when the language cannot align.
163
+ *
164
+ * Returning null rather than defaulting matters: the previous implementation fell
165
+ * back to `en-US` for anything unrecognised, so a language outside the aligned set
166
+ * would have been aligned against an English acoustic model -- producing timings
167
+ * that are confidently wrong rather than an error.
168
+ */
169
+ export function toAlignmentLocale(language: string): string | null {
170
+ return ALIGNMENT_LOCALES[language] ?? null;
171
+ }
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { ALIGNMENT_LOCALES, canAlign, LANGUAGE_NAMES, SYNTHESIS_LANGUAGES } from "./languages.js";
2
3
 
3
4
  /**
4
5
  * Supported TTS voices (matches the platform's 9 OpenAI voices)
@@ -30,26 +31,14 @@ export const FormatSchema = z.enum(["mp3", "aac", "opus", "flac", "wav"]);
30
31
  export type Format = z.infer<typeof FormatSchema>;
31
32
 
32
33
  /**
33
- * Supported languages for synthesis + alignment
34
- * Uses short ISO 639-1 codes as expected by the VocaSync API
35
- * Only languages where both OpenAI TTS synthesis and MFA forced alignment are available
34
+ * Languages the synthesis voices can speak (ISO 639-1).
35
+ *
36
+ * Wider than the set that can be force-aligned. A post that needs word highlighting is
37
+ * additionally constrained by `ALIGNMENT_LOCALES`; one synthesised with `align: false`
38
+ * is not. `validateConfig` rejects the impossible combination rather than letting a
39
+ * sync pay for synthesis and then fail at the alignment step.
36
40
  */
37
- export const LanguageSchema = z.enum([
38
- "zh",
39
- "cs",
40
- "en",
41
- "fr",
42
- "de",
43
- "ja",
44
- "ko",
45
- "pl",
46
- "pt",
47
- "ru",
48
- "es",
49
- "sv",
50
- "tr",
51
- "uk",
52
- ]);
41
+ export const LanguageSchema = z.enum(SYNTHESIS_LANGUAGES);
53
42
  export type Language = z.infer<typeof LanguageSchema>;
54
43
 
55
44
  /**
@@ -124,15 +113,25 @@ export const VocaSyncConfigSchema = z.object({
124
113
  /** Language for synthesis (e.g., "en", "fr", "de") */
125
114
  language: LanguageSchema.default("en"),
126
115
  /** Synthesis options */
127
- synthesis: SynthesisConfigSchema.default({}),
116
+ synthesis: SynthesisConfigSchema.prefault({}),
128
117
  /** Math/LaTeX support */
129
- math: MathConfigSchema.default({}),
118
+ math: MathConfigSchema.prefault({}),
130
119
  /** Output paths */
131
- output: OutputConfigSchema.default({}),
120
+ output: OutputConfigSchema.prefault({}),
121
+ /**
122
+ * Produce word-level timings, which is what powers highlighting and click-to-seek.
123
+ *
124
+ * Turn it off for narration alone: it costs less, and it lifts the language ceiling
125
+ * from the aligned set to every language the voices can speak. Overridable per post
126
+ * with `align: false` in frontmatter.
127
+ *
128
+ * @default true
129
+ */
130
+ align: z.boolean().default(true),
132
131
  /** Frontmatter field to check for audio opt-in/out (true/false) */
133
132
  frontmatterField: z.string().optional(),
134
133
  /** Processing options */
135
- processing: ProcessingConfigSchema.default({}),
134
+ processing: ProcessingConfigSchema.prefault({}),
136
135
  });
137
136
 
138
137
  export type VocaSyncConfig = z.infer<typeof VocaSyncConfigSchema>;
@@ -170,7 +169,30 @@ export type VocaSyncUserConfig = {
170
169
  * Validate and normalize user configuration
171
170
  */
172
171
  export function validateConfig(userConfig: VocaSyncUserConfig): VocaSyncConfig {
173
- return VocaSyncConfigSchema.parse(userConfig);
172
+ const config = VocaSyncConfigSchema.parse(userConfig);
173
+ assertLanguageSupportsAlignment(config.language, config.align);
174
+ return config;
175
+ }
176
+
177
+ /**
178
+ * Reject a language that cannot be aligned while alignment is requested.
179
+ *
180
+ * Caught here rather than at sync time because the failure would otherwise arrive
181
+ * after synthesis has already been paid for, as a rejection from the alignment
182
+ * endpoint that says nothing about how to proceed.
183
+ */
184
+ export function assertLanguageSupportsAlignment(language: string, align: boolean): void {
185
+ if (!align || canAlign(language)) return;
186
+ const name = LANGUAGE_NAMES[language] ?? language;
187
+ throw new Error(
188
+ `${name} ("${language}") can be synthesised but not force-aligned, so it cannot ` +
189
+ "carry the word timings that highlighting and click-to-seek need.\n\n" +
190
+ "Set `align: false` in vocasync.config.mjs to narrate it without highlighting, " +
191
+ "or `align: false` in a single post's frontmatter to make the exception there.\n\n" +
192
+ `Alignment is available for: ${Object.keys(ALIGNMENT_LOCALES)
193
+ .map((c) => `${LANGUAGE_NAMES[c] ?? c} (${c})`)
194
+ .join(", ")}.`
195
+ );
174
196
  }
175
197
 
176
198
  /**
@@ -178,6 +200,7 @@ export function validateConfig(userConfig: VocaSyncUserConfig): VocaSyncConfig {
178
200
  */
179
201
  export const defaultConfig: Omit<VocaSyncConfig, "collection"> = {
180
202
  language: "en",
203
+ align: true,
181
204
  synthesis: {
182
205
  voice: "onyx",
183
206
  quality: "sd",
@@ -1,4 +1,4 @@
1
- import { readFile, readdir, stat } from "node:fs/promises";
1
+ import { readdir, readFile, stat } from "node:fs/promises";
2
2
  import { basename, extname, join, relative } from "node:path";
3
3
  import type { CollectionConfig } from "../config/index.js";
4
4
  import type { ContentItem } from "../types/index.js";
package/src/core/index.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { loadContent, loadContentBySlug } from "./content-loader.js";
2
- export { buildSpeechDocument } from "./speech-builder.js";
3
- export { computeHash, hasChanged } from "./hash-manager.js";
4
1
  export {
2
+ createEmptyAudioMap,
3
+ getAudioEntry,
4
+ getAudioSlugs,
5
5
  loadAudioMap,
6
+ removeAudioEntry,
6
7
  saveAudioMap,
7
- getAudioEntry,
8
8
  setAudioEntry,
9
- removeAudioEntry,
10
- getAudioSlugs,
11
- createEmptyAudioMap,
12
9
  } from "./audio-map.js";
10
+ export { loadContent, loadContentBySlug } from "./content-loader.js";
11
+ export { computeHash, hasChanged } from "./hash-manager.js";
12
+ export { buildSpeechDocument } from "./speech-builder.js";
package/src/env.d.ts CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  declare module "virtual:vocasync/audio-map" {
4
4
  import type { AudioMap } from "@vocasync/astro";
5
+
5
6
  const audioMap: AudioMap;
6
7
  export default audioMap;
7
8
  }
8
9
 
9
10
  declare module "virtual:vocasync/config" {
10
11
  import type { VocaSyncConfig } from "@vocasync/astro";
12
+
11
13
  const config: VocaSyncConfig;
12
14
  export default config;
13
15
  }
package/src/index.ts CHANGED
@@ -23,45 +23,40 @@
23
23
  * ```
24
24
  */
25
25
 
26
- // Astro Integration
27
- export { default } from "./integration.js";
28
- export { default as vocasync } from "./integration.js";
29
-
26
+ export type {
27
+ Format,
28
+ Language,
29
+ MathStyle,
30
+ Quality,
31
+ VocaSyncConfig,
32
+ VocaSyncUserConfig,
33
+ Voice,
34
+ } from "./config/index.js";
30
35
  // Configuration
31
36
  export {
32
- validateConfig,
33
37
  defaultConfig,
34
- VocaSyncConfigSchema,
35
- VoiceSchema,
36
- QualitySchema,
37
38
  FormatSchema,
38
39
  LanguageSchema,
40
+ QualitySchema,
41
+ VocaSyncConfigSchema,
42
+ VoiceSchema,
43
+ validateConfig,
39
44
  } from "./config/index.js";
40
-
41
- export type {
42
- VocaSyncConfig,
43
- VocaSyncUserConfig,
44
- Voice,
45
- Quality,
46
- Format,
47
- Language,
48
- MathStyle,
49
- } from "./config/index.js";
50
-
45
+ export { getAudioEntry, loadAudioMap, saveAudioMap } from "./core/audio-map.js";
46
+ // Core utilities (for advanced usage)
47
+ export { loadContent } from "./core/content-loader.js";
48
+ export { computeHash } from "./core/hash-manager.js";
49
+ export { buildSpeechDocument } from "./core/speech-builder.js";
50
+ // Astro Integration
51
+ export { default, default as vocasync } from "./integration.js";
51
52
  // Types
52
53
  export type {
53
- ContentItem,
54
- SpeechDocument,
55
54
  AlignedWord,
56
55
  AudioArtifact,
57
56
  AudioMap,
57
+ ContentItem,
58
+ SpeechDocument,
58
59
  SyncResult,
59
- SyncSummary,
60
60
  SyncStatus,
61
+ SyncSummary,
61
62
  } from "./types/index.js";
62
-
63
- // Core utilities (for advanced usage)
64
- export { loadContent } from "./core/content-loader.js";
65
- export { buildSpeechDocument } from "./core/speech-builder.js";
66
- export { computeHash } from "./core/hash-manager.js";
67
- export { loadAudioMap, saveAudioMap, getAudioEntry } from "./core/audio-map.js";