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)

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"])

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)

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)

For full signatures, options, and return shapes, see APIs.