Quickstart
Minimal examples for G2P, pronunciation correction, phoneme ASR, and P2G.
G2P
from hama import G2PModel
model = G2PModel()
result = model.predict(
"Really? What's the orbital velocity of the moon?",
preserve_literals="punct",
)
print(result.ipa)
print(result.display_ipa) import { G2PNodeModel } from "hama-js/g2p";
const model = await G2PNodeModel.create();
const result = await model.predict(
"Really? What's the orbital velocity of the moon?",
{ preserveLiterals: "punct" },
);
console.log(result.ipa);
console.log(result.displayIpa); import { G2PBrowserModel } from "hama-js/g2p/browser";
const model = await G2PBrowserModel.create();
const result = await model.predict("안녕하세요", {
preserveLiterals: "punct",
});
console.log(result.ipa);
console.log(result.displayIpa); Pronunciation Correction
from hama import pronunciation_replace
text = "we met (jon smyth), yesterday"
terms = [{"text": "John Smythe"}]
result = pronunciation_replace(text, terms)
print(result["text"]) import { pronunciationReplace } from "hama-js";
const text = "we met (jon smyth), yesterday";
const terms = [{ text: "John Smythe" }];
const result = await pronunciationReplace(text, terms);
console.log(result.text); import { G2PBrowserModel } from "hama-js/g2p/browser";
const model = await G2PBrowserModel.create();
const result = await model.pronunciationReplace(
"we met (jon smyth), yesterday",
[{ text: "John Smythe" }],
);
console.log(result.text); ASR
from hama import ASRModel
model = ASRModel()
result = model.transcribe_file("sample.wav")
print(result.phoneme_text)
print(result.word_phoneme_text)
# v1.6.0: coarse per-phoneme time spans (CTC is peaky)
for span in model.phoneme_spans(result):
print(span.phoneme, span.start_ms, span.end_ms) import { ASRNodeModel } from "hama-js/asr";
const model = await ASRNodeModel.create();
const result = await model.transcribeWavFile("sample.wav");
console.log(result.phonemeText);
// v1.6.0: coarse per-phoneme time spans (CTC is peaky)
for (const span of model.phonemeSpans(result)) {
console.log(span.phoneme, span.startMs, span.endMs);
} import { ASRBrowserModel } from "hama-js/asr/browser";
const model = await ASRBrowserModel.create({
modelUrl: "/assets/asr_waveform.hama",
});
const result = await model.transcribeWaveform(float32Samples, 16000);
console.log(result.phonemeText);
// v1.6.0: coarse per-phoneme time spans (CTC is peaky)
for (const span of model.phonemeSpans(result)) {
console.log(span.phoneme, span.startMs, span.endMs);
} P2G
from hama import P2GModel
p2g = P2GModel()
result = p2g.predict(["l", "ɛ", "t", "|", "m", "e", "|", "s", "i"])
print(result.text) # -> "let me see"
# v1.6.0: each output token aligned to the phoneme it most attends to
for a in result.alignments:
print(a.token, a.phoneme_index, a.phoneme) import { P2GNodeModel } from "hama-js/p2g";
const p2g = await P2GNodeModel.create();
const result = p2g.predict("l ɛ t | m e | s i");
console.log(result.text);
// v1.6.0: each output token aligned to the phoneme it most attends to
for (const a of result.alignments) {
console.log(a.token, a.phonemeIndex, a.phoneme);
} import { P2GBrowserModel } from "hama-js/p2g/browser";
const p2g = await P2GBrowserModel.create({ modelUrl: "/assets/p2g.hama" });
const result = p2g.predict("l ɛ t | m e | s i");
console.log(result.text);
// v1.6.0: each output token aligned to the phoneme it most attends to
for (const a of result.alignments) {
console.log(a.token, a.phonemeIndex, a.phoneme);
} For full signatures, options, and return shapes, see APIs.