@ingglish/phonemes 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/dist/index.cjs +698 -0
- package/dist/index.d.cts +254 -0
- package/dist/index.d.ts +254 -0
- package/dist/index.js +649 -0
- package/package.json +48 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARPAbet phoneme utilities and constants.
|
|
3
|
+
*
|
|
4
|
+
* ARPAbet is the phonetic notation system used by the CMU Pronouncing Dictionary.
|
|
5
|
+
* Each English phoneme is represented by a 1-3 letter code, with vowels having
|
|
6
|
+
* optional stress markers (0=unstressed, 1=primary, 2=secondary).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* All ARPAbet vowel phonemes (without stress markers).
|
|
10
|
+
*/
|
|
11
|
+
declare const ARPABET_VOWELS: readonly ["AA", "AE", "AH", "AO", "AW", "AY", "EH", "ER", "EY", "IH", "IY", "OW", "OY", "UH", "UW"];
|
|
12
|
+
/**
|
|
13
|
+
* All ARPAbet consonant phonemes.
|
|
14
|
+
*/
|
|
15
|
+
declare const ARPABET_CONSONANTS: readonly ["B", "D", "G", "K", "P", "T", "DH", "F", "HH", "S", "SH", "TH", "V", "Z", "ZH", "CH", "JH", "M", "N", "NG", "L", "R", "W", "Y"];
|
|
16
|
+
/** Regex pattern to match ARPAbet stress markers (0, 1, 2) at end of phoneme */
|
|
17
|
+
declare const STRESS_MARKER_REGEX: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the stress level from a phoneme.
|
|
20
|
+
* Returns null for consonants or vowels without explicit stress.
|
|
21
|
+
* Uses charCode check instead of regex (consistent with stripStress).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* getStress('AH0') // 0
|
|
25
|
+
* getStress('EY1') // 1
|
|
26
|
+
* getStress('AO2') // 2
|
|
27
|
+
* getStress('B') // null
|
|
28
|
+
*/
|
|
29
|
+
declare function getStress(phoneme: string): 0 | 1 | 2 | null;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if an ARPAbet phoneme is a vowel.
|
|
32
|
+
* Vowels can have stress markers (0, 1, 2).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* isVowel('AH0') // true
|
|
36
|
+
* isVowel('EY1') // true
|
|
37
|
+
* isVowel('B') // false
|
|
38
|
+
*/
|
|
39
|
+
declare function isVowel(phoneme: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Strips stress markers (0, 1, 2) from a phoneme.
|
|
42
|
+
* Uses charCode check instead of regex (benchmarked 2x faster).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* stripStress('AH0') // 'AH'
|
|
46
|
+
* stripStress('EY1') // 'EY'
|
|
47
|
+
* stripStress('B') // 'B'
|
|
48
|
+
*/
|
|
49
|
+
declare function stripStress(phoneme: string): string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Finds the starting index of the maximal valid onset from a consonant cluster.
|
|
53
|
+
*
|
|
54
|
+
* Uses the Maximal Onset Principle: assign as many consonants as possible
|
|
55
|
+
* to the onset, as long as they form a legal onset cluster. The remaining
|
|
56
|
+
* consonants become the coda of the previous syllable.
|
|
57
|
+
*
|
|
58
|
+
* @param consonants Array of consonant phonemes between two vowels
|
|
59
|
+
* @returns Index within the consonant array where the valid onset begins
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // "extra" has consonants [K, S, T, R] between vowels
|
|
63
|
+
* // [S, T, R] is valid onset, so onset starts at index 1
|
|
64
|
+
* findOnsetStart(['K', 'S', 'T', 'R']) // 1
|
|
65
|
+
*
|
|
66
|
+
* // "instruct" has [N, S, T, R]
|
|
67
|
+
* // [S, T, R] is valid, so onset starts at index 1
|
|
68
|
+
* findOnsetStart(['N', 'S', 'T', 'R']) // 1
|
|
69
|
+
*/
|
|
70
|
+
declare function findOnsetStart(consonants: string[]): number;
|
|
71
|
+
|
|
72
|
+
interface FormatHandler {
|
|
73
|
+
forward?: ForwardConverter;
|
|
74
|
+
isLatinScript?: boolean;
|
|
75
|
+
/** Compound word join separator. Default '' */
|
|
76
|
+
joinSeparator?: string;
|
|
77
|
+
/** Display name ('Ingglish', 'IPA', etc.) */
|
|
78
|
+
label?: string;
|
|
79
|
+
/** Display name in the format's own script (e.g. 'ππ±ππΎπ―' for Shavian) */
|
|
80
|
+
nativeLabel?: string;
|
|
81
|
+
/** Whether case is preserved (caps, sentence start). Defaults to isLatinScript. */
|
|
82
|
+
preservesCase?: boolean;
|
|
83
|
+
reverseText?: ReverseTextConverter;
|
|
84
|
+
reverseTextWithMapping?: ReverseTextWithMappingConverter;
|
|
85
|
+
}
|
|
86
|
+
type ForwardConverter = (arpabet: string[], options?: ForwardConverterOptions) => string;
|
|
87
|
+
interface ForwardConverterOptions {
|
|
88
|
+
/** Disable English R-coloring rules (vowel+R fusion). Use for foreign text. */
|
|
89
|
+
disableRColoring?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/** Token returned by reverse-with-mapping translation */
|
|
92
|
+
interface ReverseToken {
|
|
93
|
+
isWord: boolean;
|
|
94
|
+
matched?: boolean;
|
|
95
|
+
original: string;
|
|
96
|
+
translated: string;
|
|
97
|
+
}
|
|
98
|
+
type ReverseTextConverter = (text: string) => string;
|
|
99
|
+
type ReverseTextWithMappingConverter = (text: string) => ReverseToken[];
|
|
100
|
+
declare function getFormatHandler(name: string): FormatHandler | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Returns whether a format uses Latin script characters.
|
|
103
|
+
* Defaults to true for unknown formats (safe for case handling).
|
|
104
|
+
*/
|
|
105
|
+
declare function getFormatIsLatinScript(name: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the join separator for compound word parts.
|
|
108
|
+
* Defaults to '' (no separator).
|
|
109
|
+
*/
|
|
110
|
+
declare function getFormatJoinSeparator(name: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* Returns the display label for a format (e.g. 'Ingglish', 'IPA').
|
|
113
|
+
* Falls back to the raw format name.
|
|
114
|
+
*/
|
|
115
|
+
declare function getFormatLabel(name: string): string;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the native-script label for a format (e.g. 'ππ±ππΎπ―' for Shavian).
|
|
118
|
+
* Falls back to the standard label, then the raw format name.
|
|
119
|
+
*/
|
|
120
|
+
declare function getFormatNativeLabel(name: string): string;
|
|
121
|
+
/**
|
|
122
|
+
* Returns whether a format preserves case (capitalization, sentence start).
|
|
123
|
+
* Falls back to isLatinScript, then true for unknown formats.
|
|
124
|
+
*/
|
|
125
|
+
declare function getFormatPreservesCase(name: string): boolean;
|
|
126
|
+
declare function registerFormat(name: string, handler: FormatHandler): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Output format for phoneme conversion.
|
|
130
|
+
*/
|
|
131
|
+
type OutputFormat = 'ingglish' | 'ipa' | (string & {});
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* ARPAbet to Ingglish conversion.
|
|
135
|
+
*
|
|
136
|
+
* Converts CMU dictionary phoneme sequences to Ingglish spelling.
|
|
137
|
+
* Ingglish is a phonetic spelling system that uses only standard
|
|
138
|
+
* English letters with no ambiguity.
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Converts a single ARPAbet phoneme to Ingglish spelling.
|
|
143
|
+
*
|
|
144
|
+
* @param phoneme ARPAbet phoneme (e.g., "AH0", "EY1", "B")
|
|
145
|
+
* @returns Ingglish spelling (e.g., "a", "ay", "b")
|
|
146
|
+
*/
|
|
147
|
+
declare function arpabetPhonemeToIngglish(phoneme: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* Converts an array of ARPAbet phonemes to Ingglish spelling.
|
|
150
|
+
* Uses direct loop + string concat (benchmarked 60% faster than map+join).
|
|
151
|
+
*
|
|
152
|
+
* R-colored vowels: AA+R β 'ar', AO+R β 'or', IH+R β 'eer' (more intuitive than 'or'/'awr'/'ir')
|
|
153
|
+
*
|
|
154
|
+
* @param arpabet Array of ARPAbet symbols (e.g., ["HH", "AH0", "L", "OW1"])
|
|
155
|
+
* @returns Ingglish spelling (e.g., "haloh")
|
|
156
|
+
*/
|
|
157
|
+
declare function arpabetToIngglish(arpabet: string[]): string;
|
|
158
|
+
interface FormatOptions {
|
|
159
|
+
/** Disable English R-coloring rules (vowel+R fusion). Use for foreign text. */
|
|
160
|
+
disableRColoring?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Universal pipeline exit point: converts the ARPAbet IR to any output format.
|
|
164
|
+
*
|
|
165
|
+
* Every translation path (dictionary, fallback, G2P) produces an ARPAbet
|
|
166
|
+
* `string[]` and calls this function to get the final user-facing string.
|
|
167
|
+
*
|
|
168
|
+
* @param arpabet Array of ARPAbet symbols (the IR)
|
|
169
|
+
* @param format Output format (e.g. 'ingglish', 'ipa', 'shavian')
|
|
170
|
+
* @param options Conversion options (e.g. disable R-coloring for foreign text)
|
|
171
|
+
* @returns Formatted string
|
|
172
|
+
*/
|
|
173
|
+
declare function arpabetToFormat(arpabet: string[], format?: OutputFormat, options?: FormatOptions): string;
|
|
174
|
+
|
|
175
|
+
declare function registerPronunciation(): void;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Ingglish to ARPAbet conversion.
|
|
179
|
+
*
|
|
180
|
+
* Used to parse Ingglish spellings back to ARPAbet phonemes
|
|
181
|
+
* for reverse translation (Ingglish -> English).
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* Generates alternative ARPAbet sequences for ambiguous spellings.
|
|
185
|
+
*
|
|
186
|
+
* For length-changing alternatives (ERβEH+R, SHβS+HH), generates
|
|
187
|
+
* single-position substitutions. For same-length alternatives (AEβAH),
|
|
188
|
+
* also generates an "all-replaced" variant to handle words with multiple
|
|
189
|
+
* ambiguous vowels (e.g., "difakalt" β D IH F AH K AH L T).
|
|
190
|
+
*/
|
|
191
|
+
declare function expandArpabetAlternatives(arpabet: string[]): string[][];
|
|
192
|
+
/**
|
|
193
|
+
* Converts an Ingglish spelling to ARPAbet phonemes.
|
|
194
|
+
* Uses index-based parsing to avoid intermediate string allocations.
|
|
195
|
+
*
|
|
196
|
+
* @param ingglish - Ingglish string (e.g., "haloh" for "hello")
|
|
197
|
+
* @returns Array of ARPAbet phonemes (e.g., ["HH", "AH", "L", "OW"]), or null if empty
|
|
198
|
+
*/
|
|
199
|
+
declare function ingglishToArpabet(ingglish: string): null | string[];
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Combined ARPAbet to Ingglish map.
|
|
203
|
+
*/
|
|
204
|
+
declare const ARPABET_TO_INGGLISH_MAP: Record<string, string>;
|
|
205
|
+
/**
|
|
206
|
+
* Forward lookup: ARPAbet vowel β Ingglish prefix (before 'r').
|
|
207
|
+
* Used by arpabetToIngglish() to handle VOWEL+R sequences.
|
|
208
|
+
*/
|
|
209
|
+
declare const R_COLORED_FORWARD: Map<string, string>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Custom format converter builder.
|
|
213
|
+
*
|
|
214
|
+
* Creates ARPAbet-to-spelling converters using user-defined phoneme mappings.
|
|
215
|
+
* Mirrors arpabetToIngglish() logic but uses merged custom mappings.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Configuration for a custom phoneme-to-spelling mapping.
|
|
220
|
+
* Only diffs from the default Ingglish mapping need to be specified.
|
|
221
|
+
*/
|
|
222
|
+
interface CustomMappingConfig {
|
|
223
|
+
/** Overrides of ARPABET_TO_INGGLISH_MAP. Includes AH0 as a separate key. */
|
|
224
|
+
phonemeMap: Record<string, string>;
|
|
225
|
+
/** Overrides of R_COLORED_FORWARD prefixes (keyed by base vowel, e.g. 'AA'). */
|
|
226
|
+
rColoredPrefixes: Record<string, string>;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Creates a forward converter function from a custom mapping config.
|
|
230
|
+
*
|
|
231
|
+
* The converter checks phonemes in this order:
|
|
232
|
+
* 1. Exact phoneme with stress digit (e.g., AH0, EY0) in phonemeMap
|
|
233
|
+
* 2. Stress-stripped base (e.g., AH, EY) in phonemeMap
|
|
234
|
+
* 3. Default ARPABET_TO_INGGLISH_MAP
|
|
235
|
+
* 4. Lowercase phoneme as fallback
|
|
236
|
+
*/
|
|
237
|
+
declare function createCustomConverter(config: CustomMappingConfig): (arpabet: string[], options?: ForwardConverterOptions) => string;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* A single token from a translated text, preserving the mapping between
|
|
241
|
+
* original and translated forms. Used by both forward and reverse translation.
|
|
242
|
+
*/
|
|
243
|
+
interface TranslatedToken {
|
|
244
|
+
/** Whether this token is a word (true) or punctuation/whitespace (false). */
|
|
245
|
+
isWord: boolean;
|
|
246
|
+
/** Whether the word was found in the dictionary (false = heuristic fallback). */
|
|
247
|
+
matched: boolean;
|
|
248
|
+
/** The original text of this token (English for forward, Ingglish for reverse). */
|
|
249
|
+
original: string;
|
|
250
|
+
/** The translated text (Ingglish for forward, English for reverse). */
|
|
251
|
+
translated: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { ARPABET_CONSONANTS, ARPABET_TO_INGGLISH_MAP, ARPABET_VOWELS, type CustomMappingConfig, type OutputFormat, R_COLORED_FORWARD, type ReverseToken, STRESS_MARKER_REGEX, type TranslatedToken, arpabetPhonemeToIngglish, arpabetToFormat, arpabetToIngglish, createCustomConverter, expandArpabetAlternatives, findOnsetStart, getFormatHandler, getFormatIsLatinScript, getFormatJoinSeparator, getFormatLabel, getFormatNativeLabel, getFormatPreservesCase, getStress, ingglishToArpabet, isVowel, registerFormat, registerPronunciation, stripStress };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARPAbet phoneme utilities and constants.
|
|
3
|
+
*
|
|
4
|
+
* ARPAbet is the phonetic notation system used by the CMU Pronouncing Dictionary.
|
|
5
|
+
* Each English phoneme is represented by a 1-3 letter code, with vowels having
|
|
6
|
+
* optional stress markers (0=unstressed, 1=primary, 2=secondary).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* All ARPAbet vowel phonemes (without stress markers).
|
|
10
|
+
*/
|
|
11
|
+
declare const ARPABET_VOWELS: readonly ["AA", "AE", "AH", "AO", "AW", "AY", "EH", "ER", "EY", "IH", "IY", "OW", "OY", "UH", "UW"];
|
|
12
|
+
/**
|
|
13
|
+
* All ARPAbet consonant phonemes.
|
|
14
|
+
*/
|
|
15
|
+
declare const ARPABET_CONSONANTS: readonly ["B", "D", "G", "K", "P", "T", "DH", "F", "HH", "S", "SH", "TH", "V", "Z", "ZH", "CH", "JH", "M", "N", "NG", "L", "R", "W", "Y"];
|
|
16
|
+
/** Regex pattern to match ARPAbet stress markers (0, 1, 2) at end of phoneme */
|
|
17
|
+
declare const STRESS_MARKER_REGEX: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the stress level from a phoneme.
|
|
20
|
+
* Returns null for consonants or vowels without explicit stress.
|
|
21
|
+
* Uses charCode check instead of regex (consistent with stripStress).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* getStress('AH0') // 0
|
|
25
|
+
* getStress('EY1') // 1
|
|
26
|
+
* getStress('AO2') // 2
|
|
27
|
+
* getStress('B') // null
|
|
28
|
+
*/
|
|
29
|
+
declare function getStress(phoneme: string): 0 | 1 | 2 | null;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if an ARPAbet phoneme is a vowel.
|
|
32
|
+
* Vowels can have stress markers (0, 1, 2).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* isVowel('AH0') // true
|
|
36
|
+
* isVowel('EY1') // true
|
|
37
|
+
* isVowel('B') // false
|
|
38
|
+
*/
|
|
39
|
+
declare function isVowel(phoneme: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Strips stress markers (0, 1, 2) from a phoneme.
|
|
42
|
+
* Uses charCode check instead of regex (benchmarked 2x faster).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* stripStress('AH0') // 'AH'
|
|
46
|
+
* stripStress('EY1') // 'EY'
|
|
47
|
+
* stripStress('B') // 'B'
|
|
48
|
+
*/
|
|
49
|
+
declare function stripStress(phoneme: string): string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Finds the starting index of the maximal valid onset from a consonant cluster.
|
|
53
|
+
*
|
|
54
|
+
* Uses the Maximal Onset Principle: assign as many consonants as possible
|
|
55
|
+
* to the onset, as long as they form a legal onset cluster. The remaining
|
|
56
|
+
* consonants become the coda of the previous syllable.
|
|
57
|
+
*
|
|
58
|
+
* @param consonants Array of consonant phonemes between two vowels
|
|
59
|
+
* @returns Index within the consonant array where the valid onset begins
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // "extra" has consonants [K, S, T, R] between vowels
|
|
63
|
+
* // [S, T, R] is valid onset, so onset starts at index 1
|
|
64
|
+
* findOnsetStart(['K', 'S', 'T', 'R']) // 1
|
|
65
|
+
*
|
|
66
|
+
* // "instruct" has [N, S, T, R]
|
|
67
|
+
* // [S, T, R] is valid, so onset starts at index 1
|
|
68
|
+
* findOnsetStart(['N', 'S', 'T', 'R']) // 1
|
|
69
|
+
*/
|
|
70
|
+
declare function findOnsetStart(consonants: string[]): number;
|
|
71
|
+
|
|
72
|
+
interface FormatHandler {
|
|
73
|
+
forward?: ForwardConverter;
|
|
74
|
+
isLatinScript?: boolean;
|
|
75
|
+
/** Compound word join separator. Default '' */
|
|
76
|
+
joinSeparator?: string;
|
|
77
|
+
/** Display name ('Ingglish', 'IPA', etc.) */
|
|
78
|
+
label?: string;
|
|
79
|
+
/** Display name in the format's own script (e.g. 'ππ±ππΎπ―' for Shavian) */
|
|
80
|
+
nativeLabel?: string;
|
|
81
|
+
/** Whether case is preserved (caps, sentence start). Defaults to isLatinScript. */
|
|
82
|
+
preservesCase?: boolean;
|
|
83
|
+
reverseText?: ReverseTextConverter;
|
|
84
|
+
reverseTextWithMapping?: ReverseTextWithMappingConverter;
|
|
85
|
+
}
|
|
86
|
+
type ForwardConverter = (arpabet: string[], options?: ForwardConverterOptions) => string;
|
|
87
|
+
interface ForwardConverterOptions {
|
|
88
|
+
/** Disable English R-coloring rules (vowel+R fusion). Use for foreign text. */
|
|
89
|
+
disableRColoring?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/** Token returned by reverse-with-mapping translation */
|
|
92
|
+
interface ReverseToken {
|
|
93
|
+
isWord: boolean;
|
|
94
|
+
matched?: boolean;
|
|
95
|
+
original: string;
|
|
96
|
+
translated: string;
|
|
97
|
+
}
|
|
98
|
+
type ReverseTextConverter = (text: string) => string;
|
|
99
|
+
type ReverseTextWithMappingConverter = (text: string) => ReverseToken[];
|
|
100
|
+
declare function getFormatHandler(name: string): FormatHandler | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Returns whether a format uses Latin script characters.
|
|
103
|
+
* Defaults to true for unknown formats (safe for case handling).
|
|
104
|
+
*/
|
|
105
|
+
declare function getFormatIsLatinScript(name: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the join separator for compound word parts.
|
|
108
|
+
* Defaults to '' (no separator).
|
|
109
|
+
*/
|
|
110
|
+
declare function getFormatJoinSeparator(name: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* Returns the display label for a format (e.g. 'Ingglish', 'IPA').
|
|
113
|
+
* Falls back to the raw format name.
|
|
114
|
+
*/
|
|
115
|
+
declare function getFormatLabel(name: string): string;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the native-script label for a format (e.g. 'ππ±ππΎπ―' for Shavian).
|
|
118
|
+
* Falls back to the standard label, then the raw format name.
|
|
119
|
+
*/
|
|
120
|
+
declare function getFormatNativeLabel(name: string): string;
|
|
121
|
+
/**
|
|
122
|
+
* Returns whether a format preserves case (capitalization, sentence start).
|
|
123
|
+
* Falls back to isLatinScript, then true for unknown formats.
|
|
124
|
+
*/
|
|
125
|
+
declare function getFormatPreservesCase(name: string): boolean;
|
|
126
|
+
declare function registerFormat(name: string, handler: FormatHandler): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Output format for phoneme conversion.
|
|
130
|
+
*/
|
|
131
|
+
type OutputFormat = 'ingglish' | 'ipa' | (string & {});
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* ARPAbet to Ingglish conversion.
|
|
135
|
+
*
|
|
136
|
+
* Converts CMU dictionary phoneme sequences to Ingglish spelling.
|
|
137
|
+
* Ingglish is a phonetic spelling system that uses only standard
|
|
138
|
+
* English letters with no ambiguity.
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Converts a single ARPAbet phoneme to Ingglish spelling.
|
|
143
|
+
*
|
|
144
|
+
* @param phoneme ARPAbet phoneme (e.g., "AH0", "EY1", "B")
|
|
145
|
+
* @returns Ingglish spelling (e.g., "a", "ay", "b")
|
|
146
|
+
*/
|
|
147
|
+
declare function arpabetPhonemeToIngglish(phoneme: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* Converts an array of ARPAbet phonemes to Ingglish spelling.
|
|
150
|
+
* Uses direct loop + string concat (benchmarked 60% faster than map+join).
|
|
151
|
+
*
|
|
152
|
+
* R-colored vowels: AA+R β 'ar', AO+R β 'or', IH+R β 'eer' (more intuitive than 'or'/'awr'/'ir')
|
|
153
|
+
*
|
|
154
|
+
* @param arpabet Array of ARPAbet symbols (e.g., ["HH", "AH0", "L", "OW1"])
|
|
155
|
+
* @returns Ingglish spelling (e.g., "haloh")
|
|
156
|
+
*/
|
|
157
|
+
declare function arpabetToIngglish(arpabet: string[]): string;
|
|
158
|
+
interface FormatOptions {
|
|
159
|
+
/** Disable English R-coloring rules (vowel+R fusion). Use for foreign text. */
|
|
160
|
+
disableRColoring?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Universal pipeline exit point: converts the ARPAbet IR to any output format.
|
|
164
|
+
*
|
|
165
|
+
* Every translation path (dictionary, fallback, G2P) produces an ARPAbet
|
|
166
|
+
* `string[]` and calls this function to get the final user-facing string.
|
|
167
|
+
*
|
|
168
|
+
* @param arpabet Array of ARPAbet symbols (the IR)
|
|
169
|
+
* @param format Output format (e.g. 'ingglish', 'ipa', 'shavian')
|
|
170
|
+
* @param options Conversion options (e.g. disable R-coloring for foreign text)
|
|
171
|
+
* @returns Formatted string
|
|
172
|
+
*/
|
|
173
|
+
declare function arpabetToFormat(arpabet: string[], format?: OutputFormat, options?: FormatOptions): string;
|
|
174
|
+
|
|
175
|
+
declare function registerPronunciation(): void;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Ingglish to ARPAbet conversion.
|
|
179
|
+
*
|
|
180
|
+
* Used to parse Ingglish spellings back to ARPAbet phonemes
|
|
181
|
+
* for reverse translation (Ingglish -> English).
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* Generates alternative ARPAbet sequences for ambiguous spellings.
|
|
185
|
+
*
|
|
186
|
+
* For length-changing alternatives (ERβEH+R, SHβS+HH), generates
|
|
187
|
+
* single-position substitutions. For same-length alternatives (AEβAH),
|
|
188
|
+
* also generates an "all-replaced" variant to handle words with multiple
|
|
189
|
+
* ambiguous vowels (e.g., "difakalt" β D IH F AH K AH L T).
|
|
190
|
+
*/
|
|
191
|
+
declare function expandArpabetAlternatives(arpabet: string[]): string[][];
|
|
192
|
+
/**
|
|
193
|
+
* Converts an Ingglish spelling to ARPAbet phonemes.
|
|
194
|
+
* Uses index-based parsing to avoid intermediate string allocations.
|
|
195
|
+
*
|
|
196
|
+
* @param ingglish - Ingglish string (e.g., "haloh" for "hello")
|
|
197
|
+
* @returns Array of ARPAbet phonemes (e.g., ["HH", "AH", "L", "OW"]), or null if empty
|
|
198
|
+
*/
|
|
199
|
+
declare function ingglishToArpabet(ingglish: string): null | string[];
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Combined ARPAbet to Ingglish map.
|
|
203
|
+
*/
|
|
204
|
+
declare const ARPABET_TO_INGGLISH_MAP: Record<string, string>;
|
|
205
|
+
/**
|
|
206
|
+
* Forward lookup: ARPAbet vowel β Ingglish prefix (before 'r').
|
|
207
|
+
* Used by arpabetToIngglish() to handle VOWEL+R sequences.
|
|
208
|
+
*/
|
|
209
|
+
declare const R_COLORED_FORWARD: Map<string, string>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Custom format converter builder.
|
|
213
|
+
*
|
|
214
|
+
* Creates ARPAbet-to-spelling converters using user-defined phoneme mappings.
|
|
215
|
+
* Mirrors arpabetToIngglish() logic but uses merged custom mappings.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Configuration for a custom phoneme-to-spelling mapping.
|
|
220
|
+
* Only diffs from the default Ingglish mapping need to be specified.
|
|
221
|
+
*/
|
|
222
|
+
interface CustomMappingConfig {
|
|
223
|
+
/** Overrides of ARPABET_TO_INGGLISH_MAP. Includes AH0 as a separate key. */
|
|
224
|
+
phonemeMap: Record<string, string>;
|
|
225
|
+
/** Overrides of R_COLORED_FORWARD prefixes (keyed by base vowel, e.g. 'AA'). */
|
|
226
|
+
rColoredPrefixes: Record<string, string>;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Creates a forward converter function from a custom mapping config.
|
|
230
|
+
*
|
|
231
|
+
* The converter checks phonemes in this order:
|
|
232
|
+
* 1. Exact phoneme with stress digit (e.g., AH0, EY0) in phonemeMap
|
|
233
|
+
* 2. Stress-stripped base (e.g., AH, EY) in phonemeMap
|
|
234
|
+
* 3. Default ARPABET_TO_INGGLISH_MAP
|
|
235
|
+
* 4. Lowercase phoneme as fallback
|
|
236
|
+
*/
|
|
237
|
+
declare function createCustomConverter(config: CustomMappingConfig): (arpabet: string[], options?: ForwardConverterOptions) => string;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* A single token from a translated text, preserving the mapping between
|
|
241
|
+
* original and translated forms. Used by both forward and reverse translation.
|
|
242
|
+
*/
|
|
243
|
+
interface TranslatedToken {
|
|
244
|
+
/** Whether this token is a word (true) or punctuation/whitespace (false). */
|
|
245
|
+
isWord: boolean;
|
|
246
|
+
/** Whether the word was found in the dictionary (false = heuristic fallback). */
|
|
247
|
+
matched: boolean;
|
|
248
|
+
/** The original text of this token (English for forward, Ingglish for reverse). */
|
|
249
|
+
original: string;
|
|
250
|
+
/** The translated text (Ingglish for forward, English for reverse). */
|
|
251
|
+
translated: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { ARPABET_CONSONANTS, ARPABET_TO_INGGLISH_MAP, ARPABET_VOWELS, type CustomMappingConfig, type OutputFormat, R_COLORED_FORWARD, type ReverseToken, STRESS_MARKER_REGEX, type TranslatedToken, arpabetPhonemeToIngglish, arpabetToFormat, arpabetToIngglish, createCustomConverter, expandArpabetAlternatives, findOnsetStart, getFormatHandler, getFormatIsLatinScript, getFormatJoinSeparator, getFormatLabel, getFormatNativeLabel, getFormatPreservesCase, getStress, ingglishToArpabet, isVowel, registerFormat, registerPronunciation, stripStress };
|