@vocasync/astro 0.1.7 → 0.1.8
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/dist/api/client.d.ts +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +5 -9
- package/dist/api/client.js.map +1 -1
- package/dist/cli.js +4 -48
- package/dist/cli.js.map +1 -1
- package/dist/components/AudioPlayer.astro +1 -1
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +42 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/core/audio-map.d.ts +1 -1
- package/dist/core/audio-map.d.ts.map +1 -1
- package/dist/core/audio-map.js +1 -1
- package/dist/core/audio-map.js.map +1 -1
- package/dist/core/content-loader.d.ts +1 -1
- package/dist/core/content-loader.d.ts.map +1 -1
- package/dist/core/content-loader.js +1 -1
- package/dist/core/content-loader.js.map +1 -1
- package/dist/core/speech-builder.d.ts +1 -1
- package/dist/core/speech-builder.d.ts.map +1 -1
- package/dist/core/speech-builder.js +4 -4
- package/dist/core/speech-builder.js.map +1 -1
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +3 -21
- package/dist/integration.js.map +1 -1
- package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
- package/dist/lib/latex-to-speech/index.js +5 -3
- package/dist/lib/latex-to-speech/index.js.map +1 -1
- package/dist/rehype/audio-words.d.ts.map +1 -1
- package/dist/rehype/audio-words.js +9 -8
- package/dist/rehype/audio-words.js.map +1 -1
- package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
- package/dist/rehype/rehype-math-speech.js +1 -1
- package/dist/rehype/rehype-math-speech.js.map +1 -1
- package/dist/rehype/remark-math-speech.d.ts.map +1 -1
- package/dist/rehype/remark-math-speech.js +2 -2
- package/dist/rehype/remark-math-speech.js.map +1 -1
- package/dist/styles/variables.css +27 -27
- package/dist/sync/orchestrator.d.ts +1 -1
- package/dist/sync/orchestrator.d.ts.map +1 -1
- package/dist/sync/orchestrator.js +3 -3
- package/dist/sync/orchestrator.js.map +1 -1
- package/package.json +1 -1
- package/src/api/client.ts +13 -24
- package/src/cli.ts +13 -61
- package/src/components/AudioPlayer.astro +1 -1
- package/src/config/index.ts +2 -0
- package/src/config/loader.ts +48 -0
- package/src/core/audio-map.ts +2 -2
- package/src/core/content-loader.ts +2 -2
- package/src/core/speech-builder.ts +10 -8
- package/src/integration.ts +4 -27
- package/src/lib/latex-to-speech/index.ts +17 -17
- package/src/rehype/audio-words.ts +22 -16
- package/src/rehype/rehype-math-speech.ts +6 -7
- package/src/rehype/remark-math-speech.ts +4 -4
- package/src/styles/variables.css +27 -27
- package/src/sync/orchestrator.ts +8 -14
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import type { VocaSyncUserConfig } from "./schema.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Load and execute a config file.
|
|
7
|
+
* Uses file:// URLs for proper ESM import resolution.
|
|
8
|
+
*/
|
|
9
|
+
async function loadConfigFile(filePath: string): Promise<VocaSyncUserConfig> {
|
|
10
|
+
try {
|
|
11
|
+
const fileUrl = `file://${filePath}`;
|
|
12
|
+
const module = await import(fileUrl);
|
|
13
|
+
return (module.default || module) as VocaSyncUserConfig;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw new Error(`Failed to load config from ${filePath}: ${error}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Discover and load a VocaSync configuration file.
|
|
21
|
+
*
|
|
22
|
+
* Searches for vocasync.config.{ts,mjs,js} in the current working directory,
|
|
23
|
+
* or loads from an explicit path if provided.
|
|
24
|
+
*
|
|
25
|
+
* @param configPath - Optional explicit path to config file
|
|
26
|
+
*/
|
|
27
|
+
export async function loadVocaSyncConfig(configPath?: string): Promise<VocaSyncUserConfig> {
|
|
28
|
+
const cwd = process.cwd();
|
|
29
|
+
|
|
30
|
+
// Try explicit config path first
|
|
31
|
+
if (configPath) {
|
|
32
|
+
const fullPath = resolve(cwd, configPath);
|
|
33
|
+
return loadConfigFile(fullPath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Try vocasync.config.ts / .mjs / .js
|
|
37
|
+
for (const ext of [".ts", ".mjs", ".js"]) {
|
|
38
|
+
const configFile = resolve(cwd, `vocasync.config${ext}`);
|
|
39
|
+
if (existsSync(configFile)) {
|
|
40
|
+
return await loadConfigFile(configFile);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new Error(
|
|
45
|
+
"No VocaSync configuration found.\n" +
|
|
46
|
+
"Create a vocasync.config.mjs file with your configuration."
|
|
47
|
+
);
|
|
48
|
+
}
|
package/src/core/audio-map.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readFile, writeFile
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AudioArtifact, AudioMap } from "../types/index.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Create an empty audio map structure
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile, readdir, stat } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
import type { ContentItem } from "../types/index.js";
|
|
2
|
+
import { basename, extname, join, relative } from "node:path";
|
|
4
3
|
import type { CollectionConfig } from "../config/index.js";
|
|
4
|
+
import type { ContentItem } from "../types/index.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Parse frontmatter from markdown content.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import remarkParse from "remark-parse";
|
|
1
|
+
import type { Code, Content, Emphasis, Heading, InlineCode, Root, Strong, Text } from "mdast";
|
|
3
2
|
import remarkMath from "remark-math";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import remarkParse from "remark-parse";
|
|
4
|
+
import { unified } from "unified";
|
|
6
5
|
import type { MathConfig } from "../config/index.js";
|
|
6
|
+
import type { ContentItem, SpeechDocument } from "../types/index.js";
|
|
7
7
|
import { computeHash } from "./hash-manager.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -15,7 +15,9 @@ interface LaTeXConverter {
|
|
|
15
15
|
|
|
16
16
|
// Cache for latex-to-speech results
|
|
17
17
|
const latexSpeechCache = new Map<string, Promise<string>>();
|
|
18
|
-
let latexToSpeech:
|
|
18
|
+
let latexToSpeech:
|
|
19
|
+
| ((exprs: string[], options?: Record<string, unknown>) => Promise<string[]>)
|
|
20
|
+
| null = null;
|
|
19
21
|
let latexToSpeechLoadAttempted = false;
|
|
20
22
|
let warnedLatexSpeechFailure = false;
|
|
21
23
|
|
|
@@ -41,7 +43,7 @@ async function createLatexConverter(config: MathConfig): Promise<LaTeXConverter
|
|
|
41
43
|
try {
|
|
42
44
|
const mod = await import("../lib/latex-to-speech/index.js");
|
|
43
45
|
latexToSpeech = mod.latexToSpeech || mod.default;
|
|
44
|
-
} catch
|
|
46
|
+
} catch {
|
|
45
47
|
console.warn(
|
|
46
48
|
"[vocasync] Math-to-speech initialization failed. Install optional dependencies:",
|
|
47
49
|
"\n npm install speech-rule-engine mathjax-full"
|
|
@@ -64,7 +66,7 @@ async function createLatexConverter(config: MathConfig): Promise<LaTeXConverter
|
|
|
64
66
|
async convert(latex: string, display: boolean): Promise<string> {
|
|
65
67
|
const trimmed = latex.trim();
|
|
66
68
|
if (!trimmed) return "";
|
|
67
|
-
|
|
69
|
+
|
|
68
70
|
const cacheKey = `${display}:${trimmed}`;
|
|
69
71
|
if (!latexSpeechCache.has(cacheKey)) {
|
|
70
72
|
const pending = (async () => {
|
|
@@ -284,7 +286,7 @@ export async function buildSpeechDocument(
|
|
|
284
286
|
const resolvedParts = await Promise.all(textParts);
|
|
285
287
|
|
|
286
288
|
// Clean up and normalize text
|
|
287
|
-
|
|
289
|
+
const text = resolvedParts
|
|
288
290
|
.join(" ")
|
|
289
291
|
.replace(/\s+/g, " ") // Normalize whitespace
|
|
290
292
|
.replace(/\n\s*\n/g, "\n\n") // Preserve paragraph breaks
|
package/src/integration.ts
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { validateConfig, type VocaSyncUserConfig } from "./config/index.js";
|
|
5
|
-
import { loadAudioMap } from "./core/audio-map.js";
|
|
2
|
+
import { type VocaSyncConfig, loadVocaSyncConfig, validateConfig } from "./config/index.js";
|
|
3
|
+
import { createEmptyAudioMap, loadAudioMap } from "./core/audio-map.js";
|
|
6
4
|
import type { AudioMap } from "./types/index.js";
|
|
7
5
|
|
|
8
6
|
// Cache for the loaded audio map
|
|
9
7
|
let audioMapCache: AudioMap | null = null;
|
|
10
8
|
|
|
11
|
-
/**
|
|
12
|
-
* Load configuration from vocasync.config.ts/js/mjs.
|
|
13
|
-
*/
|
|
14
|
-
async function loadVocaSyncConfig(): Promise<VocaSyncUserConfig> {
|
|
15
|
-
const cwd = process.cwd();
|
|
16
|
-
|
|
17
|
-
for (const ext of [".ts", ".mjs", ".js"]) {
|
|
18
|
-
const configFile = resolve(cwd, `vocasync.config${ext}`);
|
|
19
|
-
if (existsSync(configFile)) {
|
|
20
|
-
const fileUrl = `file://${configFile}`;
|
|
21
|
-
const module = await import(fileUrl);
|
|
22
|
-
return (module.default || module) as VocaSyncUserConfig;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
throw new Error(
|
|
27
|
-
"No VocaSync configuration found.\n" +
|
|
28
|
-
"Create a vocasync.config.mjs file with your configuration."
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
9
|
/**
|
|
33
10
|
* VocaSync Astro Integration.
|
|
34
11
|
*
|
|
@@ -58,7 +35,7 @@ export default function vocasyncIntegration(): AstroIntegration {
|
|
|
58
35
|
hooks: {
|
|
59
36
|
"astro:config:setup": async ({ updateConfig, logger }) => {
|
|
60
37
|
// Load config from vocasync.config.mjs
|
|
61
|
-
let config;
|
|
38
|
+
let config: VocaSyncConfig;
|
|
62
39
|
try {
|
|
63
40
|
const userConfig = await loadVocaSyncConfig();
|
|
64
41
|
config = validateConfig(userConfig);
|
|
@@ -77,7 +54,7 @@ export default function vocasyncIntegration(): AstroIntegration {
|
|
|
77
54
|
logger.warn(
|
|
78
55
|
`Audio map not found at ${config.output.audioMapPath}. Run 'npx vocasync sync' first.`
|
|
79
56
|
);
|
|
80
|
-
audioMapCache =
|
|
57
|
+
audioMapCache = createEmptyAudioMap();
|
|
81
58
|
}
|
|
82
59
|
|
|
83
60
|
// Add virtual module for audio-map access
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LaTeX to Speech conversion using speech-rule-engine and mathjax-full.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* This module provides the same interface as the vendored latex-to-speech package
|
|
5
5
|
* but works with the optional peer dependencies instead of bundling MathJax.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
// biome-ignore lint/suspicious/noExplicitAny: speech-rule-engine is an optional peer dep with no bundled types
|
|
8
9
|
let SRE: any = null;
|
|
9
10
|
let tex2mml: ((latex: string) => string) | null = null;
|
|
10
11
|
let engineSetup = false;
|
|
@@ -16,7 +17,7 @@ let initPromise: Promise<boolean> | null = null;
|
|
|
16
17
|
*/
|
|
17
18
|
async function init(): Promise<boolean> {
|
|
18
19
|
if (initPromise) return initPromise;
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
initPromise = (async () => {
|
|
21
22
|
try {
|
|
22
23
|
// Dynamically import speech-rule-engine
|
|
@@ -34,32 +35,34 @@ async function init(): Promise<boolean> {
|
|
|
34
35
|
const { HTMLDocument } = await import("mathjax-full/js/handlers/html/HTMLDocument.js");
|
|
35
36
|
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
36
37
|
const { liteAdaptor } = await import("mathjax-full/js/adaptors/liteAdaptor.js");
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const { SerializedMmlVisitor } = await import(
|
|
39
|
+
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
40
|
+
"mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js"
|
|
41
|
+
);
|
|
39
42
|
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
40
43
|
const { AllPackages } = await import("mathjax-full/js/input/tex/AllPackages.js");
|
|
41
44
|
|
|
42
45
|
// Filter out problematic packages
|
|
43
46
|
const packages = AllPackages.filter((p: string) => p !== "bussproofs");
|
|
44
|
-
|
|
47
|
+
|
|
45
48
|
// Create TeX input jax with all packages
|
|
46
49
|
const texInput = new TeX({ packages });
|
|
47
|
-
|
|
50
|
+
|
|
48
51
|
// Create a minimal HTML document for conversion
|
|
49
52
|
const adaptor = liteAdaptor();
|
|
50
53
|
const doc = new HTMLDocument("", adaptor, { InputJax: texInput });
|
|
51
|
-
|
|
54
|
+
|
|
52
55
|
// Create a visitor to serialize to MathML
|
|
53
56
|
const visitor = new SerializedMmlVisitor();
|
|
54
|
-
|
|
57
|
+
|
|
55
58
|
// Create the tex2mml function
|
|
56
59
|
tex2mml = (latex: string): string => {
|
|
57
60
|
const node = doc.convert(latex, { display: true });
|
|
58
61
|
return visitor.visitTree(node);
|
|
59
62
|
};
|
|
60
|
-
|
|
63
|
+
|
|
61
64
|
return true;
|
|
62
|
-
} catch
|
|
65
|
+
} catch {
|
|
63
66
|
console.warn("[vocasync] mathjax-full not installed. Math-to-speech disabled.");
|
|
64
67
|
console.warn("[vocasync] Install with: npm install mathjax-full speech-rule-engine");
|
|
65
68
|
return false;
|
|
@@ -82,17 +85,14 @@ export interface SREOptions {
|
|
|
82
85
|
|
|
83
86
|
/**
|
|
84
87
|
* Convert an array of LaTeX expressions to speech.
|
|
85
|
-
*
|
|
88
|
+
*
|
|
86
89
|
* @param exprs - Array of LaTeX expressions to convert
|
|
87
90
|
* @param options - SRE configuration options
|
|
88
91
|
* @returns Promise resolving to array of speech strings
|
|
89
92
|
*/
|
|
90
|
-
export async function latexToSpeech(
|
|
91
|
-
exprs: string[],
|
|
92
|
-
options: SREOptions = {}
|
|
93
|
-
): Promise<string[]> {
|
|
93
|
+
export async function latexToSpeech(exprs: string[], options: SREOptions = {}): Promise<string[]> {
|
|
94
94
|
const available = await init();
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
if (!available || !SRE || !tex2mml) {
|
|
97
97
|
// Return empty descriptions when dependencies not available
|
|
98
98
|
return exprs.map(() => "");
|
|
@@ -116,7 +116,7 @@ export async function latexToSpeech(
|
|
|
116
116
|
try {
|
|
117
117
|
const mml = tex2mml!(latex);
|
|
118
118
|
return SRE!.toSpeech(mml);
|
|
119
|
-
} catch
|
|
119
|
+
} catch {
|
|
120
120
|
console.warn(`[vocasync] Failed to convert LaTeX to speech: ${latex}`);
|
|
121
121
|
return "";
|
|
122
122
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Plugin } from "unified";
|
|
3
|
-
import { visitParents } from "unist-util-visit-parents";
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
4
2
|
import { readFileSync } from "node:fs";
|
|
5
3
|
import { resolve } from "node:path";
|
|
6
|
-
import {
|
|
4
|
+
import type { Element, Root, Text } from "hast";
|
|
5
|
+
import type { Plugin } from "unified";
|
|
6
|
+
import { visitParents } from "unist-util-visit-parents";
|
|
7
7
|
import type { AlignedWord, AudioMap } from "../types/index.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -62,7 +62,11 @@ function loadAudioMapSync(audioMapPath: string): AudioMap | null {
|
|
|
62
62
|
* @param slug - The content slug for caching
|
|
63
63
|
* @param publishableKey - Optional publishable key for authentication
|
|
64
64
|
*/
|
|
65
|
-
function fetchAlignmentSync(
|
|
65
|
+
function fetchAlignmentSync(
|
|
66
|
+
alignmentUrl: string,
|
|
67
|
+
slug: string,
|
|
68
|
+
publishableKey?: string
|
|
69
|
+
): AlignedWord[] | null {
|
|
66
70
|
// Check cache first
|
|
67
71
|
if (alignmentCache.has(slug)) {
|
|
68
72
|
return alignmentCache.get(slug) ?? null;
|
|
@@ -77,16 +81,16 @@ function fetchAlignmentSync(alignmentUrl: string, slug: string, publishableKey?:
|
|
|
77
81
|
fetchUrl = url.toString();
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
// Use
|
|
81
|
-
//
|
|
84
|
+
// Use execFileSync with curl to make a synchronous HTTP request
|
|
85
|
+
// execFileSync avoids shell invocation, preventing command injection
|
|
82
86
|
// Note: -L flag follows redirects (required for vocasync.io signed URLs)
|
|
83
|
-
const result =
|
|
87
|
+
const result = execFileSync("curl", ["-sL", fetchUrl], {
|
|
84
88
|
encoding: "utf-8",
|
|
85
89
|
timeout: 30000,
|
|
86
90
|
});
|
|
87
91
|
|
|
88
92
|
const data = JSON.parse(result);
|
|
89
|
-
|
|
93
|
+
|
|
90
94
|
// The alignment response contains a words array
|
|
91
95
|
const words = data.words as AlignedWord[] | undefined;
|
|
92
96
|
if (words && Array.isArray(words)) {
|
|
@@ -128,7 +132,7 @@ const rehypeAudioWords: Plugin<[RehypeAudioWordsOptions?], Root> = (options = {}
|
|
|
128
132
|
const {
|
|
129
133
|
audioMapPath = ".vocasync/audio-map.json",
|
|
130
134
|
classPrefix = "vocasync",
|
|
131
|
-
collectionName = "articles"
|
|
135
|
+
collectionName = "articles",
|
|
132
136
|
} = options;
|
|
133
137
|
|
|
134
138
|
return (tree, file) => {
|
|
@@ -140,20 +144,22 @@ const rehypeAudioWords: Plugin<[RehypeAudioWordsOptions?], Root> = (options = {}
|
|
|
140
144
|
|
|
141
145
|
// Resolve slug from file path
|
|
142
146
|
// Files are typically at paths like: /src/content/articles/hello-world.md
|
|
143
|
-
const filePath =
|
|
144
|
-
|
|
147
|
+
const filePath =
|
|
148
|
+
file.path ??
|
|
149
|
+
(Array.isArray(file.history) ? file.history[file.history.length - 1] : undefined);
|
|
150
|
+
|
|
145
151
|
if (!filePath) {
|
|
146
152
|
return; // No file path, skip processing
|
|
147
153
|
}
|
|
148
|
-
|
|
154
|
+
|
|
149
155
|
// Normalize path separators
|
|
150
156
|
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
151
|
-
|
|
157
|
+
|
|
152
158
|
// Try to extract slug from collection path
|
|
153
159
|
// Pattern: /src/content/{collectionName}/{slug}.md or .mdx
|
|
154
160
|
const collectionPattern = new RegExp(`/content/${collectionName}/([^/]+)\\.(md|mdx)$`);
|
|
155
161
|
const match = normalizedPath.match(collectionPattern);
|
|
156
|
-
|
|
162
|
+
|
|
157
163
|
let slug: string | undefined;
|
|
158
164
|
if (match) {
|
|
159
165
|
slug = match[1];
|
|
@@ -262,7 +268,7 @@ function processTextNode(
|
|
|
262
268
|
const wordPattern = /[\p{L}\p{N}'']+/gu;
|
|
263
269
|
let match: RegExpExecArray | null;
|
|
264
270
|
|
|
265
|
-
// biome-ignore lint/suspicious/noAssignInExpressions:
|
|
271
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: regex exec loop requires assignment in condition
|
|
266
272
|
while ((match = wordPattern.exec(text)) !== null) {
|
|
267
273
|
const word = match[0];
|
|
268
274
|
const start = match.index;
|
|
@@ -5,7 +5,9 @@ import type { MathSpeechEntry } from "./remark-math-speech.js";
|
|
|
5
5
|
|
|
6
6
|
const SR_SPEECH_CLASS = "vocasync-math-speech";
|
|
7
7
|
|
|
8
|
-
let latexToSpeech:
|
|
8
|
+
let latexToSpeech:
|
|
9
|
+
| ((exprs: string[], options?: Record<string, unknown>) => Promise<string[]>)
|
|
10
|
+
| null = null;
|
|
9
11
|
let latexToSpeechLoadAttempted = false;
|
|
10
12
|
|
|
11
13
|
const latexSpeechCache = new Map<string, Promise<string>>();
|
|
@@ -22,10 +24,7 @@ interface RehypeMathSpeechOptions {
|
|
|
22
24
|
/**
|
|
23
25
|
* Convert LaTeX to spoken text using speech-rule-engine and mathjax-full.
|
|
24
26
|
*/
|
|
25
|
-
async function speakLatex(
|
|
26
|
-
value: string,
|
|
27
|
-
style: string = "clearspeak"
|
|
28
|
-
): Promise<string> {
|
|
27
|
+
async function speakLatex(value: string, style = "clearspeak"): Promise<string> {
|
|
29
28
|
const trimmed = String(value ?? "").trim();
|
|
30
29
|
if (!trimmed) return "";
|
|
31
30
|
|
|
@@ -35,7 +34,7 @@ async function speakLatex(
|
|
|
35
34
|
try {
|
|
36
35
|
const mod = await import("../lib/latex-to-speech/index.js");
|
|
37
36
|
latexToSpeech = mod.latexToSpeech || mod.default;
|
|
38
|
-
} catch
|
|
37
|
+
} catch {
|
|
39
38
|
console.warn(
|
|
40
39
|
"[vocasync] Math-to-speech initialization failed. Install optional dependencies:",
|
|
41
40
|
"\n npm install speech-rule-engine mathjax-full"
|
|
@@ -82,7 +81,7 @@ function normalizeWhitespace(value = ""): string {
|
|
|
82
81
|
/**
|
|
83
82
|
* Rehype plugin that injects hidden spoken text next to math elements.
|
|
84
83
|
* This allows rehypeAudioWords to wrap the spoken words with timing data.
|
|
85
|
-
*
|
|
84
|
+
*
|
|
86
85
|
* Must run AFTER rehype-katex or rehype-mathjax, and BEFORE rehypeAudioWords.
|
|
87
86
|
*/
|
|
88
87
|
export default function rehypeMathSpeech(options: RehypeMathSpeechOptions = {}) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { visit } from "unist-util-visit";
|
|
2
1
|
import type { Root } from "mdast";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
3
|
import type { VFile } from "vfile";
|
|
4
4
|
|
|
5
5
|
export type MathSpeechEntry = {
|
|
@@ -15,9 +15,9 @@ export type MathSpeechEntry = {
|
|
|
15
15
|
export default function remarkMathSpeechCollector() {
|
|
16
16
|
return function transformer(tree: Root, file: VFile) {
|
|
17
17
|
const entries: MathSpeechEntry[] = [];
|
|
18
|
-
visit(tree, (node
|
|
19
|
-
if (node
|
|
20
|
-
const latex = String(node.value ?? "").trim();
|
|
18
|
+
visit(tree, (node) => {
|
|
19
|
+
if (node.type !== "math" && node.type !== "inlineMath") return;
|
|
20
|
+
const latex = String("value" in node ? (node.value ?? "") : "").trim();
|
|
21
21
|
if (!latex) return;
|
|
22
22
|
entries.push({
|
|
23
23
|
latex,
|
package/src/styles/variables.css
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* VocaSync AudioPlayer CSS Variables
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Import this file and override variables to customize the player appearance.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```css
|
|
8
8
|
* @import "@vocasync/astro/styles/variables.css";
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* :root {
|
|
11
11
|
* --vocasync-primary: #8b5cf6;
|
|
12
12
|
* }
|
|
@@ -17,73 +17,73 @@
|
|
|
17
17
|
/* ========================================
|
|
18
18
|
* COLOR PALETTE
|
|
19
19
|
* ======================================== */
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
/* Primary brand color - used for buttons, progress bar, active states */
|
|
22
22
|
--vocasync-primary: #3b82f6;
|
|
23
23
|
--vocasync-primary-hover: #2563eb;
|
|
24
24
|
--vocasync-primary-content: #ffffff;
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
/* Surface colors - backgrounds and cards */
|
|
27
27
|
--vocasync-surface: #f8fafc;
|
|
28
28
|
--vocasync-surface-elevated: #ffffff;
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
/* Border colors */
|
|
31
31
|
--vocasync-border: #e2e8f0;
|
|
32
32
|
--vocasync-border-focus: #3b82f6;
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
/* Text colors */
|
|
35
35
|
--vocasync-text: #1e293b;
|
|
36
36
|
--vocasync-text-muted: #64748b;
|
|
37
37
|
--vocasync-text-faint: #94a3b8;
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
/* ========================================
|
|
40
40
|
* WORD HIGHLIGHTING
|
|
41
41
|
* ======================================== */
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
/* Color for the currently spoken word */
|
|
44
44
|
--vocasync-highlight: #10b981;
|
|
45
45
|
--vocasync-highlight-text: #ffffff;
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
/* Opacity for active word background */
|
|
48
48
|
--vocasync-highlight-active-opacity: 0.25;
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
/* Opacity for trailing words (creates a "wake" effect) */
|
|
51
51
|
--vocasync-highlight-trail-opacity: 0.12;
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
/* ========================================
|
|
54
54
|
* SIZING & SPACING
|
|
55
55
|
* ======================================== */
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
/* Player dimensions */
|
|
58
58
|
--vocasync-player-radius: 0.75rem;
|
|
59
59
|
--vocasync-player-padding: 1rem;
|
|
60
60
|
--vocasync-player-gap: 0.75rem;
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
/* Button sizes */
|
|
63
63
|
--vocasync-button-size: 2.5rem;
|
|
64
64
|
--vocasync-button-radius: 9999px;
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
/* Slider/range input */
|
|
67
67
|
--vocasync-slider-height: 0.375rem;
|
|
68
68
|
--vocasync-slider-thumb-size: 1rem;
|
|
69
69
|
--vocasync-slider-radius: 9999px;
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
/* Mini player */
|
|
72
72
|
--vocasync-mini-height: 3.5rem;
|
|
73
73
|
--vocasync-mini-offset: 1rem;
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
/* ========================================
|
|
76
76
|
* SHADOWS & EFFECTS
|
|
77
77
|
* ======================================== */
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
--vocasync-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
|
|
80
80
|
--vocasync-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
|
|
81
81
|
--vocasync-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
/* ========================================
|
|
84
84
|
* TRANSITIONS
|
|
85
85
|
* ======================================== */
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
--vocasync-transition-fast: 150ms ease;
|
|
88
88
|
--vocasync-transition: 200ms ease;
|
|
89
89
|
--vocasync-transition-slow: 300ms ease;
|
|
@@ -98,20 +98,20 @@
|
|
|
98
98
|
--vocasync-primary: #60a5fa;
|
|
99
99
|
--vocasync-primary-hover: #3b82f6;
|
|
100
100
|
--vocasync-primary-content: #1e293b;
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
--vocasync-surface: #1e293b;
|
|
103
103
|
--vocasync-surface-elevated: #334155;
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
--vocasync-border: #475569;
|
|
106
106
|
--vocasync-border-focus: #60a5fa;
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
--vocasync-text: #f1f5f9;
|
|
109
109
|
--vocasync-text-muted: #94a3b8;
|
|
110
110
|
--vocasync-text-faint: #64748b;
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
--vocasync-highlight: #34d399;
|
|
113
113
|
--vocasync-highlight-text: #1e293b;
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
--vocasync-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
|
|
116
116
|
--vocasync-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
|
|
117
117
|
--vocasync-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
|
|
@@ -123,8 +123,8 @@
|
|
|
123
123
|
* ======================================== */
|
|
124
124
|
|
|
125
125
|
.vocasync-word {
|
|
126
|
-
transition: background-color var(--vocasync-transition-fast),
|
|
127
|
-
|
|
126
|
+
transition: background-color var(--vocasync-transition-fast), color
|
|
127
|
+
var(--vocasync-transition-fast);
|
|
128
128
|
border-radius: 0.125rem;
|
|
129
129
|
padding: 0 0.0625rem;
|
|
130
130
|
margin: 0 -0.0625rem;
|
package/src/sync/orchestrator.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { type VocaSyncClient, getStreamingUrls } from "../api/client.js";
|
|
1
2
|
import type { VocaSyncConfig } from "../config/index.js";
|
|
3
|
+
import { getAudioEntry, loadAudioMap, saveAudioMap, setAudioEntry } from "../core/audio-map.js";
|
|
4
|
+
import { loadContent } from "../core/content-loader.js";
|
|
5
|
+
import { hasChanged } from "../core/hash-manager.js";
|
|
6
|
+
import { buildSpeechDocument } from "../core/speech-builder.js";
|
|
2
7
|
import type {
|
|
3
|
-
ContentItem,
|
|
4
8
|
AudioArtifact,
|
|
5
9
|
AudioMap,
|
|
10
|
+
ContentItem,
|
|
6
11
|
SyncResult,
|
|
7
|
-
SyncSummary,
|
|
8
12
|
SyncStatus,
|
|
13
|
+
SyncSummary,
|
|
9
14
|
} from "../types/index.js";
|
|
10
|
-
import { loadContent } from "../core/content-loader.js";
|
|
11
|
-
import { buildSpeechDocument } from "../core/speech-builder.js";
|
|
12
|
-
import { loadAudioMap, saveAudioMap, getAudioEntry, setAudioEntry } from "../core/audio-map.js";
|
|
13
|
-
import { hasChanged } from "../core/hash-manager.js";
|
|
14
|
-
import { VocaSyncClient, getStreamingUrls } from "../api/client.js";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Options for the sync operation.
|
|
@@ -69,13 +69,7 @@ export async function sync(
|
|
|
69
69
|
|
|
70
70
|
// Process each item
|
|
71
71
|
for (const item of items) {
|
|
72
|
-
const result = await processItem(
|
|
73
|
-
item,
|
|
74
|
-
config,
|
|
75
|
-
client,
|
|
76
|
-
audioMap,
|
|
77
|
-
{ force, dryRun, onProgress }
|
|
78
|
-
);
|
|
72
|
+
const result = await processItem(item, config, client, audioMap, { force, dryRun, onProgress });
|
|
79
73
|
|
|
80
74
|
results.push(result);
|
|
81
75
|
|