Пример #1
0
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
Пример #2
0
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)
Пример #3
0
    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")
        )
Пример #4
0
    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")
Пример #5
0
    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"))
Пример #6
0
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)
Пример #7
0
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 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)
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
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)
Пример #13
0
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")
Пример #14
0
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)
Пример #15
0
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")
Пример #16
0
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)
Пример #18
0
 def testTranslateWords(self):
     words = self.translations.keys()
     # preserve ordering
     translations = [self.translations[w] for w in words]
     self.assertEqual(g2p.translateWords(words), translations)
Пример #19
0
 def testTranslateWords(self):
     words = self.translations.keys()
     # preserve ordering
     translations = [self.translations[w] for w in words]
     self.assertEqual(g2p.translateWords(words), translations)
Пример #20
0
                    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()
Пример #21
0
                    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()