API Reference

Ham is a toolkit for manipulating words, pronunciations, and phonemes.

class ham.Pronunciation(phonemes)[source]

A wrapper around a list of phonemes.

__contains__(obj)[source]

Checks if a phoneme is in this pronunciation.

If the phoneme is an unstressed vowel, that phoneme will be compared against contained vowels without regard to stress. Otherwise, if the phoneme is a stressed vowel sound, the stress will be taken into account.

>>> 'AA' in Pronunciation(['B', 'AA1', 'R', 'N'])
True

>>> 'AW0' in Pronunciation(['B', 'R', 'AW1', 'N'])
False
__weakref__

list of weak references to the object (if defined)

index(value, start=0)[source]

Return the first index of value, starting at the start index given.

If an unstressed vowel is given, will return the first index with that vowel sound regardless of stress. Otherwise index will only find a vowel sound with identical stress.

>>> Pronunciation(['B', 'AA1', 'R', 'N']).index('AA')
1
class ham.SoundPairing(word, pronunciation)[source]

A SoundPairing is for mapping a word with a pronunciation. It is used as an intermediate step for breaking a word into its phonograms.

__weakref__

list of weak references to the object (if defined)

class ham.Word(word)[source]

Encapsulates a word.

__weakref__

list of weak references to the object (if defined)

pop(seq)[source]

Return and remove a letter or sequence of letters.

>>> hello = Word('hello')
>>> hello.pop('el')
'el'
>>> str(hello)
'h..lo'

If seq does not exist, raise a ValueError.

pronunciations()[source]

Returns a list of Pronunciations for the word.

Looks the word up in the CMU pronouncing dictionary (http://www.speech.cs.cmu.edu/cgi-bin/cmudict)

If the word does not exist in the pronouncing dictionary, return an empty list.

>>> Word('hungry').pronunciations()
[<Pronunciation "HH AH1 NG G R IY0">]
>>> Word('chewbacca').pronunciations()
[]
vowel_groups()[source]

Generator that yields consecutive groups of vowels.

>>> list(Word('onomatopoeia').vowel_groups())
['o', 'o', 'a', 'o', 'oeia']

Project Versions

Previous topic

Ham: phoneme and grapheme toolkit

This Page