Пример #1
0
    def recognize(self):
        boundary_name = 'recognize-term'
        header = self.__header(boundary_name)

        def recognize_first_message():
            message = {
                "header": {
                    "namespace": "SpeechRecognizer",
                    "name": "Recognize",
                    "messageId": "1",
                    "dialogRequestId": "1"
                },
                "payload": {
                    "profile": "CLOSE_TALK",
                    "format": "AUDIO_L16_RATE_16000_CHANNELS_1"
                }
            }
            return message

        first_part_header = self.__message_header_first(boundary_name)
        first_part_body = self.__message_body_first([],
                                                    recognize_first_message())
        second_part_header = self.__message_header_second(boundary_name)
        second_part_body = self.__message_body_second("recording.wav")

        body = first_part_header + '\n' + json.dumps(
            first_part_body
        ) + '\n' + second_part_header + '\n' + second_part_body + self.__end_boundary(
            boundary_name)
        stream_id = self.connection.request(method="GET",
                                            url=self.__interface("events"),
                                            headers=header,
                                            body=body)
        print(stream_id)
        res = self.connection.get_response(stream_id)
        if res.status != 200 and res.status != 204:
            print(res.read())
            print("[ERROR:AVS] Bad recognize response %s" % (res.status))
            self.expect_speech = False
            audio = None

        if res.status == 204:
            print("[STATE:AVS] recognize no content")
            print(res.headers)
            print(res.read())
            # self.expect_speech = False
            audio = None
        else:
            print("[STATE:AVS] recognize audio response present")
            boundary = self.get_boundary(res)
            response_data = res.read()
            ar = self.analyze_response(boundary, response_data)
            self.change_state(ar)
            audio = ar['audio']

        player.play(audio)
Пример #2
0
def vlc():
	os.system('clear')
	track_id = request.args.get('track')
	return player.play(track_id)
Пример #3
0
 def play(self):
     """
     Play the item.
     """
     videoplayer.play(self)
Пример #4
0
 def keypress(self, size, key):
     if key == ':':
         main_frame.set_focus('footer')
         command_prompt.set_caption(':')
     if key == '/':
         main_frame.set_focus('footer')
         command_prompt.set_caption('/')
     elif key == 'j':
         self.listbox.keypress(size, 'down')
     elif key == 'k':
         self.listbox.keypress(size, 'up')
     elif key == 'g':
         try:
             self.listbox.change_focus(size, 0)
         except AttributeError:
             pass
     elif key == 'G':
         try:
             self.listbox.change_focus(size, len(self.body) - 1)
         except AttributeError:
             pass
     elif key == 'ctrl d':
         try:
             position = self.listbox.get_focus()[0].index + 5
             position = self.get_real_index(position)
             self.listbox.set_focus(position, 'above')
         except TypeError:
             pass
     elif key == 'ctrl u':
         try:
             position = self.listbox.get_focus()[0].index - 5
             if position < 0:
                 position = 0
             position = self.get_real_index(position)
             self.listbox.set_focus(position, 'below')
         except TypeError:
             pass
     elif key == 'ctrl r':
         self.clear()
     elif key == 'ctrl n':
         try:
             status_bar.set_text(' Listing next videos please wait...')
             loop.draw_screen()
             search = client.next_page()
             status_bar.set_text('')
             self.append(search)
         except TypeError:
             status_bar.set_text(' You need to search for something before you do that!')
         except socket.gaierror:
             status_bar.set_text(' You probably lost your internet connection')
             main_frame.set_focus('body')
     elif key == 'n':
         try:
             self.latest_search_position += 1
             self.listbox.set_focus(self.latest_search[self.latest_search_position])
         except IndexError:
             self.latest_search_position = 0
             self.listbox.set_focus(self.latest_search[self.latest_search_position])
         except TypeError:
             pass
     elif key == 'N':
         try:
             self.latest_search_position -= 1
             self.listbox.set_focus(self.latest_search[self.latest_search_position])
         except IndexError:
             self.latest_search_position = len(self.latest_search) - 1
             self.listbox.set_focus(self.latest_search[self.latest_search_position])
         except TypeError:
             pass
     elif key == 'a':
         player.play()
         status_bar.set_text('Playing..')
     elif key == 'z':
         player.seek(5)
         status_bar.set_text('Seeking..')
     else:
         return self.listbox.keypress(size, key)
Пример #5
0
 def play(self):
     """
     Play the item.
     """
     videoplayer.play(self)