phonemize
Version:
Fast phonemizer with rule-based G2P prediction. Pure JavaScript implementation.
34 lines (33 loc) • 1.64 kB
TypeScript
import { LanguageProcessor } from "../g2p";
declare class RussianG2P implements LanguageProcessor {
readonly id = "ru-g2p";
readonly name = "Russian G2P Processor";
readonly supportedLanguages: string[];
preProcess(text: string): string;
predict(word: string, language?: string, pos?: string): string | null;
/**
* Token-level G2P. Input is the post-anyAscii Latin transliteration:
*
* - digraphs (zh/kh/ch/sh/shch/ts) → real IPA, looked up longest-first
* so the bare `s`/`z`/`t`/`c`/`k`/`h` fallbacks never preempt them.
* - "y" before a/o/u is the anyAscii rendering of я/ё/ю — when it
* follows a consonant it palatalizes that consonant and the `y` is
* absorbed; word-initially or after a vowel it surfaces as /j/.
* - "e" and "i" after a consonant also palatalize.
* - Final voiced obstruent → voiceless (final devoicing).
*
* This is a phonemic approximation only — Russian needs lexical stress
* to do unstressed-vowel reduction (akan'e / ikan'e) properly, and we
* don't have a stress dictionary, so vowel quality stays full.
*/
private processRussian;
/**
* Assign heuristic stress and apply unstressed-vowel reduction in place.
* Vowel tokens are a/e/i/o/u/ɨ. Stressed vowel keeps full quality; for
* unstressed: o,a → ɐ (first-pretonic or word-initial) else ə; e → ɪ;
* i/u/ɨ stay. A ˈ mark is inserted at the stressed syllable's onset.
*/
private applyStressAndReduction;
addPronunciation(word: string, pronunciation: string): void;
}
export default RussianG2P;