diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-30 20:14:17 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-10-01 14:15:46 +0200 |
| commit | d378caee59df005e94ba6f891976ceb64c2a48d2 (patch) | |
| tree | a3c292056645e40d1385ae2a1939025554234206 /client/musicmode.py | |
| parent | 2bcceb3fe037355dbdfdc46ffbd036c7f719a7bf (diff) | |
| download | jasper-client-d378caee59df005e94ba6f891976ceb64c2a48d2.tar.gz jasper-client-d378caee59df005e94ba6f891976ceb64c2a48d2.zip | |
Remove music mode
Diffstat (limited to 'client/musicmode.py')
| -rw-r--r-- | client/musicmode.py | 183 |
1 files changed, 0 insertions, 183 deletions
diff --git a/client/musicmode.py b/client/musicmode.py deleted file mode 100644 index 900c4f1..0000000 --- a/client/musicmode.py +++ /dev/null @@ -1,183 +0,0 @@ -# -*- coding: utf-8-*- -""" - Manages the conversation -""" - -import os -from mic import Mic -import g2p -from music import * -import stt - - -class MusicMode: - - 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( - mic.speaker, - 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 delegateInput(self, input): - - command = input.upper() - - # check if input is meant to start the music module - if "PLAYLIST" in command: - command = command.replace("PLAYLIST", "") - elif "STOP" in command: - self.mic.say("Stopping music") - self.music.stop() - return - elif "PLAY" in command: - self.mic.say("Playing %s" % self.music.current_song()) - self.music.play() - return - elif "PAUSE" in command: - self.mic.say("Pausing music") - # not pause because would need a way to keep track of pause/play - # state - self.music.stop() - return - elif any(ext in command for ext in ["LOUDER", "HIGHER"]): - self.mic.say("Louder") - self.music.volume(interval=10) - self.music.play() - return - elif any(ext in command for ext in ["SOFTER", "LOWER"]): - self.mic.say("Softer") - self.music.volume(interval=-10) - self.music.play() - return - elif "NEXT" in command: - self.mic.say("Next song") - self.music.play() # backwards necessary to get mopidy to work - self.music.next() - self.mic.say("Playing %s" % self.music.current_song()) - return - elif "PREVIOUS" in command: - self.mic.say("Previous song") - self.music.play() # backwards necessary to get mopidy to work - self.music.previous() - self.mic.say("Playing %s" % self.music.current_song()) - return - - # SONG SELECTION... requires long-loading dictionary and language model - # songs = self.music.fuzzy_songs(query = command.replace("PLAY", "")) - # if songs: - # self.mic.say("Found songs") - # self.music.play(songs = songs) - - # print "SONG RESULTS" - # print "============" - # for song in songs: - # print "Song: %s Artist: %s" % (song.title, song.artist) - - # self.mic.say("Playing %s" % self.music.current_song()) - - # else: - # self.mic.say("No songs found. Resuming current song.") - # self.music.play() - - # PLAYLIST SELECTION - playlists = self.music.fuzzy_playlists(query=command) - if playlists: - self.mic.say("Loading playlist %s" % playlists[0]) - self.music.play(playlist_name=playlists[0]) - self.mic.say("Playing %s" % self.music.current_song()) - else: - self.mic.say("No playlists found. Resuming current song.") - self.music.play() - - return - - def handleForever(self): - - self.music.play() - self.mic.say("Playing %s" % self.music.current_song()) - - while True: - - try: - threshold, transcribed = self.mic.passiveListen(self.persona) - except: - continue - - if threshold: - - self.music.pause() - - input = self.mic.activeListen(MUSIC=True) - - if "close" in input.lower(): - self.mic.say("Closing Spotify") - return - - if input: - 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() - - # make language model - os.system( - "text2idngram -vocab sentences_spotify.txt < sentences_spotify_separated.txt -idngram spotify.idngram") - os.system( - "idngram2lm -idngram spotify.idngram -vocab sentences_spotify.txt -arpa languagemodel_spotify.lm") - - print "Language Model and Dictionary Done" |
