@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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { validateConfig } from "./config/index.js";
|
|
4
|
+
import { loadAudioMap } from "./core/audio-map.js";
|
|
5
|
+
// Cache for the loaded audio map
|
|
6
|
+
let audioMapCache = null;
|
|
7
|
+
/**
|
|
8
|
+
* Load configuration from vocasync.config.ts/js/mjs.
|
|
9
|
+
*/
|
|
10
|
+
async function loadVocaSyncConfig() {
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
for (const ext of [".ts", ".mjs", ".js"]) {
|
|
13
|
+
const configFile = resolve(cwd, `vocasync.config${ext}`);
|
|
14
|
+
if (existsSync(configFile)) {
|
|
15
|
+
const fileUrl = `file://${configFile}`;
|
|
16
|
+
const module = await import(fileUrl);
|
|
17
|
+
return (module.default || module);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
throw new Error("No VocaSync configuration found.\n" +
|
|
21
|
+
"Create a vocasync.config.mjs file with your configuration.");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* VocaSync Astro Integration.
|
|
25
|
+
*
|
|
26
|
+
* Provides:
|
|
27
|
+
* - Virtual module `virtual:vocasync/audio-map` for accessing audio data
|
|
28
|
+
* - Automatic rehype plugin for word-level highlighting
|
|
29
|
+
* - Optional build-time sync command
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // astro.config.mjs
|
|
34
|
+
* import vocasync from "@vocasync/astro";
|
|
35
|
+
*
|
|
36
|
+
* export default defineConfig({
|
|
37
|
+
* integrations: [vocasync()],
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // vocasync.config.mjs
|
|
41
|
+
* export default {
|
|
42
|
+
* collection: { name: "blog", path: "./src/content/blog" },
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export default function vocasyncIntegration() {
|
|
47
|
+
return {
|
|
48
|
+
name: "@vocasync/astro",
|
|
49
|
+
hooks: {
|
|
50
|
+
"astro:config:setup": async ({ updateConfig, logger }) => {
|
|
51
|
+
// Load config from vocasync.config.mjs
|
|
52
|
+
let config;
|
|
53
|
+
try {
|
|
54
|
+
const userConfig = await loadVocaSyncConfig();
|
|
55
|
+
config = validateConfig(userConfig);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error(`Failed to load VocaSync config: ${error}`);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
logger.info("VocaSync integration loaded");
|
|
62
|
+
// Pre-load audio map for rehype plugin
|
|
63
|
+
try {
|
|
64
|
+
audioMapCache = await loadAudioMap(config.output.audioMapPath);
|
|
65
|
+
logger.info(`Loaded audio map with ${Object.keys(audioMapCache.entries).length} entries`);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
logger.warn(`Audio map not found at ${config.output.audioMapPath}. Run 'npx vocasync sync' first.`);
|
|
69
|
+
audioMapCache = { version: 1, updatedAt: "", entries: {} };
|
|
70
|
+
}
|
|
71
|
+
// Add virtual module for audio-map access
|
|
72
|
+
updateConfig({
|
|
73
|
+
vite: {
|
|
74
|
+
plugins: [
|
|
75
|
+
{
|
|
76
|
+
name: "vite-plugin-vocasync",
|
|
77
|
+
resolveId(id) {
|
|
78
|
+
if (id === "virtual:vocasync/audio-map") {
|
|
79
|
+
return "\0virtual:vocasync/audio-map";
|
|
80
|
+
}
|
|
81
|
+
if (id === "virtual:vocasync/config") {
|
|
82
|
+
return "\0virtual:vocasync/config";
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
},
|
|
86
|
+
async load(id) {
|
|
87
|
+
if (id === "\0virtual:vocasync/audio-map") {
|
|
88
|
+
// Return cached audio map
|
|
89
|
+
return `export default ${JSON.stringify(audioMapCache)};`;
|
|
90
|
+
}
|
|
91
|
+
if (id === "\0virtual:vocasync/config") {
|
|
92
|
+
// Export the validated config
|
|
93
|
+
return `export default ${JSON.stringify(config)};`;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
"astro:build:done": ({ logger }) => {
|
|
103
|
+
logger.info("VocaSync build complete");
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Also export as named export
|
|
109
|
+
export { vocasyncIntegration as vocasync };
|
|
110
|
+
//# sourceMappingURL=integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.js","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAA2B,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,iCAAiC;AACjC,IAAI,aAAa,GAAo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AAyB,CAAC,CAAC;YACzC,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,8BAA8B;AAC9B,OAAO,EAAE,mBAAmB,IAAI,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LaTeX to Speech conversion using speech-rule-engine and mathjax-full.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the same interface as the vendored latex-to-speech package
|
|
5
|
+
* but works with the optional peer dependencies instead of bundling MathJax.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Options for speech-rule-engine
|
|
9
|
+
*/
|
|
10
|
+
export interface SREOptions {
|
|
11
|
+
locale?: string;
|
|
12
|
+
domain?: string;
|
|
13
|
+
style?: string;
|
|
14
|
+
modality?: string;
|
|
15
|
+
speech?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert an array of LaTeX expressions to speech.
|
|
19
|
+
*
|
|
20
|
+
* @param exprs - Array of LaTeX expressions to convert
|
|
21
|
+
* @param options - SRE configuration options
|
|
22
|
+
* @returns Promise resolving to array of speech strings
|
|
23
|
+
*/
|
|
24
|
+
export declare function latexToSpeech(exprs: string[], options?: SREOptions): Promise<string[]>;
|
|
25
|
+
export default latexToSpeech;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/latex-to-speech/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC,CA+BnB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LaTeX to Speech conversion using speech-rule-engine and mathjax-full.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the same interface as the vendored latex-to-speech package
|
|
5
|
+
* but works with the optional peer dependencies instead of bundling MathJax.
|
|
6
|
+
*/
|
|
7
|
+
let SRE = null;
|
|
8
|
+
let tex2mml = null;
|
|
9
|
+
let engineSetup = false;
|
|
10
|
+
let initPromise = null;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the speech-rule-engine and MathJax tex2mml converter.
|
|
13
|
+
* Returns true if successful, false if dependencies are not available.
|
|
14
|
+
*/
|
|
15
|
+
async function init() {
|
|
16
|
+
if (initPromise)
|
|
17
|
+
return initPromise;
|
|
18
|
+
initPromise = (async () => {
|
|
19
|
+
try {
|
|
20
|
+
// Dynamically import speech-rule-engine
|
|
21
|
+
SRE = await import("speech-rule-engine");
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
console.warn("[vocasync] speech-rule-engine not installed. Math-to-speech disabled.");
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
// Dynamically import mathjax-full components for tex2mml
|
|
29
|
+
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
30
|
+
const { TeX } = await import("mathjax-full/js/input/tex.js");
|
|
31
|
+
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
32
|
+
const { HTMLDocument } = await import("mathjax-full/js/handlers/html/HTMLDocument.js");
|
|
33
|
+
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
34
|
+
const { liteAdaptor } = await import("mathjax-full/js/adaptors/liteAdaptor.js");
|
|
35
|
+
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
36
|
+
const { SerializedMmlVisitor } = await import("mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js");
|
|
37
|
+
// @ts-expect-error - mathjax-full is an optional peer dependency
|
|
38
|
+
const { AllPackages } = await import("mathjax-full/js/input/tex/AllPackages.js");
|
|
39
|
+
// Filter out problematic packages
|
|
40
|
+
const packages = AllPackages.filter((p) => p !== "bussproofs");
|
|
41
|
+
// Create TeX input jax with all packages
|
|
42
|
+
const texInput = new TeX({ packages });
|
|
43
|
+
// Create a minimal HTML document for conversion
|
|
44
|
+
const adaptor = liteAdaptor();
|
|
45
|
+
const doc = new HTMLDocument("", adaptor, { InputJax: texInput });
|
|
46
|
+
// Create a visitor to serialize to MathML
|
|
47
|
+
const visitor = new SerializedMmlVisitor();
|
|
48
|
+
// Create the tex2mml function
|
|
49
|
+
tex2mml = (latex) => {
|
|
50
|
+
const node = doc.convert(latex, { display: true });
|
|
51
|
+
return visitor.visitTree(node);
|
|
52
|
+
};
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.warn("[vocasync] mathjax-full not installed. Math-to-speech disabled.");
|
|
57
|
+
console.warn("[vocasync] Install with: npm install mathjax-full speech-rule-engine");
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
return initPromise;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Convert an array of LaTeX expressions to speech.
|
|
65
|
+
*
|
|
66
|
+
* @param exprs - Array of LaTeX expressions to convert
|
|
67
|
+
* @param options - SRE configuration options
|
|
68
|
+
* @returns Promise resolving to array of speech strings
|
|
69
|
+
*/
|
|
70
|
+
export async function latexToSpeech(exprs, options = {}) {
|
|
71
|
+
const available = await init();
|
|
72
|
+
if (!available || !SRE || !tex2mml) {
|
|
73
|
+
// Return empty descriptions when dependencies not available
|
|
74
|
+
return exprs.map(() => "");
|
|
75
|
+
}
|
|
76
|
+
// Set up the engine if not already done
|
|
77
|
+
if (!engineSetup) {
|
|
78
|
+
await SRE.setupEngine({
|
|
79
|
+
locale: options.locale || "en",
|
|
80
|
+
domain: options.domain || "mathspeak",
|
|
81
|
+
style: options.style || "default",
|
|
82
|
+
modality: options.modality || "speech",
|
|
83
|
+
speech: options.speech || "deep",
|
|
84
|
+
...options,
|
|
85
|
+
});
|
|
86
|
+
engineSetup = true;
|
|
87
|
+
}
|
|
88
|
+
// Convert each expression
|
|
89
|
+
return exprs.map((latex) => {
|
|
90
|
+
try {
|
|
91
|
+
const mml = tex2mml(latex);
|
|
92
|
+
return SRE.toSpeech(mml);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
console.warn(`[vocasync] Failed to convert LaTeX to speech: ${latex}`);
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
export default latexToSpeech;
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/latex-to-speech/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,IAAI,GAAG,GAAQ,IAAI,CAAC;AACpB,IAAI,OAAO,GAAuC,IAAI,CAAC;AACvD,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,IAAI,WAAW,GAA4B,IAAI,CAAC;AAEhD;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IAEpC,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;QACxB,IAAI,CAAC;YACH,wCAAwC;YACxC,GAAG,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,IAAI,CAAC,uEAAuE,CAAC,CAAC;YACtF,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC;YACH,yDAAyD;YACzD,iEAAiE;YACjE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,MAAM,CAAC,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,50 @@
|
|
|
1
|
+
import type { Root } from "hast";
|
|
2
|
+
import type { Plugin } from "unified";
|
|
3
|
+
/**
|
|
4
|
+
* Options for the rehype audio words plugin.
|
|
5
|
+
*/
|
|
6
|
+
export interface RehypeAudioWordsOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Path to the audio map JSON file.
|
|
9
|
+
* Can be absolute or relative to the project root.
|
|
10
|
+
* @default ".vocasync/audio-map.json"
|
|
11
|
+
*/
|
|
12
|
+
audioMapPath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* CSS class prefix for generated elements.
|
|
15
|
+
* @default "vocasync"
|
|
16
|
+
*/
|
|
17
|
+
classPrefix?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The name of the content collection folder to extract slugs from.
|
|
20
|
+
* @default "articles"
|
|
21
|
+
*/
|
|
22
|
+
collectionName?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Rehype plugin that wraps words with timing spans for audio sync.
|
|
26
|
+
*
|
|
27
|
+
* For each text node in the document, this plugin:
|
|
28
|
+
* 1. Tokenizes the text into words
|
|
29
|
+
* 2. Matches words against alignment data
|
|
30
|
+
* 3. Wraps matched words in <span> elements with data-start and data-end attributes
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // astro.config.mjs
|
|
35
|
+
* import { defineConfig } from "astro/config";
|
|
36
|
+
* import { rehypeAudioWords } from "@vocasync/astro/rehype";
|
|
37
|
+
*
|
|
38
|
+
* export default defineConfig({
|
|
39
|
+
* markdown: {
|
|
40
|
+
* rehypePlugins: [
|
|
41
|
+
* [rehypeAudioWords, { collectionName: "articles" }]
|
|
42
|
+
* ]
|
|
43
|
+
* }
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare const rehypeAudioWords: Plugin<[RehypeAudioWordsOptions?], Root>;
|
|
48
|
+
export default rehypeAudioWords;
|
|
49
|
+
export { rehypeAudioWords };
|
|
50
|
+
//# sourceMappingURL=audio-words.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio-words.d.ts","sourceRoot":"","sources":["../../src/rehype/audio-words.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAiB,MAAM,MAAM,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOtC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA8DD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,QAAA,MAAM,gBAAgB,EAAE,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,IAAI,CA0F9D,CAAC;AA0IF,eAAe,gBAAgB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { visitParents } from "unist-util-visit-parents";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
// Cache the loaded audio map to avoid re-reading on every file
|
|
6
|
+
let audioMapCache = null;
|
|
7
|
+
let audioMapCachePath = null;
|
|
8
|
+
// Cache for fetched alignment data per slug
|
|
9
|
+
const alignmentCache = new Map();
|
|
10
|
+
function loadAudioMapSync(audioMapPath) {
|
|
11
|
+
// Use cache if same path
|
|
12
|
+
if (audioMapCache && audioMapCachePath === audioMapPath) {
|
|
13
|
+
return audioMapCache;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const absolutePath = resolve(process.cwd(), audioMapPath);
|
|
17
|
+
const content = readFileSync(absolutePath, "utf-8");
|
|
18
|
+
audioMapCache = JSON.parse(content);
|
|
19
|
+
audioMapCachePath = audioMapPath;
|
|
20
|
+
return audioMapCache;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// File doesn't exist or is invalid - return null
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Fetch alignment data from URL (synchronously using a worker thread approach).
|
|
29
|
+
* Since rehype plugins must be synchronous, we use a sync HTTP request.
|
|
30
|
+
*/
|
|
31
|
+
function fetchAlignmentSync(alignmentUrl, slug) {
|
|
32
|
+
// Check cache first
|
|
33
|
+
if (alignmentCache.has(slug)) {
|
|
34
|
+
return alignmentCache.get(slug) ?? null;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
// Use sync-fetch or execSync to make a synchronous HTTP request
|
|
38
|
+
// We'll use child_process.execSync with curl as a simple solution
|
|
39
|
+
// Note: -L flag follows redirects (required for vocasync.io signed URLs)
|
|
40
|
+
const result = execSync(`curl -sL "${alignmentUrl}"`, {
|
|
41
|
+
encoding: "utf-8",
|
|
42
|
+
timeout: 30000,
|
|
43
|
+
});
|
|
44
|
+
const data = JSON.parse(result);
|
|
45
|
+
// The alignment response contains a words array
|
|
46
|
+
const words = data.words;
|
|
47
|
+
if (words && Array.isArray(words)) {
|
|
48
|
+
alignmentCache.set(slug, words);
|
|
49
|
+
return words;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Failed to fetch - return null
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Rehype plugin that wraps words with timing spans for audio sync.
|
|
60
|
+
*
|
|
61
|
+
* For each text node in the document, this plugin:
|
|
62
|
+
* 1. Tokenizes the text into words
|
|
63
|
+
* 2. Matches words against alignment data
|
|
64
|
+
* 3. Wraps matched words in <span> elements with data-start and data-end attributes
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // astro.config.mjs
|
|
69
|
+
* import { defineConfig } from "astro/config";
|
|
70
|
+
* import { rehypeAudioWords } from "@vocasync/astro/rehype";
|
|
71
|
+
*
|
|
72
|
+
* export default defineConfig({
|
|
73
|
+
* markdown: {
|
|
74
|
+
* rehypePlugins: [
|
|
75
|
+
* [rehypeAudioWords, { collectionName: "articles" }]
|
|
76
|
+
* ]
|
|
77
|
+
* }
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
const rehypeAudioWords = (options = {}) => {
|
|
82
|
+
const { audioMapPath = ".vocasync/audio-map.json", classPrefix = "vocasync", collectionName = "articles" } = options;
|
|
83
|
+
return (tree, file) => {
|
|
84
|
+
// Load audio map (cached after first load)
|
|
85
|
+
const audioMap = loadAudioMapSync(audioMapPath);
|
|
86
|
+
if (!audioMap) {
|
|
87
|
+
return; // No audio map available, skip processing
|
|
88
|
+
}
|
|
89
|
+
// Resolve slug from file path
|
|
90
|
+
// Files are typically at paths like: /src/content/articles/hello-world.md
|
|
91
|
+
const filePath = file.path ?? (Array.isArray(file.history) ? file.history[file.history.length - 1] : undefined);
|
|
92
|
+
if (!filePath) {
|
|
93
|
+
return; // No file path, skip processing
|
|
94
|
+
}
|
|
95
|
+
// Normalize path separators
|
|
96
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
97
|
+
// Try to extract slug from collection path
|
|
98
|
+
// Pattern: /src/content/{collectionName}/{slug}.md or .mdx
|
|
99
|
+
const collectionPattern = new RegExp(`/content/${collectionName}/([^/]+)\\.(md|mdx)$`);
|
|
100
|
+
const match = normalizedPath.match(collectionPattern);
|
|
101
|
+
let slug;
|
|
102
|
+
if (match) {
|
|
103
|
+
slug = match[1];
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// Fallback: just get the filename without extension
|
|
107
|
+
const filenameMatch = normalizedPath.match(/\/([^/]+)\.(md|mdx)$/);
|
|
108
|
+
if (filenameMatch) {
|
|
109
|
+
slug = filenameMatch[1];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!slug) {
|
|
113
|
+
return; // No slug, skip processing
|
|
114
|
+
}
|
|
115
|
+
// Get alignment URL for this slug from audio map
|
|
116
|
+
const entry = audioMap.entries[slug];
|
|
117
|
+
if (!entry?.alignmentUrl) {
|
|
118
|
+
return; // No alignment URL, skip
|
|
119
|
+
}
|
|
120
|
+
// Fetch alignment words from URL
|
|
121
|
+
const words = fetchAlignmentSync(entry.alignmentUrl, slug);
|
|
122
|
+
if (!words || words.length === 0) {
|
|
123
|
+
return; // No alignment data, skip
|
|
124
|
+
}
|
|
125
|
+
// Track word index as we process text nodes
|
|
126
|
+
let wordIndex = 0;
|
|
127
|
+
// Process all text nodes in the document
|
|
128
|
+
visitParents(tree, "text", (node, ancestors) => {
|
|
129
|
+
const textNode = node;
|
|
130
|
+
const parent = ancestors[ancestors.length - 1];
|
|
131
|
+
// Skip text in code blocks, scripts, styles
|
|
132
|
+
if (isInNonTextualElement(ancestors)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Tokenize and match words
|
|
136
|
+
const result = processTextNode(textNode.value, words, wordIndex, classPrefix);
|
|
137
|
+
if (result.nodes.length === 0 || result.nodes.length === 1) {
|
|
138
|
+
return; // No changes needed
|
|
139
|
+
}
|
|
140
|
+
// Update word index
|
|
141
|
+
wordIndex = result.nextWordIndex;
|
|
142
|
+
// Replace text node with annotated nodes
|
|
143
|
+
const parentChildren = parent.children;
|
|
144
|
+
const nodeIndex = parentChildren.indexOf(node);
|
|
145
|
+
if (nodeIndex !== -1) {
|
|
146
|
+
parentChildren.splice(nodeIndex, 1, ...result.nodes);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Check if ancestors include non-textual elements (code, script, style, KaTeX).
|
|
153
|
+
*/
|
|
154
|
+
function isInNonTextualElement(ancestors) {
|
|
155
|
+
const nonTextualTags = new Set(["code", "pre", "script", "style", "svg", "math"]);
|
|
156
|
+
const nonTextualClasses = new Set(["katex", "katex-mathml", "katex-html", "mjx-container"]);
|
|
157
|
+
for (const ancestor of ancestors) {
|
|
158
|
+
if ("tagName" in ancestor && nonTextualTags.has(ancestor.tagName)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
// Check for KaTeX/MathJax class names
|
|
162
|
+
if ("properties" in ancestor && ancestor.properties?.className) {
|
|
163
|
+
const classes = Array.isArray(ancestor.properties.className)
|
|
164
|
+
? ancestor.properties.className
|
|
165
|
+
: [ancestor.properties.className];
|
|
166
|
+
for (const cls of classes) {
|
|
167
|
+
if (typeof cls === "string" && nonTextualClasses.has(cls)) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Process a text node and create annotated nodes.
|
|
177
|
+
*/
|
|
178
|
+
function processTextNode(text, words, startIndex, classPrefix) {
|
|
179
|
+
const nodes = [];
|
|
180
|
+
let wordIndex = startIndex;
|
|
181
|
+
let lastEnd = 0;
|
|
182
|
+
// Regex to match words (similar to word boundaries)
|
|
183
|
+
const wordPattern = /[\p{L}\p{N}'']+/gu;
|
|
184
|
+
let match;
|
|
185
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
|
|
186
|
+
while ((match = wordPattern.exec(text)) !== null) {
|
|
187
|
+
const word = match[0];
|
|
188
|
+
const start = match.index;
|
|
189
|
+
// Add text before this word
|
|
190
|
+
if (start > lastEnd) {
|
|
191
|
+
nodes.push({
|
|
192
|
+
type: "text",
|
|
193
|
+
value: text.slice(lastEnd, start),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// Try to match with alignment data - look ahead if needed
|
|
197
|
+
const normalizedWord = normalizeWord(word);
|
|
198
|
+
let matchedIndex = -1;
|
|
199
|
+
let matchedAligned = null;
|
|
200
|
+
// Search forward from current index to find matching word
|
|
201
|
+
// Look ahead up to 10 words to handle minor ordering differences
|
|
202
|
+
const maxLookahead = 10;
|
|
203
|
+
for (let i = wordIndex; i < Math.min(wordIndex + maxLookahead, words.length); i++) {
|
|
204
|
+
const candidate = words[i];
|
|
205
|
+
if (normalizeWord(candidate.word) === normalizedWord) {
|
|
206
|
+
matchedIndex = i;
|
|
207
|
+
matchedAligned = candidate;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (matchedAligned && matchedIndex !== -1) {
|
|
212
|
+
// Create annotated span
|
|
213
|
+
nodes.push({
|
|
214
|
+
type: "element",
|
|
215
|
+
tagName: "span",
|
|
216
|
+
properties: {
|
|
217
|
+
className: [`${classPrefix}-word`],
|
|
218
|
+
"data-word-index": matchedIndex,
|
|
219
|
+
"data-start": matchedAligned.start.toFixed(3),
|
|
220
|
+
"data-end": matchedAligned.end.toFixed(3),
|
|
221
|
+
},
|
|
222
|
+
children: [{ type: "text", value: word }],
|
|
223
|
+
});
|
|
224
|
+
wordIndex = matchedIndex + 1;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// No match, just add as text
|
|
228
|
+
nodes.push({
|
|
229
|
+
type: "text",
|
|
230
|
+
value: word,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
lastEnd = start + word.length;
|
|
234
|
+
}
|
|
235
|
+
// Add remaining text
|
|
236
|
+
if (lastEnd < text.length) {
|
|
237
|
+
nodes.push({
|
|
238
|
+
type: "text",
|
|
239
|
+
value: text.slice(lastEnd),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
// Merge adjacent text nodes
|
|
243
|
+
const merged = [];
|
|
244
|
+
for (const node of nodes) {
|
|
245
|
+
const last = merged[merged.length - 1];
|
|
246
|
+
if (node.type === "text" && last?.type === "text") {
|
|
247
|
+
last.value += node.value;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
merged.push(node);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
nodes: merged,
|
|
255
|
+
nextWordIndex: wordIndex,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Normalize a word for comparison (lowercase, remove punctuation).
|
|
260
|
+
*/
|
|
261
|
+
function normalizeWord(word) {
|
|
262
|
+
return word
|
|
263
|
+
.toLowerCase()
|
|
264
|
+
.replace(/[^\p{L}\p{N}]/gu, "")
|
|
265
|
+
.trim();
|
|
266
|
+
}
|
|
267
|
+
export default rehypeAudioWords;
|
|
268
|
+
export { rehypeAudioWords };
|
|
269
|
+
//# sourceMappingURL=audio-words.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio-words.js","sourceRoot":"","sources":["../../src/rehype/audio-words.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA2B9C,+DAA+D;AAC/D,IAAI,aAAa,GAAoB,IAAI,CAAC;AAC1C,IAAI,iBAAiB,GAAkB,IAAI,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,cAAc,GAA+B,IAAI,GAAG,EAAE,CAAC;AAE7D,SAAS,gBAAgB,CAAC,YAAoB;IAC5C,yBAAyB;IACzB,IAAI,aAAa,IAAI,iBAAiB,KAAK,YAAY,EAAE,CAAC;QACxD,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACpD,aAAa,GAAG,IAA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C;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,SAAS;KACzB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI;SACR,WAAW,EAAE;SACb,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,eAAe,gBAAgB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default, rehypeAudioWords } from "./audio-words.js";
|
|
2
|
+
export type { RehypeAudioWordsOptions } from "./audio-words.js";
|
|
3
|
+
export { default as rehypeMathSpeech } from "./rehype-math-speech.js";
|
|
4
|
+
export { default as remarkMathSpeech } from "./remark-math-speech.js";
|
|
5
|
+
export type { MathSpeechEntry } from "./remark-math-speech.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rehype/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rehype/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Root } from "hast";
|
|
2
|
+
import type { VFile } from "vfile";
|
|
3
|
+
interface RehypeMathSpeechOptions {
|
|
4
|
+
/**
|
|
5
|
+
* SRE domain style for math-to-speech conversion
|
|
6
|
+
* @default "clearspeak"
|
|
7
|
+
*/
|
|
8
|
+
style?: "clearspeak" | "mathspeak";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Rehype plugin that injects hidden spoken text next to math elements.
|
|
12
|
+
* This allows rehypeAudioWords to wrap the spoken words with timing data.
|
|
13
|
+
*
|
|
14
|
+
* Must run AFTER rehype-katex or rehype-mathjax, and BEFORE rehypeAudioWords.
|
|
15
|
+
*/
|
|
16
|
+
export default function rehypeMathSpeech(options?: RehypeMathSpeechOptions): (tree: Root, file: VFile) => Promise<void>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=rehype-math-speech.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-math-speech.d.ts","sourceRoot":"","sources":["../../src/rehype/rehype-math-speech.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,IAAI,EAAE,MAAM,MAAM,CAAC;AAElD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAWnC,UAAU,uBAAuB;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CACpC;AA8DD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,IAG1C,MAAM,IAAI,EAAE,MAAM,KAAK,mBAsD1D"}
|