Previous topic

Voices

Next topic

Style Guide

HRG with the Python APIΒΆ

The code to recreate the HRG structure in figure 4 can be found at speect/swig/python/examples/hrg_docs_example.py, or HRG example. See HRG API for a detailed description of the API. Here we show some snippets to explain the process of building an utterance.

An utterance is created by a call to speect.SUtterance():

import speect

utt = speect.SUtterance()

A relation is created from the utterance with speect.SUtterance.relation_new():

# create a new "Word" relation
word_rel = utt.relation_new("Word")

and items can be created by appending them to a relation with speect.SRelation.append():

# add word in word relation
word_item = word_rel.append()

word_item["name"] = "twenty"

No shared content argument was passed in speect.SRelation.append(). Shared content is used when one wants to add an item to more than one relation, and share the content of the items. For example, we might have a token relation, with the first token being “21”. In the word relation we will have two words, “twenty” and “one”, both of which can be daughters (as in figure 4, but with the token relation one level higher than the word relation) of the “21” token item. To create the shared items we can code it as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
item21 = token_rel.append()
item21["name"] = "21"

item_twenty = word_rel.append()
item_twenty["name"] = "twenty"

item_one = word_rel.append()
item_one["name"] = "one"

item21.add_daughter(item_twenty)
item21.add_daughter(item_one)

Figure 5 shows a representation of the HRG that can be created by following the above code example. Note that item21 is now the parent item (gotten with speec.SItem.parent() of both itemTwenty and itemOne).


An example of the HRG representation of parent/daughter items.

Figure 5: An example of the HRG representation of parent/daughter items.