hama-js
Version:
G2P, phoneme-ASR, and P2G inference for Node, Bun, and browsers, powered by a self-contained WASM engine (no onnxruntime).
40 lines (39 loc) • 1.3 kB
TypeScript
export interface Vocabulary {
encoder: string[];
decoder: string[];
}
export declare const VOCAB: Vocabulary;
export interface Alignment {
phoneme: string;
phonemeIndex: number;
/**
* Original input character index for this phoneme alignment.
* Uses -1 sentinel when the input has no non-whitespace characters.
*/
charIndex: number;
}
export interface G2PResult {
ipa: string;
displayIpa: string;
alignments: Alignment[];
}
export type PreserveLiteralsMode = "none" | "punct";
export interface EncodedText {
ids: bigint[];
length: number;
positionMap: number[];
}
export declare const encodeText: (text: string, maxInputLen: number) => EncodedText;
export declare const decoderIds: {
pad: number;
sos: number;
eos: number;
unk: number;
};
export declare const decodeIdsToResult: (ids: ArrayLike<number | bigint>, attnIndices: ArrayLike<number | bigint>, positionMap: number[]) => G2PResult;
export interface PreparedPredictionText {
modelText: string;
charIndexMap: number[];
}
export declare const prepareTextForPrediction: (text: string, preserveLiterals: PreserveLiteralsMode) => PreparedPredictionText;
export declare const buildDisplayIpa: (ipa: string, alignments: Alignment[], originalText: string) => string;