def test_stop_calls_stdin_write_with_p(self, popen_mock, shlex_mock, system_mock): popen_mock.return_value.poll.return_value = None my_pandora_player = PandoraPlayer() my_pandora_player.stop() popen_mock.return_value.stdin.write.assert_called_with(b'p\n')
def test_close_with_a_program_that_wont_close_calls_kill(self, sleep_mock, popen_mock, shlex_mock, system_mock): popen_mock.return_value.poll.return_value = None my_pandora_player = PandoraPlayer() my_pandora_player.close() self.assertTrue(popen_mock.return_value.kill.called)
def test_close_with_a_closed_program_only_calls_terminate(self, popen_mock, shlex_mock, system_mock): popen_mock.return_value.poll.return_value = "fake_value" my_pandora_player = PandoraPlayer() my_pandora_player.close() self.assertTrue(popen_mock.return_value.terminate.called) self.assertFalse(popen_mock.return_value.kill.called)
def test_stop_raises_assertion_if_process_closed(self, popen_mock, shlex_mock, system_mock): popen_mock.return_value.poll.return_value = "fake_value" my_pandora_player = PandoraPlayer() self.assertRaisesRegex( ProgramCommunicationError, "failed to send message because of Couldn't pause Pianobar", my_pandora_player.stop)
import speech_recognition as sr from command_listener.command_listener import CommandListener from action_handler.action_handler import ActionHandler, UndefinedCommandError from pandora_player.pandora_player import PandoraPlayer if __name__ == "__main__": my_muisc_player = PandoraPlayer() my_action_handler = ActionHandler(my_music_player) try: r = sr.Recognizer() with sr.Microphone() as source: my_command_listener = CommandListener() keep_listening = True while (keep_listening): try: r.adjust_for_ambient_noise(source) audio = r.listen(source) text_of_audio = r.recognize_google(audio) if (my_command_listener.command_word_present(text_of_audio) ): command_string = my_command_listener.get_command( text_of_audio) print("command word found and was " + command_string) my_action_handler.take_action(command_string) else: print("no command word relistening") except sr.UnknownValueError: print("known problem keep running") except UndefinedCommandError: print("Undefined command") finally: my_action_handler.take_action("kill pandora")