Skip to content
Snippets Groups Projects
Commit 4589dde6 authored by Timo Birr's avatar Timo Birr :rage:
Browse files

Fixed providers so they do not crash on memory restart

parent 251a3e2b
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ from abc import ABC
from time import sleep
import numpy as np
from Ice import LocalException
from armarx_audio.aron.audio import Audio
from armarx_audio.audio_reader import AudioReader, AUDIO_CORE_SEGMENT_ID
......@@ -34,8 +35,15 @@ class AudioMemoryASR(BaseASR, ABC):
while not hasattr(self, '_audio_reader'):
sleep(1) # Wait for Audio Memory to connect. Unfortunately, recorder_thread might get started before.
print('Subscribing to updates from', self._audio_input_entity)
self._audio_reader.poll_updates(entity_id=self._audio_input_entity,
callback=self._receive_audio_from_memory)
while True:
try:
self._audio_reader.poll_updates(entity_id=self._audio_input_entity,
callback=self._receive_audio_from_memory)
except LocalException as e:
self._audio_reader = AudioReader.from_mns(self._mns)
def _receive_audio_from_memory(self, audio: Audio):
waveform: np.ndarray = np.stack([np.squeeze(c.waveform)
......
......@@ -3,11 +3,12 @@ import logging
import threading
from typing import Optional
from Ice import LocalException
from armarx_memory.client import MemoryNameSystem
from armarx_memory.core import MemoryID
from armarx_memory.segments.SpeechToText import SpeechToTextWriter
logger = logging.getLogger(__name__)
class BaseASR(abc.ABC):
......@@ -17,10 +18,11 @@ class BaseASR(abc.ABC):
channel=0
):
super().__init__()
logger.info(f"Getting MNS.")
self.log = logging.getLogger(name=output_provider_name)
self.log.info(f"Getting MNS.")
self._mns = MemoryNameSystem.wait_for_mns()
self._writer = SpeechToTextWriter.from_mns(self._mns, wait=True)
self._output_entity_id = self._writer.make_entity_name(output_provider_name)
self._recorder_thread = threading.Thread(target=self.recording_loop, daemon=True)
......@@ -40,8 +42,12 @@ class BaseASR(abc.ABC):
pass
def publish_hypothesis(self, hypo: str, confidence: float = 1, speaker: Optional[MemoryID] = None):
logger.info(f"Committing hypothesis '{hypo}' with confidence {confidence:.4f}.")
self._writer.commit(self._output_entity_id, text=hypo, confidence=confidence, speaker=speaker)
try:
self._writer.commit(self._output_entity_id, text=hypo, confidence=confidence, speaker=speaker)
self.log.info(f"Committing hypothesis '{hypo}'.")
except LocalException as e:
self._writer = SpeechToTextWriter.from_mns(self._mns, wait=True)
@classmethod
def add_argparse_args(cls, parser):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment