/** * Abstract G2P (Grapheme-to-Phoneme) Processor Interface * * This module provides an abstraction layer for different G2P engines, * allowing dynamic registration and usage of language-specific processors. * * The exported `g2pRegistry` and free functions wrap a default global * registry to preserve the simple `phonemize("hello")` API. To create * isolated registrations (so multiple language sets can coexist without * stepping on each other) use `new G2PRegistry()` directly or the * higher-level `createPhonemizer()` factory in `core.ts`. */ export interface G2PProcessor { /** * Unique identifier for this G2P processor */ readonly id: string; /** * Human-readable name for this G2P processor */ readonly name: string; /** * Languages this processor can handle. Use BCP 47-style tags; the * registry treats `en` as a parent of `en-US`/`en-GB` etc., so a * processor that lists `["en"]` will be selected for `en-GB` requests * unless a more specific processor is also registered. */ readonly supportedLanguages: string[]; /** * Predict phonemes for a given word * * @param word - Word to convert to phonemes * @param language - Language code (optional, for disambiguation) * @param pos - Part of speech (optional, for homograph disambiguation) * @returns Phoneme string in IPA format, or null if cannot process */ predict(word: string, language?: string, pos?: string): string | null; /** * Add a custom pronunciation for a word * * @param word - Word to add pronunciation for * @param pronunciation - IPA pronunciation string */ addPronunciation(word: string, pronunciation: string): void; } /** * Return the primary language subtag — `en-GB` → `en`, `zh-Hant-TW` → `zh`. */ export declare function primaryLang(tag: string): string; /** * Normalize a BCP 47 tag for comparison. The spec defines tag matching * as case-insensitive, so we lowercase before any equality check. */ export declare function normalizeTag(tag: string): string; export declare class G2PRegistry { private processors; /** Insertion order for stable "first registered wins" semantics. */ private order; register(processor: G2PProcessor): void; unregister(id: string): boolean; getProcessor(id: string): G2PProcessor | undefined; getProcessorsForLanguage(language: string): G2PProcessor[]; getAllProcessors(): G2PProcessor[]; /** * Find the best processor for a given word and language. When a * language is provided, dialect-exact processors are tried first, * then parent-tag processors. With no language we fall back to the * first registered processor. */ findBestProcessor(_word: string, language?: string): G2PProcessor | null; predictPhonemes(word: string, language?: string, pos?: string): string | null; clear(): void; getSupportedLanguages(): string[]; } export declare const g2pRegistry: G2PRegistry; /** * Detect the language of the given text based on Unicode character ranges * * @param text - Text to detect language for * @returns Language code or null if not detected */ export declare function detectLanguage(text: string): string | null; /** * Register a G2P processor on the default global registry. * * For multi-instance setups, prefer `createPhonemizer()` from `./core`. */ export declare function useG2P(processor: G2PProcessor): void; export declare function getG2PProcessor(word: string, language?: string): G2PProcessor | null; export declare function predictPhonemes(word: string, language?: string, pos?: string): string | null; export declare function getRegisteredProcessorIds(): string[]; export declare function getProcessorsForLanguage(language: string): G2PProcessor[]; export declare function getSupportedLanguages(): string[];