Package: pronunciation-dictionary
pronunciation-dictionaryLibrary to save and load pronunciation dictionaries (language-independent).FeaturesLoad dictionary from file or URLParsing ofline commentspronunciation commentsnumbers indicating alternative pronunciations for wordsweightsMultiprocessing for faster deserializationSave dictionary to fileincluding numbers for alternative pronunciationsinclude weightsset word/weight/pronunciation separatorSelect pronunciation viafirst/lastlongest/shortesthighest/lowest weightrandomweightGet phoneme setExample dictionaries and deserialization argumentsMontreal Forced Aligner dictionariesencoding: "UTF-8"CMUencoding: "ISO-8859-1"consider_numbers: Trueconsider_pronunciation_comments: TrueLibriSpeechencoding: "UTF-8"ProsodylabOld:CMU 0.7bencoding: "ISO-8859-1"consider_comments: Trueconsider_numbers: TrueExcerpt from CMU (as example)a.d. EY2 D IY1
a.m. EY2 EH1 M
a.s EY1 Z
aaa T R IH2 P AH0 L EY1
aaberg AA1 B ER0 G
aachen AA1 K AH0 N
aachener AA1 K AH0 N ER0
aaker AA1 K ER0
aalborg AO1 L B AO0 R G # place, danish
aalborg(2) AA1 L B AO0 R GInstallationpipinstallpronunciation-dictionary--userUsagefrompronunciation_dictionaryimportload_dict,save_dict,MultiprocessingOptions,DeserializationOptions,SerializationOptionsExamplefrompathlibimportPathfrompronunciation_dictionaryimport(DeserializationOptions,MultiprocessingOptions,SerializationOptions,get_phoneme_set,load_dict_from_url,save_dict)dictionary=load_dict_from_url("https://raw.githubusercontent.com/cmusphinx/cmudict/master/cmudict.dict","ISO-8859-1",DeserializationOptions(False,True,True,False),MultiprocessingOptions(4,None,10000))phoneme_set=get_phoneme_set(dictionary)print(phoneme_set)# {'Z', 'EY1', 'AH0', 'F', 'AE0', 'UW0', 'CH', 'G', 'V', 'AY1', 'AO2', 'ZH', 'AA1', 'IY1', 'AW0', 'T', 'TH', 'AY2', 'DH', 'S', 'W', 'ER1', 'AA2', 'AE2', 'AE1', 'AW1', 'UW1', 'AH1', 'Y', 'EY2', 'AO0', 'OW2', 'OY2', 'IY2', 'JH', 'N', 'NG', 'P', 'IH2', 'M', 'OW0', 'L', 'UH1', 'IY0', 'EY0', 'HH', 'IH0', 'SH', 'AH2', 'AW2', 'EH2', 'OW1', 'D', 'R', 'IH1', 'AO1', 'B', 'UH2', 'UH0', 'ER0', 'UW2', 'ER2', 'EH0', 'AY0', 'AA0', 'EH1', 'OY1', 'OY0', 'K'}pronunciations_distmantle=dictionary.get("dismantle")forpronunciation,weightinpronunciations_distmantle.items():print(pronunciation,weight)# ('D', 'IH0', 'S', 'M', 'AE1', 'N', 'T', 'AH0', 'L') 1.0# ('D', 'IH0', 'S', 'M', 'AE1', 'N', 'AH0', 'L') 1.0save_dict(dictionary,Path("/tmp/cmu.dict"),"UTF-8",SerializationOptions("DOUBLE-SPACE",False,False))head/tmp/cmu.dict# 'bout  B AW1 T# 'cause  K AH0 Z# 'course  K AO1 R S# 'cuse  K Y UW1 Z# 'em  AH0 M# 'frisco  F R IH1 S K OW0# 'gain  G EH1 N# 'kay  K EY1# 'm  AH0 M# 'n  AH0 NRoadmapreplaceSerializationOptions,DeserializationOptionsandMultiprocessingOptionswith parametersadd default parameter valuesadd more testsDevelopment setup# updatesudoaptupdate# install Python 3.8, 3.9, 3.10 & 3.11 for ensuring that tests can be runsudoaptinstallpython3-pip\python3.8python3.8-devpython3.8-distutilspython3.8-venv\python3.9python3.9-devpython3.9-distutilspython3.9-venv\python3.10python3.10-devpython3.10-distutilspython3.10-venv\python3.11python3.11-devpython3.11-distutilspython3.11-venv\python3.12python3.12-devpython3.12-distutilspython3.12-venv# install pipenv for creation of virtual environmentspython3.8-mpipinstallpipenv--user# check out repogitclonehttps://github.com/stefantaubert/pronunciation-dictionary.gitcdpronunciation-dictionary# create virtual environmentpython3.8-mpipenvinstall--devRunning the tests# first install the tool like in "Development setup"# then, navigate into the directory of the repo (if not already done)cdpronunciation-dictionary# activate environmentpython3.8-mpipenvshell# run teststoxFinal lines of test result output:py38: commands succeeded
  py39: commands succeeded
  py310: commands succeeded
  py311: commands succeeded
  py312: commands succeeded
  congratulations :)LicenseMIT LicenseAcknowledgmentsFunded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) – Project-ID 416228727 – CRC 1410CitationIf you want to cite this repo, you can use this BibTeX-entry generated by GitHub (seeAbout => Cite this repository).Taubert, S. (2024). pronunciation-dictionary (Version 0.0.6) [Computer software]. https://doi.org/10.5281/zenodo.7386813