コード例 #1
0
ファイル: main.py プロジェクト: NadirJ/squeeze-alexa
 def on_play_artist(self, intent, session, pid=None):
     server = self._server
     try:
         artist = intent['slots']['Artist']['value']
         print_d("Extracted artist slot: {}".format(artist))
     except KeyError:
         print_d("Couldn't process artist from: {intent}", intent=intent)
         return speech_response(text=_("Couldn't process that artist. "))
     else:
         matched_artists = server.search_for_artist(artist)
         print_d(
             "Found Matching artists on squeezebox server "
             "{matched_artists}",
             matched_artists=matched_artists)
         try:
             server.play_artist(matched_artists[0], player_id=pid)
             artist_name = sanitise_text(matched_artists[0])
             text = _(
                 "Playing albums by \"{artist_name}\" on squeezebox".format(
                     artist_name=artist_name))
             return self.smart_response(text=text, speech=text)
         except KeyError:
             return speech_response(
                 text=_("Couldn't find the artist on squeezebox. "))
     raise ValueError("Don't understand intent '{}'".format(intent))
コード例 #2
0
ファイル: main.py プロジェクト: NadirJ/squeeze-alexa
 def on_play_playlist(self, intent, session, pid=None):
     server = self._server
     try:
         slot = intent['slots']['Playlist']['value']
         print_d("Extracted playlist slot: {slot}", slot=slot)
     except KeyError:
         print_d("Couldn't process playlist from: {intent}", intent=intent)
         if not server.playlists:
             return speech_response(text=_("There are no playlists"))
         pl = random.choice(server.playlists)
         text = _("Didn't hear a playlist there. "
                  "You could try the \"{name}\" playlist?").format(name=pl)
         return speech_response(text=text)
     else:
         if not server.playlists:
             return speech_response(text=_("No Squeezebox playlists found"))
         result = process.extractOne(slot, server.playlists)
         print_d("{guess} was the best guess for '{slot}' from {choices}",
                 guess=str(result),
                 slot=slot,
                 choices=server.playlists)
         if result and int(result[1]) >= MinConfidences.PLAYLIST:
             pl = result[0]
             server.playlist_resume(pl, player_id=pid)
             name = sanitise_text(pl)
             return self.smart_response(
                 speech=_("Playing \"{name}\" playlist").format(name=name),
                 text=_("Playing \"{name}\" playlist").format(name=name))
         pl = random.choice(server.playlists)
         template = _("Couldn't find a playlist matching \"{name}\"."
                      "How about the \"{suggestion}\" playlist?")
         return speech_response(template.format(name=slot, suggestion=pl))
コード例 #3
0
ファイル: main.py プロジェクト: NadirJ/squeeze-alexa
    def on_select_player(self, intent, session, pid=None):
        srv = self._server
        srv.refresh_status()

        # Do it again, yes, but not defaulting this time.
        pid = self.player_id_from(intent, defaulting=False)
        if pid:
            player = srv.players[pid]
            srv.cur_player_id = player.id
            text = _("Selected {player}").format(player=player.name)
            title = _("Selected player {player}").format(player=player)
            return speech_response(title=title,
                                   text=text,
                                   store={"player_id": pid})
        speech = (_("I only found these players: {players}. "
                    "Could you try again?").format(
                        players=english_join(srv.player_names)))
        reprompt = (_("You can select a player by saying \"{utterance}\" "
                      "and then the player name.").format(
                          utterance=Utterances.SELECT_PLAYER))
        try:
            player = intent['slots']['Player']['value']
            title = (_("No player called \"{name}\"").format(name=player))
        except KeyError:
            title = "Didn't recognise a player name"
        return speech_response(title,
                               speech,
                               reprompt_text=reprompt,
                               end=False)
コード例 #4
0
ファイル: main.py プロジェクト: jpfarcy/squeeze-alexa
    def on_launch(self, launch_request, session):

        print_d("Entering interactive mode for sessionId={}",
                session['sessionId'])
        speech_output = _("Squeezebox is online. Please try some commands.")
        reprompt_text = _("Try resume, pause, next, previous, play some jazz, "
                          "or ask Squeezebox to turn it up or down")
        return speech_response("Welcome", speech_output, reprompt_text,
                               end=False)
コード例 #5
0
ファイル: handler.py プロジェクト: jpfarcy/squeeze-alexa
def lambda_handler(event, context):
    """ Route the incoming request based on type (LaunchRequest, IntentRequest,
    etc.) The JSON body of the request is provided in the event parameter.
    """
    sqa = SqueezeAlexa(app_id=APPLICATION_ID)
    try:
        return sqa.handle(event, context)
    except Exception as e:
        if not settings.USE_SPOKEN_ERRORS:
            raise e
        # Work with AWS stack-trace log magic
        print_w(format_exc().replace('\n', '\r'))
        error = str(e.msg if hasattr(e, "msg") else e)
        return speech_response(title=_("All went wrong"),
                               text=_("Oh dear: {type}. {message}").format(
                                   type=type(e).__name__, message=error))
コード例 #6
0
ファイル: handler.py プロジェクト: dougadams/squeeze-alexa
def lambda_handler(event, context, server=None):
    """ Route the incoming request based on type (LaunchRequest, IntentRequest,
    etc.) The JSON body of the request is provided in the event parameter.
    """
    try:
        sqa = SqueezeAlexa(server=server or get_server(),
                           app_id=SKILL_SETTINGS.application_id)
        return sqa.handle(event, context)
    except Exception as e:
        if not SKILL_SETTINGS.use_spoken_errors:
            raise e
        # Work with AWS stack-trace log magic
        print(format_exc().replace('\n', '\r'))
        error = str(e.msg if hasattr(e, "msg") else e)
        text = _("Oh dear: {type}. {message}").format(
            type=type(e).__name__, message=error)
        return speech_response(title=_("All went wrong"), text=text)
コード例 #7
0
 def smart_response(self,
                    speech=None,
                    title=None,
                    text=None,
                    reprompt_text=None,
                    end=True,
                    store=None):
     if (self.audio_enabled) and (speech):
         return speech_response(speech=speech,
                                title=title,
                                text=text,
                                reprompt_text=reprompt_text,
                                end=end,
                                store=store)
     return audio_response(speech=speech,
                           title=title,
                           text=text,
                           reprompt_text=reprompt_text,
                           end=end,
                           store=store)
コード例 #8
0
ファイル: main.py プロジェクト: NadirJ/squeeze-alexa
 def smart_response(self, title=None, text=None, speech=None):
     if self.audio_enabled:
         return speech_response(title=title or text, text=speech)
     return audio_response(speech=speech, text=text, title=title)
コード例 #9
0
ファイル: main.py プロジェクト: NadirJ/squeeze-alexa
 def on_session_ended(self, intent, session):
     print_d("Session {id} ended", id=session['sessionId'])
     speech_output = _("Hasta la vista. Baby.")
     return speech_response("Session Ended", speech_output, end=True)