phonemize
Version:
Fast phonemizer with rule-based G2P prediction. Pure JavaScript implementation.
46 lines (45 loc) • 1.87 kB
TypeScript
/**
* English vowel reduction (P2.2 of G2P redesign).
*
* Given an IPA string (no stress marks) and the set of stressed nucleus
* indices, replace each unstressed vowel nucleus with its reduced form.
*
* Reduction rules (simple, ordered by specificity):
*
* 1. Unstressed nucleus immediately followed by /ɹ/ (any vowel + r in
* the same syllable) → ɝ. Examples: doctor /dɑkˈtɝ/, mother /mʌðˈɝ/.
*
* 2. Unstressed word-final open syllable with high front vowel
* (/i, ɪ/) → i (happy-tensing).
*
* 3. All other unstressed nuclei → ə.
*
* Stressed nuclei are left untouched. Long vowels (/i/, /u/, /eɪ/, /oʊ/,
* /aɪ/, /aʊ/, /ɔɪ/) generally don't reduce — caller can decide whether to
* apply rules to them via the `reduceLong` option (default: false).
*
* The function expects no stress marks in the input — caller manages
* stress externally via the indices.
*/
/**
* Locate each vowel nucleus in `ipa`. Returns array of (startIdx, endIdx)
* where endIdx is exclusive.
*/
export declare function findNuclei(ipa: string): Array<[number, number]>;
export interface ReduceOptions {
/** Also reduce long vowels (default: false — they typically resist). */
reduceLong?: boolean;
/** Apply happy-tensing for unstressed word-final /i/. */
happyTensing?: boolean;
}
/**
* Reduce unstressed vowels in `ipa`. `stressed` is a set of nucleus indices
* (0-based, in the order they appear in `ipa`) that should NOT be reduced.
*/
export declare function reduceUnstressedVowels(ipa: string, stressed: ReadonlySet<number>, opts?: ReduceOptions): string;
/**
* Given an IPA string with stress marks, extract the set of stressed
* nucleus indices (primary + secondary both count as "stressed" for
* reduction purposes).
*/
export declare function extractStressedNuclei(ipa: string): Set<number>;