UNPKG

hama-js

Version:

G2P, phoneme-ASR, and P2G inference for Node, Bun, and browsers, powered by a self-contained WASM engine (no onnxruntime).

111 lines (110 loc) 4.39 kB
import { type PhonemeSpan } from "./ctc.js"; export { ctcPhonemeSpans, ASR_OUTPUT_FRAME_SAMPLES } from "./ctc.js"; export type { PhonemeSpan } from "./ctc.js"; import { type P2GAlignment } from "./p2g-text.js"; export type { P2GAlignment } from "./p2g-text.js"; import { G2PResult, PreserveLiteralsMode } from "./tokenizer.js"; import { PronunciationReplaceOptions, PronunciationReplaceResult, PronunciationScanOptions, PronunciationScanResult, PronunciationTerm } from "./pronunciation.js"; export interface BrowserOptions { modelUrl?: string; encoderUrl?: string; decoderStepUrl?: string; maxInputLen?: number; maxOutputLen?: number; } export interface BrowserPredictOptions { splitDelimiter?: string | RegExp | null; outputDelimiter?: string; preserveLiterals?: PreserveLiteralsMode; } export interface ASRBrowserOptions { modelUrl?: string; vocabUrl?: string; sampleRate?: number; blankToken?: string; unkToken?: string; wordBoundaryToken?: string; temperature?: number; blankBias?: number; unkBias?: number; collapseRepeats?: boolean; } export interface ASRResult { phonemes: string[]; phonemeText: string; wordPhonemeText: string; tokenIds: number[]; frameTokenIds: number[]; numFrames: number; } export interface CTCDecodeOptions { blankId: number; wordBoundaryToken: string; collapseRepeats?: boolean; } export declare const decodeCtcTokens: (frameTokenIds: readonly number[], decoderTokens: readonly string[], options: CTCDecodeOptions) => { tokenIds: number[]; phonemes: string[]; words: string[][]; }; export declare class G2PBrowserModel { private readonly engine; private readonly encHandle; private readonly decHandle; private readonly options; private constructor(); static create(options?: BrowserOptions): Promise<G2PBrowserModel>; predict(text: string, options?: BrowserPredictOptions): Promise<G2PResult>; pronunciationScan(text: string, terms: Array<string | PronunciationTerm>, options?: PronunciationScanOptions): Promise<PronunciationScanResult>; pronunciationReplace(text: string, terms: Array<string | PronunciationTerm>, options?: PronunciationReplaceOptions): Promise<PronunciationReplaceResult>; getMaxInputLen(): number; private predictSingle; private predictSingleSplit; } export declare class ASRBrowserModel { private readonly engine; private readonly handle; private readonly decoderTokens; private readonly blankId; private readonly unkId; private readonly wordBoundaryToken; private readonly temperature; private readonly blankBias; private readonly unkBias; private readonly collapseRepeats; private readonly sampleRate; private constructor(); static create(options?: ASRBrowserOptions): Promise<ASRBrowserModel>; get inputFormat(): "waveform"; transcribeWaveform(waveform: readonly number[] | Float32Array, sampleRate: number): Promise<ASRResult>; /** Approximate per-phoneme time spans (ms) from an ASRResult. */ phonemeSpans(result: ASRResult): PhonemeSpan[]; private argmaxFrames; } export interface P2GBrowserOptions { modelUrl?: string; vocabUrl?: string; } export interface P2GResult { text: string; tokens: string[]; alignments: P2GAlignment[]; } export declare class P2GBrowserModel { private readonly engine; private readonly handle; private readonly tokens; private readonly token2id; private readonly bos; private readonly src; private readonly tgt; private readonly eos; private readonly pad; private readonly unk; private constructor(); static create(options?: P2GBrowserOptions): Promise<P2GBrowserModel>; predict(phonemes: string | readonly string[]): P2GResult; } export declare const pronunciationScan: (text: string, terms: Array<string | PronunciationTerm>, options?: PronunciationScanOptions) => Promise<PronunciationScanResult>; export declare const pronunciationReplace: (text: string, terms: Array<string | PronunciationTerm>, options?: PronunciationReplaceOptions) => Promise<PronunciationReplaceResult>; export type { PronunciationMatch, PronunciationPatch, PronunciationReplaceOptions, PronunciationReplaceResult, PronunciationScanOptions, PronunciationScanResult, PronunciationTerm, } from "./pronunciation.js";