@vocasync/astro 0.1.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -41
- package/dist/api/client.d.ts +63 -50
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +132 -145
- package/dist/api/client.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/components/AudioPlayer.astro +136 -137
- package/dist/config/schema.d.ts +21 -20
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +15 -4
- package/dist/config/schema.js.map +1 -1
- package/dist/core/audio-map.js +1 -1
- package/dist/core/speech-builder.d.ts +10 -7
- package/dist/core/speech-builder.d.ts.map +1 -1
- package/dist/core/speech-builder.js +73 -168
- package/dist/core/speech-builder.js.map +1 -1
- package/dist/core/spoken-form.d.ts +52 -0
- package/dist/core/spoken-form.d.ts.map +1 -0
- package/dist/core/spoken-form.js +279 -0
- package/dist/core/spoken-form.js.map +1 -0
- package/dist/lib/latex-to-speech/index.d.ts +9 -2
- package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
- package/dist/lib/latex-to-speech/index.js +20 -22
- package/dist/lib/latex-to-speech/index.js.map +1 -1
- package/dist/lib/latex-to-speech/speak.d.ts +13 -0
- package/dist/lib/latex-to-speech/speak.d.ts.map +1 -0
- package/dist/lib/latex-to-speech/speak.js +47 -0
- package/dist/lib/latex-to-speech/speak.js.map +1 -0
- package/dist/rehype/audio-words.d.ts +14 -24
- package/dist/rehype/audio-words.d.ts.map +1 -1
- package/dist/rehype/audio-words.js +131 -252
- package/dist/rehype/audio-words.js.map +1 -1
- package/dist/rehype/index.d.ts +1 -2
- package/dist/rehype/index.d.ts.map +1 -1
- package/dist/rehype/index.js +0 -1
- package/dist/rehype/index.js.map +1 -1
- package/dist/rehype/rehype-math-speech.d.ts +26 -10
- package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
- package/dist/rehype/rehype-math-speech.js +59 -92
- package/dist/rehype/rehype-math-speech.js.map +1 -1
- package/dist/rehype/shared.d.ts +9 -0
- package/dist/rehype/shared.d.ts.map +1 -0
- package/dist/rehype/shared.js +31 -0
- package/dist/rehype/shared.js.map +1 -0
- package/dist/sync/orchestrator.d.ts +4 -22
- package/dist/sync/orchestrator.d.ts.map +1 -1
- package/dist/sync/orchestrator.js +123 -123
- package/dist/sync/orchestrator.js.map +1 -1
- package/dist/types/index.d.ts +82 -46
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +14 -11
- package/src/api/client.ts +175 -190
- package/src/api/index.ts +8 -1
- package/src/cli.ts +7 -14
- package/src/components/AudioPlayer.astro +136 -137
- package/src/config/schema.ts +15 -4
- package/src/core/audio-map.ts +1 -1
- package/src/core/speech-builder.ts +75 -192
- package/src/core/spoken-form.ts +298 -0
- package/src/lib/latex-to-speech/index.ts +32 -22
- package/src/lib/latex-to-speech/speak.ts +55 -0
- package/src/rehype/audio-words.ts +145 -307
- package/src/rehype/index.ts +1 -2
- package/src/rehype/rehype-math-speech.ts +64 -117
- package/src/rehype/shared.ts +36 -0
- package/src/sync/orchestrator.ts +150 -157
- package/src/types/index.ts +85 -47
- package/src/types/modules.d.ts +5 -2
- package/dist/rehype/remark-math-speech.d.ts +0 -13
- package/dist/rehype/remark-math-speech.d.ts.map +0 -1
- package/dist/rehype/remark-math-speech.js +0 -26
- package/dist/rehype/remark-math-speech.js.map +0 -1
- package/src/rehype/remark-math-speech.ts +0 -31
|
@@ -1,206 +1,115 @@
|
|
|
1
1
|
import remarkMath from "remark-math";
|
|
2
2
|
import remarkParse from "remark-parse";
|
|
3
3
|
import { unified } from "unified";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const latexSpeechCache = new Map();
|
|
7
|
-
let latexToSpeech = null;
|
|
8
|
-
let latexToSpeechLoadAttempted = false;
|
|
9
|
-
let warnedLatexSpeechFailure = false;
|
|
10
|
-
/**
|
|
11
|
-
* Normalize whitespace in text.
|
|
12
|
-
*/
|
|
13
|
-
function normalizeWhitespace(value = "") {
|
|
14
|
-
return value.replace(/\r/g, "").replace(/\s+/g, " ").trim();
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Create a lazy-loaded LaTeX converter using our internal latex-to-speech module.
|
|
18
|
-
* This uses speech-rule-engine and mathjax-full as optional peer dependencies.
|
|
19
|
-
*/
|
|
20
|
-
async function createLatexConverter(config) {
|
|
21
|
-
if (!config.enabled) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
// Lazy load our internal latex-to-speech module
|
|
25
|
-
if (!latexToSpeechLoadAttempted) {
|
|
26
|
-
latexToSpeechLoadAttempted = true;
|
|
27
|
-
try {
|
|
28
|
-
const mod = await import("../lib/latex-to-speech/index.js");
|
|
29
|
-
latexToSpeech = mod.latexToSpeech || mod.default;
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
console.warn("[vocasync] Math-to-speech initialization failed. Install optional dependencies:", "\n npm install speech-rule-engine mathjax-full");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (!latexToSpeech) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const options = {
|
|
39
|
-
domain: config.style || "clearspeak",
|
|
40
|
-
style: "default",
|
|
41
|
-
locale: "en",
|
|
42
|
-
modality: "speech",
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
async convert(latex, display) {
|
|
46
|
-
const trimmed = latex.trim();
|
|
47
|
-
if (!trimmed)
|
|
48
|
-
return "";
|
|
49
|
-
const cacheKey = `${display}:${trimmed}`;
|
|
50
|
-
if (!latexSpeechCache.has(cacheKey)) {
|
|
51
|
-
const pending = (async () => {
|
|
52
|
-
try {
|
|
53
|
-
const result = await latexToSpeech([trimmed], options);
|
|
54
|
-
const spoken = Array.isArray(result) ? result[0] : String(result ?? "");
|
|
55
|
-
return normalizeWhitespace(spoken);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
if (!warnedLatexSpeechFailure) {
|
|
59
|
-
console.warn("[vocasync] Failed to convert LaTeX to speech:", error instanceof Error ? error.message : error);
|
|
60
|
-
warnedLatexSpeechFailure = true;
|
|
61
|
-
}
|
|
62
|
-
return normalizeWhitespace(trimmed);
|
|
63
|
-
}
|
|
64
|
-
})();
|
|
65
|
-
latexSpeechCache.set(cacheKey, pending);
|
|
66
|
-
}
|
|
67
|
-
return latexSpeechCache.get(cacheKey);
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
4
|
+
import { speakLatex } from "../lib/latex-to-speech/speak.js";
|
|
5
|
+
import { buildSpeechtextPair } from "./spoken-form.js";
|
|
71
6
|
/**
|
|
72
7
|
* Build a speech document from markdown content.
|
|
73
|
-
* Converts markdown to plain text suitable for TTS synthesis.
|
|
74
8
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
9
|
+
* Produces plain text from the SAME visible tokens the rehype word-wrapper
|
|
10
|
+
* sees — no phantom tokens (no "Quote:", "Image:", "[Code in X]", inline
|
|
11
|
+
* code), and code blocks / images are skipped exactly as rehype skips
|
|
12
|
+
* `pre`/`code`/`img`. This keeps the alignment transcript
|
|
13
|
+
* (`normalisedSpeechtext`) token-for-token with the rehype `data-i` stream.
|
|
14
|
+
*
|
|
15
|
+
* Headings keep a leading "# " marker so the synthesis backend chunks at
|
|
16
|
+
* heading boundaries; `stripForAlignment` removes it, so it never becomes an
|
|
17
|
+
* alignment token. Math expressions contribute their `speakLatex` output at
|
|
18
|
+
* their reading position (the same string the rehype math handler counts).
|
|
78
19
|
*/
|
|
79
20
|
export async function buildSpeechDocument(item, options = {}) {
|
|
80
21
|
const mathConfig = options.math ?? { enabled: false, style: "clearspeak" };
|
|
81
|
-
const
|
|
82
|
-
// Parse markdown with math support
|
|
22
|
+
const style = mathConfig.style || "clearspeak";
|
|
83
23
|
const processor = unified().use(remarkParse).use(remarkMath);
|
|
84
24
|
const tree = processor.parse(item.content);
|
|
85
|
-
// Extract text from AST - can contain strings or promises
|
|
86
25
|
const textParts = [];
|
|
26
|
+
// Collect math spoken forms keyed by `${'d'|'i'}:${latex}` so the rehype
|
|
27
|
+
// plugin can reuse them without running math-to-speech in the Vite build.
|
|
28
|
+
const mathKeys = [];
|
|
29
|
+
const mathPromises = [];
|
|
30
|
+
function recordMath(latex, display) {
|
|
31
|
+
const p = speakLatex(latex, display, style);
|
|
32
|
+
mathKeys.push(`${display ? "d" : "i"}:${latex.trim()}`);
|
|
33
|
+
mathPromises.push(p);
|
|
34
|
+
return p;
|
|
35
|
+
}
|
|
36
|
+
function processChildren(node) {
|
|
37
|
+
for (const child of node.children) {
|
|
38
|
+
processNode(child);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
87
41
|
function processNode(node) {
|
|
88
42
|
switch (node.type) {
|
|
89
43
|
case "text": {
|
|
90
|
-
|
|
91
|
-
textParts.push(textNode.value);
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case "inlineCode": {
|
|
95
|
-
const codeNode = node;
|
|
96
|
-
// Skip short code, read longer code
|
|
97
|
-
if (codeNode.value.length > 10) {
|
|
98
|
-
textParts.push(codeNode.value);
|
|
99
|
-
}
|
|
44
|
+
textParts.push(node.value);
|
|
100
45
|
break;
|
|
101
46
|
}
|
|
47
|
+
// Inline code and code blocks are skipped by the rehype word-wrapper
|
|
48
|
+
// (pre/code in its skip set), so they must not contribute speech tokens.
|
|
49
|
+
case "inlineCode":
|
|
102
50
|
case "code": {
|
|
103
|
-
const blockCode = node;
|
|
104
|
-
// Skip code blocks entirely for TTS
|
|
105
|
-
// Could optionally add language hint: "Code block in {lang}"
|
|
106
|
-
if (blockCode.lang) {
|
|
107
|
-
textParts.push(`[Code in ${blockCode.lang}]`);
|
|
108
|
-
}
|
|
109
51
|
break;
|
|
110
52
|
}
|
|
111
53
|
case "heading": {
|
|
112
54
|
const heading = node;
|
|
113
|
-
//
|
|
55
|
+
// Single "#" chunk marker for all heading levels (synthesis backend
|
|
56
|
+
// expects it). Removed by stripForAlignment, so not an alignment token.
|
|
114
57
|
textParts.push("\n# ");
|
|
115
|
-
|
|
116
|
-
for (const child of heading.children) {
|
|
117
|
-
processNode(child);
|
|
118
|
-
}
|
|
119
|
-
// Add newline after headings for separation
|
|
58
|
+
processChildren(heading);
|
|
120
59
|
textParts.push("\n");
|
|
121
60
|
break;
|
|
122
61
|
}
|
|
123
62
|
case "paragraph": {
|
|
124
|
-
|
|
125
|
-
for (const child of para.children) {
|
|
126
|
-
processNode(child);
|
|
127
|
-
}
|
|
128
|
-
// Paragraph break
|
|
63
|
+
processChildren(node);
|
|
129
64
|
textParts.push("\n");
|
|
130
65
|
break;
|
|
131
66
|
}
|
|
132
67
|
case "emphasis": {
|
|
133
|
-
|
|
134
|
-
for (const child of em.children) {
|
|
135
|
-
processNode(child);
|
|
136
|
-
}
|
|
68
|
+
processChildren(node);
|
|
137
69
|
break;
|
|
138
70
|
}
|
|
139
71
|
case "strong": {
|
|
140
|
-
|
|
141
|
-
for (const child of strong.children) {
|
|
142
|
-
processNode(child);
|
|
143
|
-
}
|
|
72
|
+
processChildren(node);
|
|
144
73
|
break;
|
|
145
74
|
}
|
|
146
75
|
case "link": {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
for (const child of link.children) {
|
|
150
|
-
processNode(child);
|
|
151
|
-
}
|
|
76
|
+
// Read link text only, not the URL (matches rehype: <a> text is walked).
|
|
77
|
+
processChildren(node);
|
|
152
78
|
break;
|
|
153
79
|
}
|
|
80
|
+
// Images are skipped by the rehype word-wrapper (img in its skip set);
|
|
81
|
+
// alt text is an attribute, not a rendered text node — emit nothing.
|
|
154
82
|
case "image": {
|
|
155
|
-
const img = node;
|
|
156
|
-
// Read alt text
|
|
157
|
-
if (img.alt) {
|
|
158
|
-
textParts.push(`Image: ${img.alt}`);
|
|
159
|
-
}
|
|
160
83
|
break;
|
|
161
84
|
}
|
|
162
85
|
case "list": {
|
|
163
|
-
|
|
164
|
-
for (const child of list.children) {
|
|
165
|
-
processNode(child);
|
|
166
|
-
}
|
|
86
|
+
processChildren(node);
|
|
167
87
|
break;
|
|
168
88
|
}
|
|
169
89
|
case "listItem": {
|
|
170
|
-
|
|
171
|
-
for
|
|
172
|
-
processNode(child);
|
|
173
|
-
}
|
|
90
|
+
processChildren(node);
|
|
91
|
+
// Sentence break for TTS prosody; punctuation only, not an alignment token.
|
|
174
92
|
textParts.push(". ");
|
|
175
93
|
break;
|
|
176
94
|
}
|
|
177
95
|
case "blockquote": {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
textParts.push(" End quote.");
|
|
96
|
+
// Just the quote's text — no "Quote:"/"End quote." wrappers (those
|
|
97
|
+
// words have no rendered-DOM counterpart and would desync data-i).
|
|
98
|
+
processChildren(node);
|
|
99
|
+
textParts.push("\n");
|
|
184
100
|
break;
|
|
185
101
|
}
|
|
186
|
-
// Math nodes from remark-math
|
|
187
102
|
case "math": {
|
|
188
103
|
const mathNode = node;
|
|
189
|
-
if (
|
|
190
|
-
textParts.push(
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
textParts.push(`[Math: ${mathNode.value.slice(0, 30)}]`);
|
|
104
|
+
if (mathConfig.enabled) {
|
|
105
|
+
textParts.push(recordMath(mathNode.value, true));
|
|
194
106
|
}
|
|
195
107
|
break;
|
|
196
108
|
}
|
|
197
109
|
case "inlineMath": {
|
|
198
110
|
const inlineMathNode = node;
|
|
199
|
-
if (
|
|
200
|
-
textParts.push(
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
textParts.push(inlineMathNode.value);
|
|
111
|
+
if (mathConfig.enabled) {
|
|
112
|
+
textParts.push(recordMath(inlineMathNode.value, false));
|
|
204
113
|
}
|
|
205
114
|
break;
|
|
206
115
|
}
|
|
@@ -208,44 +117,40 @@ export async function buildSpeechDocument(item, options = {}) {
|
|
|
208
117
|
textParts.push("\n\n");
|
|
209
118
|
break;
|
|
210
119
|
}
|
|
211
|
-
// Handle container nodes with children
|
|
212
120
|
case "root": {
|
|
213
|
-
|
|
214
|
-
for (const child of root.children) {
|
|
215
|
-
processNode(child);
|
|
216
|
-
}
|
|
121
|
+
processChildren(node);
|
|
217
122
|
break;
|
|
218
123
|
}
|
|
219
124
|
default: {
|
|
220
|
-
// Try to process children if they exist
|
|
221
125
|
const maybeParent = node;
|
|
222
|
-
if (maybeParent.children)
|
|
223
|
-
|
|
224
|
-
processNode(child);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
126
|
+
if (maybeParent.children)
|
|
127
|
+
processChildren(maybeParent);
|
|
227
128
|
}
|
|
228
129
|
}
|
|
229
130
|
}
|
|
230
131
|
processNode(tree);
|
|
231
|
-
// Resolve
|
|
132
|
+
// Resolve async math conversions.
|
|
232
133
|
const resolvedParts = await Promise.all(textParts);
|
|
233
|
-
//
|
|
234
|
-
|
|
134
|
+
// Normalize whitespace. The title is intentionally excluded so the
|
|
135
|
+
// alignment data matches the article body only.
|
|
136
|
+
const plainText = resolvedParts
|
|
235
137
|
.join(" ")
|
|
236
|
-
.replace(
|
|
237
|
-
.replace(/\n\s*\n/g, "\n\n")
|
|
238
|
-
.replace(/\s*\.\s*\./g, ".")
|
|
138
|
+
.replace(/[ \t]+/g, " ")
|
|
139
|
+
.replace(/\n\s*\n/g, "\n\n")
|
|
140
|
+
.replace(/\s*\.\s*\./g, ".")
|
|
239
141
|
.trim();
|
|
240
|
-
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
142
|
+
const { speechtext, normalisedSpeechtext } = buildSpeechtextPair(plainText);
|
|
143
|
+
// Map each math expression's latex key to its resolved spoken form.
|
|
144
|
+
const resolvedMath = await Promise.all(mathPromises);
|
|
145
|
+
const mathSpeech = {};
|
|
146
|
+
for (let i = 0; i < mathKeys.length; i++) {
|
|
147
|
+
mathSpeech[mathKeys[i]] = resolvedMath[i];
|
|
148
|
+
}
|
|
245
149
|
return {
|
|
246
150
|
slug: item.slug,
|
|
247
|
-
|
|
248
|
-
|
|
151
|
+
speechtext,
|
|
152
|
+
normalisedSpeechtext,
|
|
153
|
+
mathSpeech,
|
|
249
154
|
source: item.filePath,
|
|
250
155
|
};
|
|
251
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech-builder.js","sourceRoot":"","sources":["../../src/core/speech-builder.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"speech-builder.js","sourceRoot":"","sources":["../../src/core/speech-builder.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAMvD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAiB,EACjB,UAAwB,EAAE;IAE1B,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IAC3E,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,IAAI,YAAY,CAAC;IAE/C,MAAM,SAAS,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAS,CA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,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU;QACV,oBAAoB;QACpB,UAAU;QACV,MAAM,EAAE,IAAI,CAAC,QAAQ;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spoken-form normalization primitives.
|
|
3
|
+
*
|
|
4
|
+
* Ported from the Valeon blog's audio pipeline so the plugin's
|
|
5
|
+
* build-time tokenization reproduces VocaSync's alignment token stream
|
|
6
|
+
* exactly. Two transforms:
|
|
7
|
+
*
|
|
8
|
+
* expandSpokenForms(text) — expands currencies, numbers, percentages
|
|
9
|
+
* into spoken word equivalents. Preserves
|
|
10
|
+
* punctuation/casing so it reads naturally
|
|
11
|
+
* for TTS. This is the `speechtext` POSTed
|
|
12
|
+
* to synthesis.
|
|
13
|
+
*
|
|
14
|
+
* stripForAlignment(text) — derives the alignment-friendly form:
|
|
15
|
+
* lowercase, punctuation removed, whitespace
|
|
16
|
+
* collapsed, contractions preserved. This is
|
|
17
|
+
* the `normalisedSpeechtext` POSTed as the
|
|
18
|
+
* alignment transcript AND the basis for the
|
|
19
|
+
* rehype plugin's `data-i`/`data-n` indices.
|
|
20
|
+
*
|
|
21
|
+
* Because the alignment transcript IS `stripForAlignment(expandSpokenForms(text))`,
|
|
22
|
+
* the worker's own normalizer is a no-op over it and word indices line up
|
|
23
|
+
* token-for-token with the rehype output.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Expand currency symbols, numbers, and percentages into their spoken
|
|
27
|
+
* word forms. Preserves punctuation and surrounding text — this is the
|
|
28
|
+
* surface that becomes `speechtext`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function expandSpokenForms(input: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Strip a speechtext-form string into the alignment form: lowercase,
|
|
33
|
+
* punctuation removed, whitespace collapsed. Contractions are preserved
|
|
34
|
+
* (e.g. "don't" stays one token).
|
|
35
|
+
*/
|
|
36
|
+
export declare function stripForAlignment(input: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Produce both the speechtext (POSTed to synthesis) and
|
|
39
|
+
* normalisedSpeechtext (POSTed as the alignment transcript) forms from a
|
|
40
|
+
* single plain-text input.
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildSpeechtextPair(plainText: string): {
|
|
43
|
+
speechtext: string;
|
|
44
|
+
normalisedSpeechtext: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* How many alignment tokens a visible string expands to. Used by the
|
|
48
|
+
* rehype plugin to compute `data-n` for each wrapped word / math unit.
|
|
49
|
+
* "$50" -> 2 ("fifty dollar"); "1995" -> 6; unambiguous words -> 1.
|
|
50
|
+
*/
|
|
51
|
+
export declare function spokenTokenCount(visible: string): number;
|
|
52
|
+
//# sourceMappingURL=spoken-form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spoken-form.d.ts","sourceRoot":"","sources":["../../src/core/spoken-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA8LH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAuCvD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAIA;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIxD"}
|