Exemplo n.º 1
0
    def test_get_stt_from_file(self):
        from neon_speech.service import NeonSpeechClient
        from neon_messagebus.service import NeonBusService
        AUDIO_FILE_PATH = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "audio_files")
        TEST_CONFIG = get_neon_speech_config()
        TEST_CONFIG["stt"]["module"] = "deepspeech_stream_local"
        bus = NeonBusService(daemonic=True)
        bus.start()
        client = NeonSpeechClient(speech_config=TEST_CONFIG, daemonic=True)
        audio, context, transcripts = \
            client._get_stt_from_file(join(AUDIO_FILE_PATH, "stop.wav"))
        self.assertIsInstance(audio, AudioData)
        self.assertIsInstance(context, dict)
        self.assertIsInstance(transcripts, list)
        self.assertIn("stop", transcripts)

        def threaded_get_stt():
            audio, context, transcripts = \
                client._get_stt_from_file(join(AUDIO_FILE_PATH, "stop.wav"))
            self.assertIsInstance(audio, AudioData)
            self.assertIsInstance(context, dict)
            self.assertIsInstance(transcripts, list)
            self.assertIn("stop", transcripts)

        threads = list()
        for i in range(0, 12):
            t = Thread(target=threaded_get_stt)
            threads.append(t)
            t.start()

        for t in threads:
            t.join(30)
        bus.shutdown()
Exemplo n.º 2
0
def get_speech_module_config() -> dict:
    """
    Get a dict config with all values required for the speech module read from
    Neon YML config
    :returns: dict Mycroft config with Neon YML values where defined
    """
    ovos = get_ovos_config()
    if "hotwords" in ovos:
        conf = ovos.pop("hotwords")
        LOG.debug(f"removed hostwords config: {conf}")
    neon = get_neon_speech_config()
    return {**ovos, **neon}
Exemplo n.º 3
0
    def create(config=None, results_event: Event = None):
        if config and not config.get(
                "module"
        ):  # No module, try getting stt config from passed config
            config = config.get("stt")
        if not config:  # No config, go get it
            config = get_neon_speech_config().get("stt", {})

        LOG.info(f"Create STT with config: {config}")
        clazz = OVOSSTTFactory.get_class(config)
        if not clazz:
            LOG.warning("plugin not found, falling back to Chromium STT")
            config["module"] = "google"  # TODO configurable fallback plugin
            clazz = OVOSSTTFactory.get_class(config)
            if not clazz:
                raise ValueError("fallback plugin not found")

        return WrappedSTT(clazz, config=config, results_event=results_event)
Exemplo n.º 4
0
 def __new__(cls, clazz, *args, **kwargs):
     # read config
     config_core = {'stt': kwargs.get("config")} or get_neon_speech_config()
     metric_upload = config_core.get("metric_upload", False)
     # build STT
     for k in list(kwargs.keys()):
         if k not in signature(clazz).parameters:
             kwargs.pop(k)
     stt = clazz(*args, **kwargs)
     # add missing properties
     if metric_upload:
         server_addr = config_core.get("remote_server", "64.34.186.120")
         stt.server_bus = MessageBusClient(host=server_addr)
         stt.server_bus.run_in_thread()
     else:
         stt.server_bus = None
     stt.keys = config_core.get("keys", {})
     return stt
Exemplo n.º 5
0
import unittest

from time import sleep, time
from multiprocessing import Process
from mycroft_bus_client import MessageBusClient, Message
from neon_utils.configuration_utils import get_neon_speech_config
from neon_utils.file_utils import encode_file_to_base64_string
from neon_utils.logger import LOG
from neon_messagebus.service import NeonBusService

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from neon_speech.__main__ import main as neon_speech_main

AUDIO_FILE_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               "audio_files")
TEST_CONFIG = get_neon_speech_config()
TEST_CONFIG["stt"]["module"] = "deepspeech_stream_local"


class TestAPIMethods(unittest.TestCase):
    speech_thread = None

    @classmethod
    def setUpClass(cls) -> None:
        cls.messagebus = NeonBusService(debug=True, daemonic=True)
        cls.messagebus.start()
        cls.speech_thread = Process(target=neon_speech_main,
                                    kwargs={"speech_config": TEST_CONFIG},
                                    daemon=False)
        cls.speech_thread.start()
        cls.bus = MessageBusClient()