Exemplo n.º 1
0
class RhasspyTestCore:
    def __init__(self, profile_name, train=True):
        self.profile_name = profile_name
        self.system_profiles_dir = os.path.join(os.getcwd(), "profiles")
        self.train = train

    def __enter__(self):
        self.user_profiles_dir = tempfile.TemporaryDirectory()
        self.core = RhasspyCore(self.profile_name, self.system_profiles_dir,
                                self.user_profiles_dir.name)
        self.core.profile.set("wake.system", "dummy")
        self.core.start(preload=False)

        if self.train:
            self.core.train()

        return self.core

    def __exit__(self, *args):
        self.core.shutdown()

        try:
            self.user_profiles_dir.cleanup()
        except:
            pass
Exemplo n.º 2
0
    def test_training(self):
        """Test training"""
        profile_name = "en"
        with tempfile.TemporaryDirectory(prefix="rhasspy_") as temp_dir:
            profiles_dirs = [temp_dir, "profiles"]
            core = RhasspyCore(profile_name, profiles_dirs, do_logging=True)
            core.profile.set("rhasspy.listen_on_start", False)
            core.profile.set("rhasspy.preload_profile", False)
            core.start()

            sentences_path = core.profile.write_path(
                core.profile.get("speech_to_text.sentences_ini")
            )

            with open(sentences_path, "w") as sentences_file:
                print("[Foo]", file=sentences_file)
                print("foo bar", file=sentences_file)
                print("foo bar baz", file=sentences_file)

            core.train()
            with open("etc/test/what_time_is_it.wav", "rb") as wav_file:
                text = core.transcribe_wav(wav_file.read()).text
                assert text != "what time is it"

            # Add some more sentences
            with open(sentences_path, "a") as sentences_file:
                print("", file=sentences_file)
                print("[GetTime]", file=sentences_file)
                print("what time is it", file=sentences_file)

            core.train()
            with open("etc/test/what_time_is_it.wav", "rb") as wav_file:
                text = core.transcribe_wav(wav_file.read()).text
                assert text == "what time is it"