Skip to content

Loading a Phone Collection

Using PhoneCollection

The PhoneCollection class loads all phones from phoible per default. This means you have access to phone definitons and their features in many languages.

In [1]:
from phones import PhoneCollection
pc = PhoneCollection()

Getting all Phones in a Language

Let's first retrieve the first 5 phones in English. As phoible uses ISO 639-3 language codes), we use .langs with the "eng" code to retrieve English phones.

In [2]:
# get 5 english phones
pc.langs("eng").values[:5]
Out[2]:
[aː (eng), b (eng), d (eng), d̠ʒ (eng), e (eng)]

We can also retrieve phones in multiple languages.

In [3]:
# get 5 english/german phones
pc.langs(["eng", "deu"]).values[:5]
Out[3]:
[a (deu), ai (deu), au (deu), aɪ (deu), aʊ (deu)]

Languages can be listed using lang_list.

In [4]:
pc.lang_list[:5]
Out[4]:
['aal', 'aap', 'aar', 'aau', 'abb']

Getting a Specific Phone

Using .phones, we can also retrieve specific phones.

In [5]:
pc.phones("aɪ").values
Out[5]:
[aɪ (blb), aɪ (deu), aɪ (fao), aɪ (ruk), aɪ (shk), aɪ (wym)]

You can use .val, if you want to get only one phone instead of a phone for each language.

In [6]:
pc.phones("aɪ").val
Out[6]:

Using .vector, the vector representation of the phone can be accessed.

In [7]:
pc.phones("aɪ").val.vector
Out[7]:
array([-1.,  0.,  1., -1.,  0., -1., -1.,  1., -1.,  0.,  0.,  1., -1.,
        0.,  0.,  0., -1.,  0., -1., -1.,  0., -1., -1.,  1., -1., -1.,
        0., -1.,  1., -1., -1.,  0.,  1., -1., -1.,  0., -1.])

As with languages, phones can be listed using phone_list.

In [8]:
pc.langs("eng").phone_list[:5]
Out[8]:
['aː', 'b', 'd', 'd̠ʒ', 'e']

Using other Collections

Sources for PhoneCollection can be imported from phones.sources.

At the moment phoible and panphon are supported.

In [9]:
from phones.sources import PANPHON, PHOIBLE
pc_panphon = PhoneCollection(PANPHON)

Dialects

When using the PHOIBLE source, dialects are not loaded per default. You can change this by using load_dialects and specifying a specific dialect by using .dialects.

In [10]:
pc_dialects = PhoneCollection(load_dialects=True)
pc_dialects.langs("eng").dialects("english (liverpool)").values[:5]
Out[10]:
[a (eng), aɪ (eng), aʊ (eng), b (eng), d (eng)]

Some languages do not have a "standard" version and are only accessible when using load_dialects, for example Asturian.

In [11]:
pc.langs("ast").values, pc_dialects.langs("ast").dialects("asturian (north-eastern)").values[:5]
Out[11]:
([], [b (ast), d̪ (ast), e̞ (ast), f (ast), i (ast)])

You can list dialects using dialect_list.

In [12]:
pc_dialects.langs("ast").dialect_list
Out[12]:
['Asturian (North-Eastern)', 'Asturian (Western)']