예제 #1
0
ws_queues: List[List[asyncio.Queue]] = [[], []]
ws_locks: List[asyncio.Lock] = [asyncio.Lock(), asyncio.Lock()]


async def add_ws_event(event_type: int, text: str):
    """Send text out to all websockets for a specific event."""
    async with ws_locks[event_type]:
        for q in ws_queues[event_type]:
            await q.put(text)


# Send logging messages out to websocket
logging.root.addHandler(
    FunctionLoggingHandler(
        lambda msg: asyncio.run_coroutine_threadsafe(
            add_ws_event(WS_EVENT_LOG, msg), loop
        )
    )
)


class WebSocketObserver(RhasspyActor):
    """Observe the dialogue manager and output intents to the websocket."""

    def in_started(self, message: Any, sender: RhasspyActor) -> None:
        """Handle messages in started state."""
        if isinstance(message, IntentRecognized):
            # Add slots
            intent_slots = {}
            for ev in message.intent.get("entities", []):
                intent_slots[ev["entity"]] = ev["value"]
예제 #2
0
WS_EVENT_INTENT = 0
WS_EVENT_LOG = 1

ws_queues: List[Dict[Any, GQueue]] = [{}, {}]
ws_locks: List[RLock] = [RLock(), RLock()]


def add_ws_event(event_type: int, text: str):
    with ws_locks[event_type]:
        for queue in ws_queues[event_type].values():
            queue.put(text)


logging.root.addHandler(
    FunctionLoggingHandler(lambda msg: add_ws_event(WS_EVENT_LOG, msg)))


class WebSocketObserver(RhasspyActor):
    """Observes the dialogue manager and outputs intents to the websocket."""
    def in_started(self, message: Any, sender: RhasspyActor) -> None:
        if isinstance(message, IntentRecognized):
            # Add slots
            intent_slots = {}
            for ev in message.intent.get("entities", []):
                intent_slots[ev["entity"]] = ev["value"]

            message.intent["slots"] = intent_slots

            # Convert to JSON
            intent_json = json.dumps(message.intent)
예제 #3
0
async def add_ws_event(message_type: str, text: str):
    """Send text out to all user websockets for a specific event."""
    for q in user_queues:
        await q.put((message_type, text))


async def log_ws_event(text: str):
    """Send logging message out to websockets."""
    for q in logging_queues:
        await q.put(text)


# Send logging messages out to websocket
logging.root.addHandler(
    FunctionLoggingHandler(
        lambda msg: asyncio.run_coroutine_threadsafe(log_ws_event(msg), loop)))


class WebSocketObserver(RhasspyActor):
    """Observe the dialogue manager and output intents to the websocket."""
    def in_started(self, message: Any, sender: RhasspyActor) -> None:
        """Handle messages in started state."""
        global last_voice_wav

        if isinstance(message, IntentRecognized):
            # Add slots
            intent_slots = {}
            for ev in message.intent.get("entities", []):
                intent_slots[ev["entity"]] = ev["value"]

            message.intent["slots"] = intent_slots