MCPcopy Create free account
hub / github.com/jasperproject/jasper-client / MusicMode

Class MusicMode

client/modules/MPDControl.py:64–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63# The interesting part
64class MusicMode(object):
65
66 def __init__(self, PERSONA, mic, mpdwrapper):
67 self._logger = logging.getLogger(__name__)
68 self.persona = PERSONA
69 # self.mic - we're actually going to ignore the mic they passed in
70 self.music = mpdwrapper
71
72 # index spotify playlists into new dictionary and language models
73 phrases = ["STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS",
74 "LOUDER", "SOFTER", "LOWER", "HIGHER", "VOLUME",
75 "PLAYLIST"]
76 phrases.extend(self.music.get_soup_playlist())
77
78 music_stt_engine = mic.active_stt_engine.get_instance('music', phrases)
79
80 self.mic = Mic(mic.speaker,
81 mic.passive_stt_engine,
82 music_stt_engine)
83
84 def delegateInput(self, input):
85
86 command = input.upper()
87
88 # check if input is meant to start the music module
89 if "PLAYLIST" in command:
90 command = command.replace("PLAYLIST", "")
91 elif "STOP" in command:
92 self.mic.say("Stopping music")
93 self.music.stop()
94 return
95 elif "PLAY" in command:
96 self.mic.say("Playing %s" % self.music.current_song())
97 self.music.play()
98 return
99 elif "PAUSE" in command:
100 self.mic.say("Pausing music")
101 # not pause because would need a way to keep track of pause/play
102 # state
103 self.music.stop()
104 return
105 elif any(ext in command for ext in ["LOUDER", "HIGHER"]):
106 self.mic.say("Louder")
107 self.music.volume(interval=10)
108 self.music.play()
109 return
110 elif any(ext in command for ext in ["SOFTER", "LOWER"]):
111 self.mic.say("Softer")
112 self.music.volume(interval=-10)
113 self.music.play()
114 return
115 elif "NEXT" in command:
116 self.mic.say("Next song")
117 self.music.play() # backwards necessary to get mopidy to work
118 self.music.next()
119 self.mic.say("Playing %s" % self.music.current_song())
120 return
121 elif "PREVIOUS" in command:

Callers 1

handleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected