def compile(words, dict_filename, langmodel_filename): """ Writes the given list of words out as dictionary.dic and languagemodel.ml, for use as parameters in Mic """ sentences_file = tmp_path('sentences.txt') idgram_file = tmp_path('temp.idgram') words = [w.upper() for w in words] words = list(set(words)) # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dict_filename, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences_file, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model os.system( "text2idngram -vocab {sentences} < {sentences} -idngram {idgram}".format( sentences=sentences_file, idgram=idgram_file)) os.system( "idngram2lm -idngram {idgram} -vocab {sentences} -arpa {langmodel}".format( idgram=idgram_file, sentences=sentences_file, langmodel=langmodel_filename)) return True
def compile(sentences, dictionary, languagemodel): """ Gets the words and creates the dictionary """ modules = Brain.get_modules() words = [] for module in modules: words.extend(module.WORDS) # for spotify module words.extend(["MUSIC", "SPOTIFY"]) words = list(set(words)) # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dictionary, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model text2lm(sentences, languagemodel)
def __init__(self, PERSONA, mic): self.persona = PERSONA # self.mic - we're actually going to ignore the mic they passed in self.music = Music() # index spotify playlists into new dictionary and language models original = self.music.get_soup_playlist( ) + ["STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS", "LOUDER", "SOFTER", "LOWER", "HIGHER", "VOLUME", "PLAYLIST"] pronounced = g2p.translateWords(original) zipped = zip(original, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open("dictionary_spotify.dic", "w") as f: f.write("\n".join(lines) + "\n") with open("sentences_spotify.txt", "w") as f: f.write("\n".join(original) + "\n") f.write("<s> \n </s> \n") f.close() # make language model os.system( "text2idngram -vocab sentences_spotify.txt < sentences_spotify.txt -idngram spotify.idngram") os.system( "idngram2lm -idngram spotify.idngram -vocab sentences_spotify.txt -arpa languagemodel_spotify.lm") # create a new mic with the new music models self.mic = Mic( speaker.newSpeaker(), stt.PocketSphinxSTT(lmd_music="languagemodel_spotify.lm", dictd_music="dictionary_spotify.dic"), stt.PocketSphinxSTT(lmd_music="languagemodel_spotify.lm", dictd_music="dictionary_spotify.dic") )
def __init__(self, PERSONA, mic): self.persona = PERSONA # self.mic - we're actually going to ignore the mic they passed in self.music = Music() # index spotify playlists into new dictionary and language models original = self.music.get_soup_playlist() + [ "STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS", "LOUDER", "SOFTER", "LOWER", "HIGHER", "VOLUME", "PLAYLIST" ] pronounced = g2p.translateWords(original) zipped = zip(original, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open("dictionary_spotify.dic", "w") as f: f.write("\n".join(lines) + "\n") with open("sentences_spotify.txt", "w") as f: f.write("\n".join(original) + "\n") f.write("<s> \n </s> \n") f.close() # make language model os.system( "text2idngram -vocab sentences_spotify.txt < sentences_spotify.txt -idngram spotify.idngram" ) os.system( "idngram2lm -idngram spotify.idngram -vocab sentences_spotify.txt -arpa languagemodel_spotify.lm" ) # create a new mic with the new music models self.mic = Mic("languagemodel.lm", "dictionary.dic", "languagemodel_persona.lm", "dictionary_persona.dic", "languagemodel_spotify.lm", "dictionary_spotify.dic")
def __init__(self, PERSONA, mic, mpdwrapper): self._logger = logging.getLogger(__name__) self.persona = PERSONA # self.mic - we're actually going to ignore the mic they passed in self.music = mpdwrapper # index spotify playlists into new dictionary and language models original = [ "STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS", "LOUDER", "SOFTER", "LOWER", "HIGHER", "VOLUME", "PLAYLIST" ] + self.music.get_soup_playlist() pronounced = g2p.translateWords(original) zipped = zip(original, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open("dictionary_spotify.dic", "w") as f: f.write("\n".join(lines) + "\n") with open("sentences_spotify.txt", "w") as f: f.write("\n".join(original) + "\n") f.write("<s> \n </s> \n") f.close() # make language model os.system("text2idngram -vocab sentences_spotify.txt < " + "sentences_spotify.txt -idngram spotify.idngram") os.system("idngram2lm -idngram spotify.idngram -vocab " + "sentences_spotify.txt -arpa languagemodel_spotify.lm") # create a new mic with the new music models self.mic = Mic( mic.speaker, mic.passive_stt_engine, stt.PocketSphinxSTT(lmd_music="languagemodel_spotify.lm", dictd_music="dictionary_spotify.dic"))
def compile(sentences, dictionary, languagemodel): """ Gets the words and creates the dictionary """ m = [os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname("../client/modules/") + "/*.py")] words = [] for module_name in m: try: exec("import %s" % module_name) eval("words.extend(%s.WORDS)" % module_name) except: pass # module probably doesn't have the property words = list(set(words)) # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dictionary, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model text2lm(sentences, languagemodel)
def compile(sentences, dictionary, languagemodel): """ Gets the words and creates the dictionary """ m = [ os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname("../client/modules/") + "/*.py") ] words = [] for module_name in m: try: exec("import %s" % module_name) eval("words.extend(%s.WORDS)" % module_name) except: pass # module probably doesn't have the property words = list(set(words)) # for spotify module words.extend(["MUSIC", "SPOTIFY"]) # for training module words.extend([ "SIXTEEN", "SEVENTEEN", "EIGTHTEEN", "NINETEEN", "TWENTY", "TWENTYONE", "TWENTYTWO", "TWENTYTHREE", "TWENTYFOUR", "TWENTYFIVE", "TWENTYSIX" ]) # for cooking module words.extend(["LASAGNA", "SPAGHETTI", "FRENCH", "FRIES"]) # for alarm module words.extend(["ONE", "FIVE", "SECONDS", "MINUTES"]) # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dictionary, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model text2lm(sentences, languagemodel)
def create_dict(words, output_file): """ Creates the dictionary from words """ # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(output_file, "w") as f: for line in lines: f.write("%s\n" % line)
def compile(sentences, dictionary, languagemodel): """ Gets the words and creates the dictionary """ m = [os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname("../client/modules/") + "/*.py")] words = [] for module_name in m: try: exec("import %s" % module_name) eval("words.extend(%s.WORDS)" % module_name) except: pass # module probably doesn't have the property words = list(set(words)) # for spotify module words.extend(["MUSIC", "SPOTIFY"]) # for training module words.extend(["SIXTEEN","SEVENTEEN","EIGTHTEEN","NINETEEN","TWENTY", "TWENTYONE", "TWENTYTWO","TWENTYTHREE","TWENTYFOUR","TWENTYFIVE","TWENTYSIX"]) # for cooking module words.extend(["LASAGNA", "SPAGHETTI", "FRENCH", "FRIES"]) # for alarm module words.extend(["ONE", "FIVE", "SECONDS", "MINUTES"]) # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dictionary, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model text2lm(sentences, languagemodel)
def compile(sentences, dictionary, languagemodel, words): # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dictionary, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model text2lm(sentences, languagemodel)
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"]) words.extend(["EXIT","QUIT"]) # 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")
def compile(sentences, dictionary, languagemodel): """ Gets the words and creates the dictionary """ m = [ os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname("../client/modules/") + "/*.py") ] words = [] for module_name in m: try: exec("import %s" % module_name) eval("words.extend(%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(dictionary, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model text2lm(sentences, languagemodel)
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")
def compile(words, dict_filename, langmodel_filename): """ Writes the given list of words out as dictionary.dic and languagemodel.ml, for use as parameters in Mic """ sentences_file = tmp_path('sentences.txt') idgram_file = tmp_path('temp.idgram') words = [w.upper() for w in words] words = list(set(words)) # create the dictionary pronounced = g2p.translateWords(words) zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dict_filename, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences_file, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model os.system( "text2idngram -vocab {sentences} < {sentences} -idngram {idgram}". format(sentences=sentences_file, idgram=idgram_file)) os.system( "idngram2lm -idngram {idgram} -vocab {sentences} -arpa {langmodel}". format(idgram=idgram_file, sentences=sentences_file, langmodel=langmodel_filename)) return True
def compileLocations(sentences, dictionary, languagemodel): words = [] words = getlocationOptions(); words = list(set(words)) print words # create the dictionary pronounced = g2p.translateWords(words) print pronounced zipped = zip(words, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open(dictionary, "w") as f: f.write("\n".join(lines) + "\n") # create the language model with open(sentences, "w") as f: f.write("\n".join(words) + "\n") f.write("<s> \n </s> \n") f.close() # make language model text2lm(sentences, languagemodel)
def testTranslateWords(self): words = self.translations.keys() # preserve ordering translations = [self.translations[w] for w in words] self.assertEqual(g2p.translateWords(words), translations)
self.music.play() if __name__ == "__main__": """ Indexes the Spotify music library to dictionary_spotify.dic and languagemodel_spotify.lm """ musicmode = MusicMode("JASPER", None) music = musicmode.music original = music.get_soup() + [ "STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS", "LOUDER", "SOFTER" ] pronounced = g2p.translateWords(original) zipped = zip(original, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open("dictionary_spotify.dic", "w") as f: f.write("\n".join(lines) + "\n") with open("sentences_spotify.txt", "w") as f: f.write("\n".join(original) + "\n") f.write("<s> \n </s> \n") f.close() with open("sentences_spotify_separated.txt", "w") as f: f.write("\n".join(music.get_soup_separated()) + "\n") f.write("<s> \n </s> \n") f.close()
self.delegateInput(input) else: self.mic.say("Pardon?") self.music.play() if __name__ == "__main__": """ Indexes the Spotify music library to dictionary_spotify.dic and languagemodel_spotify.lm """ musicmode = MusicMode("JASPER", None) music = musicmode.music original = music.get_soup() + ["STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS", "LOUDER", "SOFTER"] pronounced = g2p.translateWords(original) zipped = zip(original, pronounced) lines = ["%s %s" % (x, y) for x, y in zipped] with open("dictionary_spotify.dic", "w") as f: f.write("\n".join(lines) + "\n") with open("sentences_spotify.txt", "w") as f: f.write("\n".join(original) + "\n") f.write("<s> \n </s> \n") f.close() with open("sentences_spotify_separated.txt", "w") as f: f.write("\n".join(music.get_soup_separated()) + "\n") f.write("<s> \n </s> \n") f.close()