Ham: phoneme and grapheme toolkit

Ham provides functionality on top of the CMU Pronouncing Dictionary (http://www.speech.cs.cmu.edu/cgi-bin/cmudict), to manipulate words and pronunciations.

Why Ham?

I promised myself that I would name my first open source project “Ham”.

Overview

This is an overview. Full API docs can be found here.

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

class ham.Pronunciation(phonemes)[source]

A wrapper around a list of phonemes.

Pronunciation.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.

class ham.Word(word)[source]

Encapsulates a word.

Word.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.

Word.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()
[]
Word.vowel_groups()[source]

Generator that yields consecutive groups of vowels.

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

Table of contents

Indices and tables

Project Versions

Table Of Contents

Next topic

API Reference

This Page