Grapheme-to-Phoneme

Grapheme to Phoneme related modeling class

class pororo.tasks.phoneme_conversion.PororoG2pFactory(task: str, lang: str, model: Optional[str])[source]

Bases: pororo.tasks.utils.base.PororoFactoryBase

Conduct grapheme to phoneme conversion

English (g2p.en)

Korean (g2p.ko)

Japanese (g2p.ja)

Chinese (g2p.zh)

Parameters
  • sent (str) – input sentence to be converted to phoneme

  • align (bool) – whether to align the result (not applied to english model)

Returns

converted phoneme sentence

Return type

str

Examples

>>> g2p = Pororo(task="g2p", lang="ko")
>>> g2p("어제는 날씨가 맑았는데, 오늘은 흐리다.")
'어제는 날씨가 말간는데, 오느른 흐리다.'
>>> g2p("어제는 날씨가 맑았는데, 오늘은 흐리다.", align=True)
[('어제는', '어제는'), ('날씨가', '날씨가'), ('맑았는데,', '말간는데,'), ('오늘은', '오느른'), ('흐리다.', '흐리다.')]
>>> g2p_en = Pororo(task="g2p", lang="en")
>>> g2p_en("I have $250 in my pocket.")
['AY1', ' ', 'HH', 'AE1', 'V', ' ', 'T', 'UW1', ' ', 'HH', 'AH1', 'N', 'D', 'R', 'AH0', 'D', ' ', 'F', 'IH1', 'F', 'T', 'IY0', ' ', 'D', 'AA1', 'L', 'ER0', 'Z', ' ', 'IH0', 'N', ' ', 'M', 'AY1', ' ', 'P', 'AA1', 'K', 'AH0', 'T', ' ', '.']
>>> g2p_zh = Pororo(task="g2p", lang="zh")
>>> g2p_zh("然而,他红了20年以后,他竟退出了大家的视线。")
'ran2 er2 , ta1 hong2 le5 2 0 nian2 yi3 hou4 , ta1 jing4 tui4 chu1 le5 da4 jia1 de5 shi4 xian4 。'
>>> g2p_zh("然而,他红了20年以后,他竟退出了大家的视线。", align=True)
[('然', 'ran2'), ('而', 'er2'), (',', ','), ('他', 'ta1'), ('红', 'hong2'), ('了', 'le5'), ('2', '2'), ('0', '0'), ('年', 'nian2'), ...]
>>> g2p_zh("然而,他红了20年以后,他竟退出了大家的视线。", align=True, tone=False)
[('然', 'ran'), ('而', 'er'), (',', ','), ('他', 'ta'), ('红', 'hong'), ('了', 'le'), ('2', '2'), ('0', '0'), ('年', 'nian'), ...]
>>> g2p_ja = Pororo(task="g2p", lang="ja")
>>> g2p_ja("pythonが大好きです")
'python ga daisuki desu'
>>> g2p_ja("pythonが大好きです", align=True)
[('python', 'python'), ('が', 'ga'), ('大好き', 'daisuki'), ('です', 'desu')]
static get_available_langs()[source]
static get_available_models()[source]
load(device: str)[source]

Load user-selected task-specific model

Parameters

device (str) – device information

Returns

User-selected task-specific model

Return type

object

class pororo.tasks.phoneme_conversion.PororoG2PKo(model, config)[source]

Bases: pororo.tasks.utils.base.PororoSimpleBase

predict(text: str, **kwargs) → Union[List, str][source]

Conduct grapheme to phoneme conversion

Parameters
  • text (str) – input sentence to be converted to phoneme

  • align (bool) – whether to align the result

Returns

converted phoneme sentence

Return type

str

class pororo.tasks.phoneme_conversion.PororoG2PEn(model, config)[source]

Bases: pororo.tasks.utils.base.PororoSimpleBase

predict(text: str, **kwargs)str[source]

Conduct grapheme to phoneme conversion

Parameters

sent (str) – input sentence to be converted to phoneme

Returns

converted phoneme sentence

Return type

str

class pororo.tasks.phoneme_conversion.PororoG2PZh(model, config)[source]

Bases: pororo.tasks.utils.base.PororoSimpleBase

predict(text: str, **kwargs) → Union[List, str][source]

Conduct grapheme to phoneme conversion

Parameters
  • text (str) – input sentence to be converted to phoneme

  • align (bool) – whether to align the result

  • tone (bool) – whether to show chinese tone

Returns

converted phoneme sentence

Return type

str

class pororo.tasks.phoneme_conversion.PororoG2PJa(tagger, romanize, config)[source]

Bases: pororo.tasks.utils.base.PororoSimpleBase

predict(text: str, **kwargs)[source]

Conduct grapheme to phoneme conversion

Parameters
  • text (str) – input sentence to be converted to phoneme

  • align (bool) – whether to align the result

Returns

converted phoneme sentence list

Return type

List[str]