Example #1
0
    def download_public_assistant(url, force_download=False):
        message = pp.ConsoleMessage(
            "Downloading assistant from {}".format(url))
        message.start()

        if not force_download and AssistantFetcher.exists_cached_from_url(url):
            message.done()
            pp.psubsuccess(
                "Using cached version from {}".format(SNIPS_CACHE_DIR))
            AssistantFetcher.copy_to_temp_assistant_from_url(url)
            return

        try:
            content = fetch_url(url)
            message.done()
        except:
            raise AssistantFetcherException(
                "Error downloading assistant. Please make sure the assistant URL is correct"
            )

        filepath = AssistantFetcher.get_assistant_cache_path_from_url(url)
        message = pp.ConsoleMessage(
            "Saving assistant to {}".format(SNIPS_CACHE_DIR))
        message.start()
        write_binary_file(filepath, content)
        message.done()
        AssistantFetcher.copy_to_temp_assistant_from_url(url)
Example #2
0
    def install_from_params(microphone_id,
                            update_asoundconf,
                            params_list=None,
                            params_dict=None,
                            silent=False):
        MicrophoneInstaller.print_start(microphone_id, silent)

        if not is_raspi_os():
            raise MicrophoneInstallerWarning(
                "System is not Raspberry Pi. Skipping microphone setup")

        if update_asoundconf:
            message = pp.ConsoleMessage(
                "Copying asound configuration to {}".format(
                    ASOUNDCONF_DEST_PATH))
            message.start()
            MicrophoneSetup.setup_asoundconf(microphone_id)
            message.done()

        if microphone_id == 'respeaker':
            message = pp.ConsoleMessage("Installing ReSpeaker drivers")
            message.start()
            try:
                respeaker_params = MicrophoneInstaller.normalize_respeaker_params(
                    params_list=params_list, params_dict=params_dict)
                RespeakerMicrophoneSetup.setup(respeaker_params['vendorId'],
                                               respeaker_params['productId'])
                message.done()
            except MicrophoneInstallerException as e:
                message.error()
                raise MicrophoneInstallerException(str(e))

        MicrophoneInstaller.print_done(silent)
Example #3
0
    def download_console_assistant(aid,
                                   email=None,
                                   password=None,
                                   force_download=False):
        start_message = "Fetching assistant $GREEN{}$RESET from the Snips Console".format(
            aid)

        if not force_download and AssistantFetcher.exists_cached_from_assistant_id(
                aid):
            pp.psubsuccess(start_message)
            pp.psubsuccess("Using cached version: {}".format(
                AssistantFetcher.get_assistant_cache_path_from_assistant_id(
                    aid)))
            AssistantFetcher.copy_to_temp_assistant_from_assistant_id(aid)
            return

        token = Cache.get_login_token()
        if token is None:
            token = AssistantFetcher.get_token(email=email, password=password)

        message = pp.ConsoleMessage(start_message)
        message.start()
        try:
            content = AssistantFetcher.download_console_assistant_only(
                aid, token)
            message.done()
        except Exception as e:
            message.error()
            Logout.logout()
            token = AssistantFetcher.get_token(email=email, password=password)
            message = pp.ConsoleMessage(
                "Retrying to fetch assistant $GREEN{}$RESET from the Snips Console"
                .format(aid))
            message.start()
            try:
                content = AssistantFetcher.download_console_assistant_only(
                    aid, token)
                message.done()
            except Exception:
                message.error()
                raise AssistantFetcherException(
                    "Error fetching assistant from the console. Please make sure the ID is correct, and that you are signed in"
                )

        filepath = AssistantFetcher.get_assistant_cache_path_from_assistant_id(
            aid)
        message = pp.ConsoleMessage("Saving assistant to {}".format(filepath))
        message.start()
        write_binary_file(filepath, content)
        message.done()
        AssistantFetcher.copy_to_temp_assistant_from_assistant_id(aid)
Example #4
0
    def load(file_path=None, generate_classes=True):
        pp.pcommand("Loading assistant")

        if file_path is None:
            file_path = AssistantFetcher.SNIPS_TEMP_ASSISTANT_PATH

        message = pp.ConsoleMessage("Loading assistant from file {}".format(file_path))
        message.start()

        if file_path is not None and not file_exists(file_path):
            message.error()
            raise AssistantLoaderException("Error loading assistant: file {} not found".format(file_path))

        if is_raspi_os():
            if not Snips.is_installed():
                message.error()
                raise AssistantLoaderException("Error: loading an assistant requires the Snips platform to be installed. Please run 'curl https://install.snips.ai -sSf | sh' to install the Snips Platform")
            Snips.load_assistant(file_path)

        message.done()

        if generate_classes:
            AssistantLoader.generate_intent_classes(file_path)

        pp.psuccess("Assistant has been successfully loaded")
Example #5
0
 def generate_intent_classes(file_path):
     message = pp.ConsoleMessage("Generating classes from assistant model")
     message.start()
     try:
         shutil.rmtree(SNIPS_CACHE_INTENTS_DIR)
     except Exception:
         pass
     IntentClassGenerator().generate(file_path, SNIPS_CACHE_INTENTS_DIR)
     message.done()
Example #6
0
    def install_node():
        pp.psubmessage("Node is not available. Installing node.", indent=True)
        message = pp.ConsoleMessage("Removing previous version of Node")
        message.start()
        try:
            execute_command("sudo apt-get -y remove nodejs nodejs-legacy npm")
            message.done()
        except:
            message.error()
            pass


        deb_file = "node_latest_armhf.deb"
        deb_url = "http://node-arm.herokuapp.com/node_latest_armhf.deb"
        
        message = pp.ConsoleMessage("Downloading Raspbian-compatible version of Node")
        message.start()

        try:
            download_file(deb_url, deb_file)
            message.done()
        except:
            message.error()
            raise BluetoothInstallerException("Error: failed to download compatible version of Node")


        message = pp.ConsoleMessage("Installing Node")
        message.start()
        try:
            execute_command("sudo dpkg -i {}".format(deb_file))
            message.done()
        except:
            message.error()
            raise BluetoothInstallerException("Error: installing Node. Please install Node manually")

        try:
            remove_file(filename)
        except:
            pass

        pp.psuccess("Successfully installed Node")
Example #7
0
    def install_from_params(speaker_id,
                            update_asoundconf,
                            params_list=None,
                            params_dict=None,
                            silent=False):
        SpeakerInstaller.print_start(speaker_id, silent)

        if not is_raspi_os():
            raise SpeakerInstallerWarning(
                "System is not Raspberry Pi. Skipping speaker setup")

        message = pp.ConsoleMessage("Installing driver")
        message.start()
        SpeakerSetup.setup_driver(speaker_id)
        message.done()

        if update_asoundconf:
            message = pp.ConsoleMessage(
                "Copying asound.conf to {}".format(ASOUNDCONF_DEST_PATH))
            message.start()
            SpeakerSetup.setup_asoundconf(speaker_id)
            message.done()

        SpeakerInstaller.print_done(silent)
Example #8
0
    def install(force_download=False):
        pp.pcommand("Setting up Bluetooth")

        if not is_raspi_os():
            raise BluetoothInstallerException("Error: Bluetooth is only available on Raspberry Pi")

        if not is_node_available():
            BluetoothInstaller.install_node()
        
        if force_download or not BluetoothInstaller.is_snips_mqtt_relay_installed():
            message = pp.ConsoleMessage("Installing Node module $GREEN{}$RESET".format(BluetoothInstaller.SNIPS_MQTT_RELAY_MODULE_NAME))
            message.start()
            try:
                execute_command("sudo npm install --no-cache --prefix={} {}".format(NODE_MODULES_PARENT_DIR, BluetoothInstaller.SNIPS_MQTT_RELAY_MODULE_NAME), True)
                message.done()
            except:
                message.error()
                raise BluetoothInstallerException("Error: Error installing Bluetooth module {}. Please install it manually".format(BluetoothInstaller.SNIPS_MQTT_RELAY_MODULE_NAME))

        pp.psuccess("Bluetooth is successfully installed")
Example #9
0
    def copy_local_file(file_path, silent=False):
        if not silent:
            message = pp.ConsoleMessage("Copying assistant {} to {}".format(
                file_path, AssistantFetcher.SNIPS_TEMP_ASSISTANT_PATH))
            message.start()

        error = None
        if not file_exists(file_path):
            error = "Error: failed to locate file {}".format(file_path)
        else:
            try:
                shutil.copy2(file_path,
                             AssistantFetcher.SNIPS_TEMP_ASSISTANT_PATH)
            except Exception as e:
                error = "Error: failed to copy file {}. Make sure you have write permissions to {}".format(
                    file_path, AssistantFetcher.SNIPS_TEMP_ASSISTANT_PATH)

        if error is not None:
            if not silent:
                message.error()
            raise AssistantFetcherException(error)
        else:
            if not silent:
                message.done()