17 from abc
import ABC, abstractmethod
18 from mycroft
import MycroftSkill
33 """ To integrate with the common play infrastructure of Mycroft 34 skills should use this base class and override the two methods 35 `CPS_match_query_phrase` (for checking if the skill can play the 36 utterance) and `CPS_start` for launching the media. 38 The class makes the skill available to queries from the 39 mycroft-playback-control skill and no special vocab for starting playback 48 spoken = name
or self.__class__.__name__
50 spoken.replace(
"Skill",
""))
55 """ Overrides the normal bind method. 56 Adds handlers for play:query and play:start messages allowing 57 interaction with the playback control skill. 59 This is called automatically during setup, and 60 need not otherwise be used. 69 search_phrase = message.data[
"phrase"]
73 self.bus.emit(message.response({
"phrase": search_phrase,
74 "skill_id": self.skill_id,
83 callback = result[2]
if len(result) > 2
else None 85 self.bus.emit(message.response({
"phrase": search_phrase,
86 "skill_id": self.skill_id,
87 "callback_data": callback,
92 self.bus.emit(message.response({
"phrase": search_phrase,
93 "skill_id": self.skill_id,
102 consumed_pct = len(match.split()) / len(phrase.split())
103 if consumed_pct > 1.0:
104 consumed_pct = 1.0 / consumed_pct
108 bonus = consumed_pct / 20.0
110 if level == CPSMatchLevel.EXACT:
112 elif level == CPSMatchLevel.MULTI_KEY:
114 elif level == CPSMatchLevel.TITLE:
116 elif level == CPSMatchLevel.ARTIST:
118 elif level == CPSMatchLevel.CATEGORY:
120 elif level == CPSMatchLevel.GENERIC:
126 if message.data[
"skill_id"] != self.skill_id:
129 phrase = message.data[
"phrase"]
130 data = message.data.get(
"callback_data")
133 if self.audioservice.is_playing:
134 self.audioservice.stop()
135 self.bus.emit(
Message(
"mycroft.stop"))
146 Begin playback of a media file or stream 148 Normally this method will be invoked with somthing like: 150 Advanced use can also include keyword arguments, such as: 151 self.CPS_play(url, repeat=True) 154 same as the Audioservice.play method 158 if 'utterance' not in kwargs:
160 self.audioservice.play(*args, **kwargs)
163 if self.audioservice.is_playing:
164 self.audioservice.stop()
176 Analyze phrase to see if it is a play-able phrase with this 180 phrase (str): User phrase uttered after "Play", e.g. "some music" 183 (match, CPSMatchLevel[, callback_data]) or None: Tuple containing 184 a string with the appropriate matching phrase, the PlayMatch 185 type, and optionally data to return in the callback if the 208 Begin playing whatever is specified in 'phrase' 211 phrase (str): User phrase uttered after "Play", e.g. "some music" 212 data (dict): Callback data specified in match_query_phrase() def CPS_match_query_phrase(self, phrase)
Abstract methods All of the following must be implemented by a skill that wants to act as a CommonPla...
def __handle_play_start(self, message)
def __init__(self, name=None, bus=None)
def CPS_start(self, phrase, data)
def __calc_confidence(self, match, phrase, level)
def __handle_play_query(self, message)
def CPS_play(self, args, kwargs)