Beispiel #1
0
def remove_wake_word(db, wake_word: WakeWord):
    """Remove a wake word and any related sample files from the database

    :param db: Database connection to the Mycroft DB
    :param wake_word: the wake word to delete
    """
    file_repository = WakeWordFileRepository(db)
    wake_word_repository = WakeWordRepository(db)
    if wake_word.id is None:
        wake_word.id = wake_word_repository.get_id(wake_word)
    for wake_word_file in file_repository.get_by_wake_word(wake_word):
        file_repository.remove(wake_word_file)
    wake_word_repository.remove(wake_word)
Beispiel #2
0
    def _get_taggable_file(self, wake_word: str,
                           session_id: str) -> TaggableFile:
        """Get a file that has still requires some tagging for a specified tag type.

        :param wake_word: the wake word being tagged by the user
        :param session_id: identifier of the user's tagging session
        :return: dataclass instance representing the file to be tagged
        """
        file_repository = WakeWordFileRepository(self.db)
        file_to_tag = file_repository.get_taggable_file(
            wake_word, len(self.tags), session_id)

        return file_to_tag
Beispiel #3
0
    def _change_wake_word_file_status(self):
        """Set the status of wake word files to "pending delete".

        Deleting all the wake word files for an account can be a time consuming
        process.  Especially if the account has contributed a lot of files.
        To keep the API call from taking too long to return, the "pending delete"
        status will be used by a nightly batch job to actually delete the files from
        the file system.
        """
        agreements = [agreement.type for agreement in self.account.agreements]
        if OPEN_DATASET in agreements:
            file_repository = WakeWordFileRepository(self.db)
            file_repository.change_account_file_status(self.account.id,
                                                       "pending delete")
def check_wake_word_file_table(context):
    """The data representing the audio file is stored correctly on the database."""
    file_repository = WakeWordFileRepository(context.db)
    wake_word = context.wake_words[context.scenario_wake_word]
    wake_word_files = file_repository.get_by_wake_word(wake_word)
    assert_that(len(wake_word_files), equal_to(1))
    wake_word_file = wake_word_files[0]
    assert_that(wake_word_file.name,
                equal_to(context.account.id + ".12345.wav"))
    assert_that(
        wake_word_file.location.directory,
        context.wake_word_dir.joinpath(
            context.scenario_wake_word.replace(" ", "-")),
    )
    assert_that(wake_word_file.location.server, equal_to("127.0.0.1"))
Beispiel #5
0
    def _add_wake_word_file(self, account: Account, file_name: str):
        """Add the sample to the database for reference and classification.

        :param account: the account from which sample originated
        :param file_name: name of the audio file saved to file system
        """
        sample = WakeWordFile(
            account_id=account.id,
            location=self.file_location,
            name=file_name,
            origin="mycroft",
            submission_date=datetime.utcnow().date(),
            wake_word=self.wake_word,
        )
        file_repository = WakeWordFileRepository(self.db)
        file_repository.add(sample)
Beispiel #6
0
def add_wake_word_file(context, file_name):
    """Add a row to the tagging.file table for testing."""
    location_repository = TaggingFileLocationRepository(context.db)
    file_location = location_repository.ensure_location_exists(
        server="127.0.0.1", directory="some/dummy/file/directory")
    wake_word_file = WakeWordFile(
        wake_word=context.wake_words["hey selene"],
        name=file_name,
        origin="mycroft",
        submission_date=datetime.utcnow().date(),
        location=file_location,
        status=UPLOADED_STATUS,
        account_id=context.account.id,
    )
    file_repository = WakeWordFileRepository(context.db)
    file_repository.add(wake_word_file)
def check_wake_word_file_table(context):
    """The data representing the audio file is stored correctly on the database."""
    file_repository = WakeWordFileRepository(context.db)
    context.wake_word_files = file_repository.get_by_wake_word(
        context.expected_wake_word_file.wake_word)
    if context.duplicate_hash:
        expected_file_names = [AUDIO_FILE_NAME, DUPLICATE_FILE_NAME]
        file_count = 2
    else:
        expected_file_names = [AUDIO_FILE_NAME]
        file_count = 1
    assert_that(len(context.wake_word_files), equal_to(file_count))
    for wake_word_file in context.wake_word_files:
        assert_that(wake_word_file.name, is_in(expected_file_names))
        assert_that(
            wake_word_file.location.directory,
            context.wake_word_dir.joinpath(
                context.expected_wake_word_file.wake_word.name.replace(
                    " ", "-")),
        )
        assert_that(wake_word_file.location.server, equal_to("127.0.0.1"))
Beispiel #8
0
def add_wake_word_sample(context):
    """Add a sample wake word file to the database to be queried by future steps."""
    file_repository = WakeWordFileRepository(context.db)
    location_repository = TaggingFileLocationRepository(context.db)
    location = TaggingFileLocation(server="127.0.0.1",
                                   directory="/opt/selene/data")
    location.id = location_repository.add(location)

    wake_word_file = WakeWordFile(
        wake_word=context.wake_word,
        name="test.wav",
        origin="mycroft",
        submission_date=datetime.utcnow().date(),
        account_id=context.accounts["foo"].id,
        status="uploaded",
        location=location,
    )
    file_repository.add(wake_word_file)
    file_repository.change_file_status(wake_word_file, PENDING_DELETE_STATUS)
    context.wake_word_file = wake_word_file
Beispiel #9
0
def check_wake_word_file_status(context):
    """An account that contributed wake word samples has those samples removed."""
    deleted_account = context.accounts["foo"]
    file_repository = WakeWordFileRepository(context.db)
    files_pending_delete = file_repository.get_pending_delete()
    assert_that(deleted_account.id, is_in(files_pending_delete))
Beispiel #10
0
def remove_wake_word_files(db, wake_word_file):
    """Remove a wake word files by wake word and their associated data."""
    file_repository = WakeWordFileRepository(db)
    file_repository.remove(wake_word_file)
    def file_repository(self):
        if self._file_repository is None:
            self._file_repository = WakeWordFileRepository(self.db)

        return self._file_repository