diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-03-30 16:03:44 -0400 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-03-30 16:03:44 -0400 |
| commit | d31fabf8cff5dae02e3fc759a4203bd374dddc99 (patch) | |
| tree | 888ec4e6d98154f862a3b9cd17a3394b657bc02e /boot/vocabcompiler.py | |
| parent | 4182b5e096e081158dddd4ad5d031af94fcc63de (diff) | |
| download | jasper-client-d31fabf8cff5dae02e3fc759a4203bd374dddc99.tar.gz jasper-client-d31fabf8cff5dae02e3fc759a4203bd374dddc99.zip | |
Initial commit
Diffstat (limited to 'boot/vocabcompiler.py')
| -rw-r--r-- | boot/vocabcompiler.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/boot/vocabcompiler.py b/boot/vocabcompiler.py new file mode 100644 index 0000000..d5455d3 --- /dev/null +++ b/boot/vocabcompiler.py @@ -0,0 +1,52 @@ +""" + This iterates over all the WORDS variables in the modules and creates a dictionary that the client program will use +""" + +import os +import sys +import pkgutil + +lib_path = os.path.abspath('../client') +sys.path.append(lib_path) +import modules +import g2p + + +def compile(): + """ + Gets the words and creates the dictionary + """ + + m = dir(modules) + + words = [] + for module_name in m: + try: + eval("words.extend(modules.%s.WORDS)" % module_name) + except: + pass # module probably doesn't have the property + + words = list(set(words)) + + # for spotify module + words.extend(["MUSIC","SPOTIFY"]) + + # create the dictionary + pronounced = g2p.translateWords(words) + zipped = zip(words, pronounced) + lines = ["%s %s" % (x, y) for x, y in zipped] + + with open("../client/dictionary.dic", "w") as f: + f.write("\n".join(lines) + "\n") + + # create the language model + with open("../client/sentences.txt", "w") as f: + f.write("\n".join(words) + "\n") + f.write("<s> \n </s> \n") + f.close() + + # make language model + os.system( + "text2idngram -vocab ../client/sentences.txt < ../client/sentences.txt -idngram temp.idngram") + os.system( + "idngram2lm -idngram temp.idngram -vocab ../client/sentences.txt -arpa ../client/languagemodel.lm") |
